-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from Team-inglo/feat/IGW-44/65
[feat/103] zustand persist 적용하기
- Loading branch information
Showing
8 changed files
with
120 additions
and
49 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
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
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
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
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import { create } from 'zustand'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
type EmailTryCountStore = { | ||
try_cnt: number; | ||
updateTryCnt: (cnt: number) => void; | ||
}; | ||
|
||
export const useEmailTryCountStore = create<EmailTryCountStore>()((set) => ({ | ||
try_cnt: 0, | ||
updateTryCnt: (try_cnt) => set(() => ({ try_cnt: try_cnt })), | ||
})); | ||
export const useEmailTryCountStore = create( | ||
persist<EmailTryCountStore>( | ||
(set) => ({ | ||
try_cnt: 0, | ||
updateTryCnt: (try_cnt) => set(() => ({ try_cnt: try_cnt })), | ||
}), | ||
{ | ||
name: 'emailTryCountStore', | ||
}, | ||
), | ||
); |
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 |
---|---|---|
@@ -1,42 +1,74 @@ | ||
import { create } from 'zustand'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
type CurrentPostIdStore = { | ||
currentPostId: number | null; | ||
updateCurrentPostId: (id: number) => void; | ||
}; | ||
|
||
export const useCurrentPostIdStore = create<CurrentPostIdStore>()((set) => ({ | ||
currentPostId: null, | ||
updateCurrentPostId: (newId: number) => set(() => ({ currentPostId: newId })), | ||
})); | ||
export const useCurrentPostIdStore = create( | ||
persist<CurrentPostIdStore>( | ||
(set) => ({ | ||
currentPostId: null, | ||
updateCurrentPostId: (newId: number) => | ||
set(() => ({ currentPostId: newId })), | ||
}), | ||
{ | ||
name: 'currentPostIdStore', | ||
}, | ||
), | ||
); | ||
|
||
type CurrentApplicantIdStore = { | ||
currentApplicantId: number | null; | ||
updateCurrentApplicantId: (id: number) => void; | ||
}; | ||
|
||
export const useCurrentApplicantIdStore = create<CurrentApplicantIdStore>()((set) => ({ | ||
currentApplicantId: null, | ||
updateCurrentApplicantId: (newId: number) => set(() => ({ currentApplicantId: newId })), | ||
})); | ||
export const useCurrentApplicantIdStore = create( | ||
persist<CurrentApplicantIdStore>( | ||
(set) => ({ | ||
currentApplicantId: null, | ||
updateCurrentApplicantId: (newId: number) => | ||
set(() => ({ currentApplicantId: newId })), | ||
}), | ||
{ | ||
name: 'currentApplicantIdStore', | ||
}, | ||
), | ||
); | ||
|
||
type CurrentDocumentIdStore = { | ||
currentDocumentId: number | null; | ||
updateCurrentDocumentId: (id: number) => void; | ||
}; | ||
|
||
export const useCurrentDocumentIdStore = create<CurrentDocumentIdStore>()((set) => ({ | ||
currentDocumentId: null, | ||
updateCurrentDocumentId: (newId: number) => set(() => ({ currentDocumentId: newId })), | ||
})); | ||
|
||
export const useCurrentDocumentIdStore = create( | ||
persist<CurrentDocumentIdStore>( | ||
(set) => ({ | ||
currentDocumentId: null, | ||
updateCurrentDocumentId: (newId: number) => | ||
set(() => ({ currentDocumentId: newId })), | ||
}), | ||
{ | ||
name: 'currentDocumentIdStore', | ||
}, | ||
), | ||
); | ||
|
||
type CurrentPostIdStoreEmployee = { | ||
currentPostId: number | null; | ||
updateCurrentPostId: (id: number) => void; | ||
}; | ||
|
||
export const useCurrentPostIdEmployeeStore = create<CurrentPostIdStoreEmployee>()((set) => ({ | ||
currentPostId: null, | ||
updateCurrentPostId: (newId: number) => set(() => ({ currentPostId: newId })), | ||
})); | ||
export const useCurrentPostIdEmployeeStore = create( | ||
persist<CurrentPostIdStoreEmployee>( | ||
(set) => ({ | ||
currentPostId: null, | ||
updateCurrentPostId: (newId: number) => | ||
set(() => ({ currentPostId: newId })), | ||
}), | ||
{ | ||
name: 'useCurrentPostIdEmployeeStore', | ||
}, | ||
), | ||
); |
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
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,20 @@ | ||
import { usePostSearchStore } from '@/store/postSearch'; | ||
import { useEmailTryCountStore } from '@/store/signup'; | ||
import { | ||
useCurrentApplicantIdStore, | ||
useCurrentDocumentIdStore, | ||
useCurrentPostIdEmployeeStore, | ||
useCurrentPostIdStore, | ||
} from '@/store/url'; | ||
import { useUserStore } from '@/store/user'; | ||
|
||
// store 전역 변수 초기화 | ||
export const clearAllStore = () => { | ||
useUserStore.persist.clearStorage(); | ||
usePostSearchStore.persist.clearStorage(); | ||
useEmailTryCountStore.persist.clearStorage(); | ||
useCurrentPostIdStore.persist.clearStorage(); | ||
useCurrentApplicantIdStore.persist.clearStorage(); | ||
useCurrentDocumentIdStore.persist.clearStorage(); | ||
useCurrentPostIdEmployeeStore.persist.clearStorage(); | ||
}; |