Skip to content

Commit

Permalink
refactor: 팔로워 팔로잉 상태 유지 및 페이지 이동에도 반영하기 위해 zustand로 관리
Browse files Browse the repository at this point in the history
  • Loading branch information
ww8007 committed Jul 23, 2023
1 parent 9b847e4 commit eb4524a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/friend/ui/FriendTypeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import styled from '@emotion/styled';
import Button from '@/common-ui/Button';
import { css } from '@emotion/react';
import { theme } from '@/styles/theme';

export enum FriendType {
Follower = 'Follower',
Following = 'Following',
}
import { FriendType } from '@/store/friend';

interface FriendTypeSelectProps {
value: FriendType;
Expand Down
8 changes: 3 additions & 5 deletions src/friend/ui/Friends.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';
import FriendFollowingItem from '@/friend/ui/friend/FriendFollowingItem';
import FriendFollowerItem from '@/friend/ui/friend/FriendFollowerItem';
import FriendTypeSelect, { FriendType } from '@/friend/ui/FriendTypeSelect';
import FriendTypeSelect from '@/friend/ui/FriendTypeSelect';
import styled from '@emotion/styled';
import getRem from '@/utils/getRem';
import useAuthStore from '@/store/auth';
Expand All @@ -12,6 +11,7 @@ import {
useGETFollowingListQuery,
} from '../api/friends';
import BlankItem from '@/common-ui/BlankItem';
import useFriendStore, { FriendType } from '@/store/friend';

const Friends = () => {
const { memberId } = useAuthStore();
Expand All @@ -24,9 +24,7 @@ const Friends = () => {
memberId,
});

const [selectedType, setSelectedType] = useState<FriendType>(
FriendType.Follower,
);
const { selectedType, setSelectedType } = useFriendStore();

const followers = followerData?.pages.flatMap((page) => page.contents) ?? [];
const followings =
Expand Down
20 changes: 20 additions & 0 deletions src/store/friend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { create } from 'zustand';

export enum FriendType {
Follower = 'Follower',
Following = 'Following',
}

interface FriendStore {
selectedType: FriendType;
setSelectedType: (mode: FriendType) => void;
}

const useFriendStore = create<FriendStore>((set) => ({
selectedType: FriendType.Follower,
setSelectedType: (selectedType) => {
set({ selectedType });
},
}));

export default useFriendStore;

1 comment on commit eb4524a

@vercel
Copy link

@vercel vercel bot commented on eb4524a Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.