Skip to content

Commit 355e3d9

Browse files
authored
Merge pull request cangzhang#11 from cangzhang/feat/refresh-tree
refactor: use webview
2 parents a506585 + 6f45e5c commit 355e3d9

34 files changed

+1321
-670
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ module.exports = {
1616
'@typescript-eslint/no-explicit-any': 0,
1717
'@typescript-eslint/explicit-module-boundary-types': 0,
1818
'@typescript-eslint/no-non-null-assertion': 0,
19+
'@typescript-eslint/no-empty-function': 0,
20+
'no-case-declarations': 0
1921
}
2022
};

package.json

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,18 @@
5454
]
5555
},
5656
"viewsContainers": {
57-
"activitybar": [
58-
{
59-
"id": "CODING-DEPOT-MR",
60-
"title": "CODING 代码仓库"
61-
}
62-
],
6357
"rightside": [
6458
{
6559
"id": "WebviewContainerId",
66-
"title": "CODING 合并请求详情"
60+
"title": "CODING 代码仓库"
6761
}
6862
]
6963
},
7064
"views": {
71-
"CODING-DEPOT-MR": [
72-
{
73-
"id": "codingPlugin.treeDepotMR",
74-
"name": "CODING 代码仓库"
75-
}
76-
],
7765
"WebviewContainerId": [
7866
{
7967
"id": "codingPlugin.webview",
80-
"title": "CODING 合并请求详情"
68+
"title": "CODING 代码仓库"
8169
}
8270
]
8371
},
@@ -97,7 +85,6 @@
9785
"type": "string",
9886
"description": "请勿修改"
9987
}
100-
10188
}
10289
}
10390
},
@@ -128,13 +115,15 @@
128115
"isomorphic-git": "^1.8.0",
129116
"querystring": "^0.2.0",
130117
"react": "^17.0.1",
131-
"react-dom": "^17.0.1"
118+
"react-dom": "^17.0.1",
119+
"react-select": "^3.1.1"
132120
},
133121
"devDependencies": {
134122
"@types/classnames": "^2.2.11",
135123
"@types/node": "^14.14.7",
136124
"@types/react": "^16.9.56",
137125
"@types/react-dom": "^16.9.9",
126+
"@types/react-select": "^3.0.26",
138127
"@typescript-eslint/eslint-plugin": "^4.7.0",
139128
"@typescript-eslint/parser": "^4.7.0",
140129
"css-loader": "^5.0.1",

src/extension.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import initialize from './initialize';
22
import CodingServer from './services/codingServer';
3-
import WebviewProvider from './webviews';
43
import ACTIONS, { dispatch } from './utils/actions';
54
import { proxyCtx } from './utils/proxy';
65
import toast from './utils/toast';
76
import { readConfig } from './services/dcloud';
87

98
async function activate(context: IContext) {
10-
const webviewProvider = new WebviewProvider(context);
9+
const codingServer = new CodingServer(context);
1110
const repoInfo = await CodingServer.getRepoParams();
12-
console.log('repoInfo: ', repoInfo);
11+
console.warn('repoInfo: ', repoInfo);
1312
const token = await readConfig(`token`);
1413

15-
const codingServer = new CodingServer(context);
16-
1714
dispatch(ACTIONS.SET_CTX, {
1815
context,
1916
value: {
20-
webviewProvider,
17+
webviewProvider: null,
2118
codingServer,
2219
depots: [],
2320
selectedDepot: null,

src/init/createWebview.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import WebviewProvider from '../webviews/depot';
2+
import ACTIONS, { dispatch } from '../utils/actions';
3+
import toast from '../utils/toast';
4+
5+
function createWebview(context: IContext) {
6+
const webviewProvider = new WebviewProvider(context);
7+
dispatch(ACTIONS.SET_WEBVIEW, {
8+
context,
9+
value: webviewProvider,
10+
});
11+
12+
toast.info('温馨提示,若页面没有渲染,请重新打开`插件扩展视图 - CODING 代码仓库`');
13+
}
14+
15+
export default createWebview;

src/init/initCredentials.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import hx from 'hbuilderx';
22
import * as DCloudService from '../services/dcloud';
33
import toast from '../utils/toast';
44
import { refreshTree } from './registerCommands';
5+
import ACTIONS, { dispatch } from '../utils/actions';
56

67
const { executeCommand } = hx.commands;
78

@@ -17,7 +18,7 @@ export async function initCredentials(context: IContext) {
1718
}
1819

1920
const resp = await DCloudService.fetchUser(hbToken);
20-
toast.info(`logged in as DCloud user: ${resp.data.nickname} ${resp.data.email}`);
21+
console.warn(`logged in as DCloud user: ${resp.data.nickname} ${resp.data.email}`);
2122

2223
if (!token) {
2324
await executeCommand('codingPlugin.createTeam');
@@ -29,6 +30,11 @@ export async function initCredentials(context: IContext) {
2930
if (accessToken) {
3031
const userData = await codingServer.getUserInfo(accessToken);
3132
toast.info(`logged in as CODING user: ${userData.name} @ ${userData.team}`);
33+
34+
dispatch(ACTIONS.SET_USER_INFO, {
35+
context: context,
36+
value: userData,
37+
});
3238
}
3339
} catch (err) {
3440
if (Number(err) === 1) {

src/init/initLoginLogout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function initLoginLogout(context: IContext) {
77
onUserLogin(() => {
88
console.warn('login');
99
refreshTree();
10+
context.webviewProvider.refresh();
1011
});
1112

1213
onUserLogout(() => {

src/init/registerCommands.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function registerCommands(context: IContext) {
7272
);
7373

7474
context.subscriptions.push(
75-
registerCommand('codingPlugin.createDepot', async function (param: any) {
75+
registerCommand('codingPlugin.createDepot', async function (callback: any) {
7676
const depot = await showInputBox({
7777
prompt: '请输入仓库名',
7878
});
@@ -84,13 +84,22 @@ export default function registerCommands(context: IContext) {
8484

8585
const team = context.userInfo.team;
8686
const result = await codingServer.createDepot(team, depot, depot);
87+
const webview = context.webviewProvider?.panel.webView;
8788
if (result) {
89+
webview.postMessage({
90+
command: 'create.depot.success',
91+
data: result,
92+
});
8893
const res = await toast.info('仓库创建成功,是否切换到该仓库?', ['是', '否']);
8994
if (res === '是') {
9095
dispatch(ACTIONS.SET_SELECTED_DEPOT, {
9196
context,
9297
value: result,
9398
});
99+
webview.postMessage({
100+
command: 'create.depot.switch',
101+
data: result,
102+
});
94103
}
95104
refreshTree();
96105
}
@@ -122,6 +131,7 @@ export default function registerCommands(context: IContext) {
122131
value: newToken,
123132
});
124133
refreshTree();
134+
context.webviewProvider.refresh();
125135
}
126136
} catch {
127137
toast.error(`个人令牌无效`);
@@ -166,6 +176,7 @@ export default function registerCommands(context: IContext) {
166176
value: result.Token,
167177
});
168178
refreshTree();
179+
context.webviewProvider.refresh();
169180
}
170181
} catch (err) {
171182
toast.error(`创建团队失败`);

src/initialize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import createTreeViews from './init/createTreeViews';
2+
import createWebview from './init/createWebview';
23
import initWorkspace from './init/initWorkspace';
34
import { initCredentials } from './init/initCredentials';
45
import registerCommands from './init/registerCommands';
@@ -13,5 +14,6 @@ export default function initialize(context: IContext) {
1314
initCredentials(context);
1415
registerCommands(context);
1516
createTreeViews(context);
17+
createWebview(context);
1618
initWorkspace(context);
1719
}

0 commit comments

Comments
 (0)