@@ -8,6 +8,9 @@ import * as configSignal from 'minimap/js/util/tauri-config-signal.mjs';
88import Root from 'minimap/js/module/Root.mjs' ;
99import ErrorView from 'minimap/js/module/ErrorView.mjs' ;
1010import WorkspaceSelect from 'minimap/js/module/WorkspaceSelect.mjs' ;
11+ import Loading from 'minimap/js/module/Loading.mjs' ;
12+
13+ import { Workspace } from 'minimap/js/api.mjs' ;
1114
1215import './reset.css' ;
1316import './global.css' ;
@@ -21,16 +24,15 @@ S.root(() => {
2124 savedWorkspaces : configSignal . array ( 'workspaces' , [
2225 {
2326 type : 'git' ,
24- remote :
25- 'file:///C:/Users/Anonymous/AppData/Roaming/minimap/test-repo'
27+ remote : 'git@github.com:Qix-/test-minimap.git'
2628 } ,
2729 { type : 'mem' , author : 'Max Mustermann' , email : 'max@example.com' } ,
2830 {
2931 type : 'git' ,
30- remote :
31- 'file:///C:/Users/Anonymous/AppData/Roaming/minimap/test-repo'
32+ remote : 'file:///Z:/tmp/minimap-test-repo'
3233 }
33- ] )
34+ ] ) ,
35+ currentWorkspace : S . data ( )
3436 } ;
3537
3638 if ( typeof window !== 'undefined' ) window . Minimap = Minimap ;
@@ -53,9 +55,63 @@ S.root(() => {
5355 const currentView = S ( ( ) => {
5456 if ( Minimap . errorMessage ( ) ) return < ErrorView { ...Minimap } /> ;
5557
58+ const currentWorkspace = Minimap . currentWorkspace ( ) ;
59+ if ( currentWorkspace && currentWorkspace . workspace )
60+ return ( ) => (
61+ < div >
62+ workspace view:{ ' ' }
63+ { JSON . stringify ( {
64+ ...currentWorkspace ,
65+ workspace : undefined
66+ } ) }
67+ </ div >
68+ ) ;
69+ if ( currentWorkspace && ! currentWorkspace . workspace )
70+ return ( ) => < Loading > { I `loading workspace...` } </ Loading > ;
71+
5672 return ( ) => < WorkspaceSelect { ...Minimap } /> ;
5773 } ) ;
5874
75+ // React to workspace loads
76+ S ( async ( ) => {
77+ const currentWorkspace = Minimap . currentWorkspace ( ) ;
78+ if ( ! currentWorkspace ) return ;
79+ if ( currentWorkspace . workspace ) return ;
80+
81+ switch ( currentWorkspace . type ) {
82+ case 'git' :
83+ if ( ! currentWorkspace . remote ) {
84+ console . error (
85+ "missing required property 'remote' for workspace type 'git':" ,
86+ currentWorkspace
87+ ) ;
88+ Minimap . currentWorkspace ( undefined ) ;
89+ break ;
90+ }
91+
92+ currentWorkspace . workspace = await Workspace . open_git (
93+ currentWorkspace . remote
94+ ) ;
95+
96+ Minimap . currentWorkspace ( currentWorkspace ) ;
97+
98+ break ;
99+ case 'mem' :
100+ currentWorkspace . workspace = await Workspace . open_mem (
101+ currentWorkspace . author ?? '<unknown author>' ,
102+ currentWorkspace . email ?? '<unknown email>'
103+ ) ;
104+
105+ Minimap . currentWorkspace ( currentWorkspace ) ;
106+
107+ break ;
108+ default :
109+ console . error ( 'unknown workspace type:' , currentWorkspace . type ) ;
110+ Minimap . currentWorkspace ( undefined ) ;
111+ break ;
112+ }
113+ } ) ;
114+
59115 // Attach!
60116 document . body . prepend ( < Root view = { currentView } fadeTime = { 150 } /> ) ;
61117} ) ;
0 commit comments