31 lines
854 B
TypeScript
31 lines
854 B
TypeScript
export const useSettings = () => {
|
|
const open = useState<boolean>('settings:open', () => false);
|
|
const currentPage = useState('settings-page', () => 'general');
|
|
const pageParams = useState('settings-params', () => [] as string[]);
|
|
|
|
const toggle = () => {
|
|
open.value = !open.value;
|
|
};
|
|
|
|
const setPage = (id: string, params?: string | string[]) => {
|
|
if (open.value === false) toggle();
|
|
|
|
currentPage.value = id;
|
|
if (params) {
|
|
if (typeof params === 'string') {
|
|
params = [params];
|
|
}
|
|
pageParams.value = params;
|
|
} else {
|
|
pageParams.value = [];
|
|
}
|
|
};
|
|
|
|
const close = () => {
|
|
open.value = false;
|
|
currentPage.value = 'page1';
|
|
};
|
|
|
|
return { open, currentPage, pageParams, toggle, setPage, close };
|
|
};
|