-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ Props Drilling 문제 해결 및 케밥 메뉴의 유일성 보장 (#76)
* feat: 피드 케밥 팝업창 저장소 * feat: 피드 kebab 메뉴 클릭 관리 메서드 추가 * feat: 케밥 버튼 적용 * feat: 메서드명 수정 * feat: FeedKebabStore 인터페이스로 수정 Closes #67
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { create } from 'zustand'; | ||
import { devtools } from 'zustand/middleware'; | ||
|
||
interface FeedKebabStore { | ||
openedFeedId: number; | ||
isOpen: boolean; | ||
openKebab: (_: number) => void; | ||
closeKebab: () => void; | ||
} | ||
|
||
/** | ||
* 피드의 kebab 메뉴를 관리하는 store | ||
*/ | ||
export const useFeedKebabStore = create<FeedKebabStore>()( | ||
devtools( | ||
(set): FeedKebabStore => ({ | ||
openedFeedId: 0, | ||
isOpen: false, | ||
openKebab: (clickedId: number) => | ||
set({ openedFeedId: clickedId, isOpen: true }), | ||
closeKebab: () => set({ openedFeedId: -1, isOpen: false }), | ||
}), | ||
{ name: 'feed-kebab-store' }, | ||
), | ||
); | ||
|
||
/** | ||
* 피드의 kebab 메뉴를 열거나 닫습니다. | ||
* @param feedId 피드 아이디 | ||
* @returns | ||
*/ | ||
export const onClickFeedKebab = (feedId: number) => { | ||
if (feedId === useFeedKebabStore.getState().openedFeedId) { | ||
useFeedKebabStore.getState().closeKebab(); | ||
return; | ||
} | ||
|
||
useFeedKebabStore.getState().openKebab(feedId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './feed-kebab-store'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters