-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathuseAccountStore.ts
43 lines (36 loc) · 1.02 KB
/
useAccountStore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { create } from './zustand';
import { StoreAccount } from './useSocialMediaStore/useSocialMediaStore.types';
export type AccountPost = Pick<
StoreAccount,
'id' | 'socialMediaId' | 'userName'
>;
type StoreState = {
accounts: AccountPost[];
addAccount: (account: StoreAccount) => void;
mainContent: string;
removeAccount: (accountId: string) => void;
updateMainContent: (value: string) => void;
};
export const useAccountStore = create<StoreState>((set) => ({
accounts: [],
addAccount: (account: StoreAccount): void => {
set((state) => ({
accounts: [
...state.accounts,
{
id: account.id,
socialMediaId: account.socialMediaId,
userName: account.userName,
},
],
}));
},
mainContent: '',
removeAccount: (accountId: string): void => {
set((state) => ({
accounts: state.accounts.filter((account) => account.id !== accountId),
}));
},
updateMainContent: (newContent: string): void =>
set({ mainContent: newContent }),
}));