Skip to content

Commit 38ce868

Browse files
committed
Show Welcome login view when not currently logged in
1 parent 4f3b883 commit 38ce868

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
{
7777
"command": "treeView.refreshList",
78-
"title": "Refresh!",
78+
"title": "Refresh",
7979
"icon": "src/icon/refresh.svg"
8080
}
8181
],
@@ -87,7 +87,13 @@
8787
"group": "navigation"
8888
}
8989
]
90-
}
90+
},
91+
"viewsWelcome": [
92+
{
93+
"view": "mdTreeItems",
94+
"contents": "No notes found. Login first.\n[Login HackMD](command:HackMD.login)"
95+
}
96+
]
9197
},
9298
"scripts": {
9399
"vscode:prepublish": "webpack --mode production",

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ const login = async (context: vscode.ExtensionContext) => {
253253
}
254254
await API.login(email, password);
255255
if (await checkLogin()) {
256+
store.isLogin = true;
257+
context.globalState.update('isLogin', true);
256258
vscode.window.showInformationMessage('Successfully login!');
257259
} else {
258260
vscode.window.showInformationMessage('Wrong email or password, please enter again');
@@ -313,6 +315,8 @@ export async function activate(context: vscode.ExtensionContext) {
313315
return;
314316
}
315317
await API.logout();
318+
store.isLogin = false;
319+
context.globalState.update('isLogin', false);
316320
vscode.window.showInformationMessage('Successfully logged out.');
317321
await refreshHistoryList(context);
318322
}));

src/mdTreeView.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { Store } from './store';
2+
import { Store, store } from './store';
33
import { reaction } from 'mobx';
44
// const history = (await API.getHistory()).history;
55
export class MdTreeItemProvider implements vscode.TreeDataProvider<TreeNode> {
@@ -21,12 +21,14 @@ export class MdTreeItemProvider implements vscode.TreeDataProvider<TreeNode> {
2121
}
2222

2323
getChildren(element?: TreeNode): vscode.ProviderResult<TreeNode[]> {
24-
if (element === undefined) {
25-
return [new TreeNode("history", vscode.TreeItemCollapsibleState.Collapsed)]
26-
} else {
27-
return this.store.history.map(item =>
28-
new NoteTreeNode(item.id, item.text, vscode.TreeItemCollapsibleState.None)
29-
);
24+
if (store.isLogin) {
25+
if (element === undefined) {
26+
return [new TreeNode("history", vscode.TreeItemCollapsibleState.Collapsed)]
27+
} else {
28+
return this.store.history.map(item =>
29+
new NoteTreeNode(item.id, item.text, vscode.TreeItemCollapsibleState.None)
30+
);
31+
}
3032
}
3133
}
3234

src/store/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { observable } from "mobx";
22

33
export interface Store {
4-
history: Array<any>
4+
history: Array<any>;
5+
isLogin: boolean;
56
}
67

78
export const store: Store = observable({
8-
history: [{}]
9+
history: [{}],
10+
isLogin: false
911
});

0 commit comments

Comments
 (0)