1- import { WorkspacePreferences } from 'nmr-load-save' ;
1+ import { CustomWorkspaces , WorkspacePreferences } from 'nmr-load-save' ;
22import { NMRiumWorkspace } from 'nmrium' ;
33import { useLayoutEffect , useState } from 'react' ;
44
5+ import { getNmrXivWorkspace } from '../workspaces/nmrxiv' ;
6+
57interface Preferences {
68 preferences : WorkspacePreferences | undefined ;
79 workspace : NMRiumWorkspace | undefined ;
810 defaultEmptyMessage : string | undefined ;
11+ customWorkspaces : CustomWorkspaces ;
912}
1013
1114const DEFAULT_PREFERENCES = {
1215 preferences : undefined ,
1316 workspace : undefined ,
1417 defaultEmptyMessage : undefined ,
18+ customWorkspaces : { } ,
1519} ;
1620
1721export function usePreferences ( ) {
@@ -25,19 +29,46 @@ export function usePreferences() {
2529 let preferences : WorkspacePreferences | undefined ;
2630 let workspace : NMRiumWorkspace | undefined ;
2731 let defaultEmptyMessage : string | undefined ;
32+ let hidePanelOnLoad = false ;
2833
2934 if ( parameters . has ( 'workspace' ) ) {
3035 workspace = parameters . get ( 'workspace' ) as NMRiumWorkspace ;
3136 }
37+
3238 if ( parameters . has ( 'preferences' ) ) {
3339 preferences = JSON . parse ( parameters . get ( 'preferences' ) || '' ) ;
3440 }
3541
3642 if ( parameters . has ( 'defaultEmptyMessage' ) ) {
3743 defaultEmptyMessage = parameters . get ( 'defaultEmptyMessage' ) as string ;
3844 }
39- setConfiguration ( { preferences, workspace, defaultEmptyMessage } ) ;
45+ if ( parameters . has ( 'hidePanelOnLoad' ) ) {
46+ hidePanelOnLoad =
47+ parameters . get ( 'hidePanelOnLoad' ) ?. toLowerCase ( ) === 'true' ;
48+ }
49+
50+ const customWorkspaces = createCustomWorkspaces ( { hidePanelOnLoad } ) ;
51+ setConfiguration ( {
52+ preferences,
53+ workspace,
54+ defaultEmptyMessage,
55+ customWorkspaces,
56+ } ) ;
4057 } , [ ] ) ;
4158
4259 return configuration ;
4360}
61+
62+ interface CreateCustomWorkspacesOptions {
63+ hidePanelOnLoad ?: boolean ;
64+ }
65+
66+ function createCustomWorkspaces (
67+ options : CreateCustomWorkspacesOptions ,
68+ ) : CustomWorkspaces {
69+ const { hidePanelOnLoad = false } = options ;
70+
71+ return {
72+ nmrXiv : getNmrXivWorkspace ( hidePanelOnLoad ) ,
73+ } ;
74+ }
0 commit comments