mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 19:03:47 +00:00
9338a615d4
* chore: update related deps * refactor: memoise entrypoints * refactor: store selectors * refactor: improve component performance * chore: remove unused dependencies * refactor: improve component dnd
25 lines
783 B
TypeScript
25 lines
783 B
TypeScript
import { create } from 'zustand';
|
|
|
|
import { booleanFromLocalStorage } from '../utils/localStorage';
|
|
|
|
type CursorStore = {
|
|
cursor: number;
|
|
isCursorLocked: boolean;
|
|
toggleCursorLocked: (newValue?: boolean) => void;
|
|
moveCursorTo: (index: number) => void;
|
|
};
|
|
|
|
const cursorLockedKey = 'ontime-cursor-islocked';
|
|
|
|
export const useCursor = create<CursorStore>()((set) => ({
|
|
cursor: 0,
|
|
isCursorLocked: booleanFromLocalStorage(cursorLockedKey, false),
|
|
toggleCursorLocked: (newValue?: boolean) =>
|
|
set((state) => {
|
|
const val = typeof newValue === 'undefined' ? !state.isCursorLocked : newValue;
|
|
localStorage.setItem(cursorLockedKey, String(val));
|
|
return { isCursorLocked: val };
|
|
}),
|
|
moveCursorTo: (index: number) => set(() => ({ cursor: index })),
|
|
}));
|