Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { Localstorage } from "@hey/data/storage";
2import { createPersistedTrackedStore } from "@/store/createTrackedStore";
3
4interface State {
5 addAccount: (account: string) => void;
6 clearAccount: (account: string) => void;
7 clearAccounts: () => void;
8 accounts: string[];
9}
10
11const { useStore: useSearchStore } = createPersistedTrackedStore<State>(
12 (set) => ({
13 accounts: [],
14 addAccount: (account) =>
15 set((state) => {
16 // Remove the account if it already exists
17 const filteredAccounts = state.accounts.filter((a) => a !== account);
18 // Add the new account to the start of the array and ensure the total is at most 5
19 return { accounts: [account, ...filteredAccounts].slice(0, 5) };
20 }),
21 clearAccount: (account) =>
22 set((state) => ({
23 accounts: state.accounts.filter((a) => a !== account)
24 })),
25 clearAccounts: () => set({ accounts: [] })
26 }),
27 { name: Localstorage.SearchStore }
28);
29
30export { useSearchStore };