aboutsummaryrefslogtreecommitdiff
path: root/apps/extension/content/store.ts
blob: d9d75630591a7b8df5b1f0d1b173032d2f74937a (plain) (blame)
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
44
45
46
47
import { create } from "zustand";
import { RefObject } from "react";

interface CommandProps {
	currValue: string;
	setCurrentValue: (value: string) => void;

	search: string;
	setSearch: (value: string) => void;

	pages: string[];
	setPages: (pages: string[]) => void;
	backPage: () => void;

	page: string;
	setPage: (page: string) => void;

	searchInputRef: RefObject<HTMLInputElement>;
	setSearchInputRef: (ref: RefObject<HTMLInputElement>) => void;
}

const useCommandStore = create<CommandProps>((set) => ({
	currValue: "",
	setCurrentValue: (value) => set({ currValue: value }),

	search: "",
	setSearch: (value) => set({ search: value }),

	pages: [],
	setPages: (pages) => {
		set({ pages });
	},
	backPage: () => {
		const pages = [...useCommandStore.getState().pages];
		pages.pop();
		useCommandStore.getState().setPages(pages);
	},

	page: "",
	setPage: (page) => set({ page }),

	searchInputRef: { current: null },
	setSearchInputRef: (ref: RefObject<HTMLInputElement>) =>
		set({ searchInputRef: ref }),
}));

export default useCommandStore;