Skip to content

Commit

Permalink
feat: main page restitution
Browse files Browse the repository at this point in the history
feat: main page restitution
  • Loading branch information
devwoodie authored Jul 28, 2023
2 parents bef6946 + 857d882 commit f0df9eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 37 deletions.
41 changes: 9 additions & 32 deletions src/pages/main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import RootStore from "../../store/RootStore";
import IcSearch from "../../assets/images/icon/ic_search.svg";
import {useNavigate} from "react-router-dom";
import Spinner from "../../components/common/Spinner";
import {FriendResponseProto} from "../../prototypes/friend/FriendResponse";
import {get} from "../../apis/RestApis";

const Main = () => {
let baseUrl : string = process.env.REACT_APP_SERVICE_URI as string
// let key = RootStore.userStore.getJwtKey;
let key = RootStore.userStore.getJwtKey;
let navigate = useNavigate();

const [key, setKey] = useState<string>();
// 리스트 비었을 때 분기처리
const [isEmptyList, setIsEmptyList] = useState<boolean>(true);
const [registerBtn, setRegisterBtn] = useState<boolean>(false);
Expand All @@ -30,9 +26,8 @@ const Main = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);

useEffect(() => {
setKey(RootStore.userStore.getJwtKey);

const isFirstVisit = sessionStorage.getItem('isFirstVisit');

if (isFirstVisit !== null) {
setIsLoading(false);
}else{
Expand All @@ -47,9 +42,7 @@ const Main = () => {
// 친구 목록 불러오기 api
useEffect(() => {
if (key) {
RootStore.userStore.getUser();
getFriendListMain("nickname");
setMindCount();
apiCallSet();
}
}, [key]);

Expand All @@ -62,35 +55,19 @@ const Main = () => {
}
}, [mainFriendList]);

const getFriendListMain = async (filterParams: any) => {
try{
const res: FriendResponseProto[] = await get(`${baseUrl}/api/friend?&sort=${filterParams}`,{
headers : {
Authorization : RootStore.userStore.getJwtKey
},
})
if(res) return setMainFriendList(res);

}catch (err){
console.log(err);
}
}
const setMindCount = async () => {
const response = await get(`${baseUrl}/api/relationships/count`, {
headers : {
Authorization : RootStore.userStore.getJwtKey
}
});
if(response) return setCount(response);
const apiCallSet = () => {
RootStore.userStore.getUser();
RootStore.friendStore.getFriendListMain(setMainFriendList, "nickname");
RootStore.mindStore.setMindCount(setCount);
}
// 필터링
const handleFilter = async () => {
if(filterParams === "level"){
setFilterParams("nickname");
getFriendListMain(filterParams);
await RootStore.friendStore.getFriendListMain(setMainFriendList, filterParams);
} else if (filterParams === "nickname"){
setFilterParams("level");
getFriendListMain(filterParams);
await RootStore.friendStore.getFriendListMain(setMainFriendList, filterParams);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/setting/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React, {useState} from "react";
import {Link} from "react-router-dom";
import IcFrontBtn from '../../assets/images/icon/ic_front_btn.svg';
import ModalConfirm from "../../components/common/ModalConfirm";
import RootStore from "../../store/RootStore";

const Setting = () => {

const getNick = new URLSearchParams(window.location.search).get("nick");
const getNick = RootStore.userStore.getUserName;
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isOkOpen, setIsOkOpen] = useState<boolean>(false);

Expand Down
4 changes: 1 addition & 3 deletions src/pages/setting/SettingNickname.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import InputTextBox from "../../components/common/InputTextBox";
import ModalConfirm from "../../components/common/ModalConfirm";
import {useNavigate} from "react-router-dom";
import ErrorMessage from "../../components/common/ErrorMessage";
import { UserPatchRequestProto } from "../../prototypes/user/UserRequestProto";
import UserStore from './../../store/UserStore';
import RootStore from "../../store/RootStore";

const SettingNickname = () => {
let regExp = /[ \{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'\"\\\(\=]/gi;
const getNick = new URLSearchParams(window.location.search).get("nick");
const getNick = RootStore.userStore.getUserName;

const navigate = useNavigate();
const [nickname, setNickname] = useState("");
Expand Down
2 changes: 1 addition & 1 deletion src/styles/pages/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

// main text
.MainText{
margin-top: 45px;
margin-top: 12vw;
.main-text{
margin: 24px 0 16px;
font-weight: bold;
Expand Down

0 comments on commit f0df9eb

Please sign in to comment.