mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 04:58:27 +00:00
add settings reset button
This commit is contained in:
parent
7994ba8b38
commit
a21b3d788f
@ -20,7 +20,7 @@ export function set(next) {
|
|||||||
localStorage.setItem(storeKey, JSON.stringify(next));
|
localStorage.setItem(storeKey, JSON.stringify(next));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateState(func) {
|
export function update(func) {
|
||||||
const prev = get();
|
const prev = get();
|
||||||
const next = func(prev);
|
const next = func(prev);
|
||||||
set(next);
|
set(next);
|
||||||
@ -31,6 +31,10 @@ export function updateState(func) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reset() {
|
||||||
|
update(() => defaults);
|
||||||
|
}
|
||||||
|
|
||||||
export function watch(func, prop) {
|
export function watch(func, prop) {
|
||||||
document.addEventListener(storeKey, (e) => {
|
document.addEventListener(storeKey, (e) => {
|
||||||
const { prev, next } = e.detail;
|
const { prev, next } = e.detail;
|
||||||
|
|||||||
@ -275,7 +275,7 @@ function FormItem({ label, children }) {
|
|||||||
const themeOptions = Object.fromEntries(Object.keys(themes).map((k) => [k, k]));
|
const themeOptions = Object.fromEntries(Object.keys(themes).map((k) => [k, k]));
|
||||||
|
|
||||||
function SettingsTab() {
|
function SettingsTab() {
|
||||||
const { state, update } = useStore();
|
const { state, update, reset } = useStore();
|
||||||
const { theme, keybindings, fontSize } = state;
|
const { theme, keybindings, fontSize } = state;
|
||||||
return (
|
return (
|
||||||
<div className="text-foreground p-4 space-y-4">
|
<div className="text-foreground p-4 space-y-4">
|
||||||
@ -304,6 +304,18 @@ function SettingsTab() {
|
|||||||
items={{ codemirror: 'Codemirror', vim: 'Vim', emacs: 'Emacs' }}
|
items={{ codemirror: 'Codemirror', vim: 'Vim', emacs: 'Emacs' }}
|
||||||
></ButtonGroup>
|
></ButtonGroup>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
<FormItem label="Reset Settings">
|
||||||
|
<button
|
||||||
|
className="bg-background p-2 max-w-[300px] rounded-md hover:opacity-50"
|
||||||
|
onClick={() => {
|
||||||
|
if (confirm('Sure?')) {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
restore default settings
|
||||||
|
</button>
|
||||||
|
</FormItem>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {} from 'react';
|
|||||||
function useStore() {
|
function useStore() {
|
||||||
const [state, setState] = useState(Store.get());
|
const [state, setState] = useState(Store.get());
|
||||||
useEvent(Store.storeKey, (e) => setState(e.detail.next));
|
useEvent(Store.storeKey, (e) => setState(e.detail.next));
|
||||||
return { state, update: Store.updateState };
|
return { state, ...Store };
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: dedupe
|
// TODO: dedupe
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user