Skip to content

Commit 26e8bcc

Browse files
committed
add loading and workspace instance opening
1 parent befed87 commit 26e8bcc

File tree

5 files changed

+96
-9
lines changed

5 files changed

+96
-9
lines changed

minimap-app/www-src/js/api.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ class Project {
125125
export class Workspace {
126126
static async open_git(remote) {
127127
const id = await invoke('git_workspace_open', { remote });
128-
return new GitWorkspace(id, 'git');
128+
return new Workspace(id, 'git');
129129
}
130130

131-
static async open_temporary(author, email) {
131+
static async open_mem(author, email) {
132132
const id = await invoke('mem_workspace_open', { author, email });
133133
return new Workspace(id, 'mem');
134134
}

minimap-app/www-src/js/index.mjs

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import * as configSignal from 'minimap/js/util/tauri-config-signal.mjs';
88
import Root from 'minimap/js/module/Root.mjs';
99
import ErrorView from 'minimap/js/module/ErrorView.mjs';
1010
import 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

1215
import './reset.css';
1316
import './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
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@keyframes loading-fadeinout {
2+
0% {
3+
opacity: 0.5;
4+
}
5+
50% {
6+
opacity: 1;
7+
}
8+
100% {
9+
opacity: 0.5;
10+
}
11+
}
12+
13+
.root {
14+
text-transform: uppercase;
15+
animation: loading-fadeinout 900ms infinite;
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Surplus from 'surplus';
2+
3+
import I from 'minimap/js/util/i18n.mjs';
4+
import sig from 'minimap/js/util/sig.mjs';
5+
6+
import * as C from './Loading.css';
7+
8+
export default ({ children }) => (
9+
<div className={C.root}>
10+
{children?.length > 0 ? children : I`loading...`}
11+
</div>
12+
);

minimap-app/www-src/js/module/WorkspaceSelect.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const TYPE_TAGS = {
2424
]
2525
};
2626

27-
export default ({ savedWorkspaces }) => {
27+
export default ({ savedWorkspaces, currentWorkspace }) => {
2828
return (
2929
<div className={C.root}>
3030
<div className={C.logoContainer}>
@@ -36,7 +36,10 @@ export default ({ savedWorkspaces }) => {
3636
{savedWorkspaces.map(workspace => {
3737
const TypeTag = TYPE_TAGS[workspace.type];
3838
return (
39-
<button className={C.workspace}>
39+
<button
40+
className={C.workspace}
41+
onClick={() => currentWorkspace(workspace)}
42+
>
4043
<TypeTag {...workspace} />
4144
</button>
4245
);

0 commit comments

Comments
 (0)