-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusePreferences.ts
More file actions
72 lines (58 loc) · 1.87 KB
/
usePreferences.ts
File metadata and controls
72 lines (58 loc) · 1.87 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import type {
CustomWorkspaces,
WorkspacePreferences,
} from '@zakodium/nmrium-core';
import type { NMRiumWorkspace } from 'nmrium';
import { getNmrXivWorkspace } from '../workspaces/nmrxiv.js';
export function usePreferences() {
const { href } = window.location;
const parameters = new URL(href).searchParams;
let preferences: WorkspacePreferences | undefined;
let workspace: NMRiumWorkspace | undefined;
let defaultEmptyMessage: string | undefined;
let hidePanelOnLoad = false;
if (parameters.has('workspace')) {
workspace = parameters.get('workspace') as NMRiumWorkspace;
}
if (parameters.has('preferences')) {
preferences = JSON.parse(parameters.get('preferences') || '');
}
if (parameters.has('defaultEmptyMessage')) {
defaultEmptyMessage = parameters.get('defaultEmptyMessage') as string;
}
if (parameters.has('hidePanelOnLoad')) {
hidePanelOnLoad =
parameters.get('hidePanelOnLoad')?.toLowerCase() === 'true';
}
const customWorkspaces = createCustomWorkspaces({ hidePanelOnLoad });
if (parameters.has('workspace')) {
workspace = parameters.get('workspace') as NMRiumWorkspace;
}
if (parameters.has('preferences')) {
preferences = JSON.parse(parameters.get('preferences') || '');
}
if (parameters.has('defaultEmptyMessage')) {
defaultEmptyMessage = parameters.get('defaultEmptyMessage') as string;
}
if (parameters.has('hidePanelOnLoad')) {
hidePanelOnLoad =
parameters.get('hidePanelOnLoad')?.toLowerCase() === 'true';
}
return {
preferences,
workspace,
defaultEmptyMessage,
customWorkspaces,
};
}
interface CreateCustomWorkspacesOptions {
hidePanelOnLoad?: boolean;
}
function createCustomWorkspaces(
options: CreateCustomWorkspacesOptions,
): CustomWorkspaces {
const { hidePanelOnLoad = false } = options;
return {
nmrXiv: getNmrXivWorkspace(hidePanelOnLoad),
};
}