mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
fix: storage key conflict across stages
This commit is contained in:
committed by
Carlos Valente
parent
efceb930e5
commit
617da68ab5
@@ -1,6 +1,8 @@
|
|||||||
import { ClientList } from 'ontime-types';
|
import { ClientList } from 'ontime-types';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
import { makeStageKey } from '../utils/localStorage';
|
||||||
|
|
||||||
interface ClientStore {
|
interface ClientStore {
|
||||||
name?: string;
|
name?: string;
|
||||||
setName: (newValue: string) => void;
|
setName: (newValue: string) => void;
|
||||||
@@ -15,7 +17,7 @@ interface ClientStore {
|
|||||||
setClients: (clients: ClientList) => void;
|
setClients: (clients: ClientList) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientNameKey = 'ontime-client-name';
|
const clientNameKey = makeStageKey('client-name');
|
||||||
|
|
||||||
function persistNameInStorage(newValue: string) {
|
function persistNameInStorage(newValue: string) {
|
||||||
localStorage.setItem(clientNameKey, newValue);
|
localStorage.setItem(clientNameKey, newValue);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { create } from 'zustand';
|
|||||||
import { booleanFromLocalStorage } from '../utils/localStorage';
|
import { booleanFromLocalStorage } from '../utils/localStorage';
|
||||||
|
|
||||||
enum LocalEventKeys {
|
enum LocalEventKeys {
|
||||||
Mirror = 'ontime-view-mirror',
|
Mirror = 'view-mirror',
|
||||||
}
|
}
|
||||||
|
|
||||||
type ViewOptionsStore = {
|
type ViewOptionsStore = {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { baseURI } from '../../externals';
|
||||||
|
|
||||||
export function booleanFromLocalStorage(key: string, fallback: boolean): boolean {
|
export function booleanFromLocalStorage(key: string, fallback: boolean): boolean {
|
||||||
const valueInStorage = localStorage.getItem(key);
|
const valueInStorage = localStorage.getItem(key);
|
||||||
if (valueInStorage) {
|
if (valueInStorage) {
|
||||||
@@ -7,3 +9,8 @@ export function booleanFromLocalStorage(key: string, fallback: boolean): boolean
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function makeStageKey(key: string) {
|
||||||
|
if (baseURI) return `${baseURI}-${key}`;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -64,11 +64,11 @@ export function convertToImportMap(namedImportMap: NamedImportMap): ImportMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function persistImportMap(options: NamedImportMap) {
|
export function persistImportMap(options: NamedImportMap) {
|
||||||
localStorage.setItem('ontime-import-options', JSON.stringify(options));
|
localStorage.setItem('import-options', JSON.stringify(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPersistImportMap(): unknown {
|
function getPersistImportMap(): unknown {
|
||||||
const options = localStorage.getItem('ontime-import-options');
|
const options = localStorage.getItem('import-options');
|
||||||
if (!options) {
|
if (!options) {
|
||||||
throw new Error('no import options found');
|
throw new Error('no import options found');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,29 @@ import { ColumnDef } from '@tanstack/react-table';
|
|||||||
import { OntimeEntry } from 'ontime-types';
|
import { OntimeEntry } from 'ontime-types';
|
||||||
|
|
||||||
import { debounce } from '../../../common/utils/debounce';
|
import { debounce } from '../../../common/utils/debounce';
|
||||||
|
import { makeStageKey } from '../../../common/utils/localStorage';
|
||||||
|
|
||||||
|
const tableSizesKey = makeStageKey('cuesheet-sizes');
|
||||||
|
const tableHiddenKey = makeStageKey('cuesheet-hidden');
|
||||||
|
const tableOrderKey = makeStageKey('cuesheet-order');
|
||||||
|
|
||||||
const saveSizesToStorage = debounce((sizes: Record<string, number>) => {
|
const saveSizesToStorage = debounce((sizes: Record<string, number>) => {
|
||||||
localStorage.setItem('table-sizes', JSON.stringify(sizes));
|
localStorage.setItem(tableSizesKey, JSON.stringify(sizes));
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
export default function useColumnManager(columns: ColumnDef<OntimeEntry>[]) {
|
export default function useColumnManager(columns: ColumnDef<OntimeEntry>[]) {
|
||||||
const [columnVisibility, setColumnVisibility] = useLocalStorage({ key: 'table-hidden', defaultValue: {} });
|
const [columnVisibility, setColumnVisibility] = useLocalStorage({
|
||||||
|
key: tableHiddenKey,
|
||||||
|
defaultValue: {},
|
||||||
|
});
|
||||||
const [columnOrder, saveColumnOrder] = useLocalStorage<string[]>({
|
const [columnOrder, saveColumnOrder] = useLocalStorage<string[]>({
|
||||||
key: 'table-order',
|
key: tableOrderKey,
|
||||||
defaultValue: columns.map((col) => col.id as string),
|
defaultValue: columns.map((col) => col.id as string),
|
||||||
});
|
});
|
||||||
|
|
||||||
const [columnSizing, setColumnSizingState] = useState(() => {
|
const [columnSizing, setColumnSizingState] = useState(() => {
|
||||||
try {
|
try {
|
||||||
const stored = localStorage.getItem('table-sizes');
|
const stored = localStorage.getItem(tableSizesKey);
|
||||||
return stored ? JSON.parse(stored) : {};
|
return stored ? JSON.parse(stored) : {};
|
||||||
} catch {
|
} catch {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
Reference in New Issue
Block a user