Skip to content

Commit

Permalink
๐Ÿ› fix: ์ถ”๊ฐ€๋œ url storage์—๋„ zustand persist ์ ์šฉํ•˜๊ธฐ #103
Browse files Browse the repository at this point in the history
  • Loading branch information
naarang committed Nov 4, 2024
1 parent 7e4b00a commit 18ba71d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
52 changes: 34 additions & 18 deletions src/store/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,51 @@ type CurrentApplicantIdStore = {
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',
},
),
);
9 changes: 8 additions & 1 deletion src/utils/clearAllStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { usePostSearchStore } from '@/store/postSearch';
import { useEmailTryCountStore } from '@/store/signup';
import { useCurrentApplicantIdStore, useCurrentPostIdStore } from '@/store/url';
import {
useCurrentApplicantIdStore,
useCurrentDocumentIdStore,
useCurrentPostIdEmployeeStore,
useCurrentPostIdStore,
} from '@/store/url';
import { useUserStore } from '@/store/user';

// store ์ „์—ญ ๋ณ€์ˆ˜ ์ดˆ๊ธฐํ™”
Expand All @@ -10,4 +15,6 @@ export const clearAllStore = () => {
useEmailTryCountStore.persist.clearStorage();
useCurrentPostIdStore.persist.clearStorage();
useCurrentApplicantIdStore.persist.clearStorage();
useCurrentDocumentIdStore.persist.clearStorage();
useCurrentPostIdEmployeeStore.persist.clearStorage();
};

0 comments on commit 18ba71d

Please sign in to comment.