Skip to content

Commit 60663e6

Browse files
committed
Improve UX
1 parent 8fb8c0e commit 60663e6

6 files changed

Lines changed: 52 additions & 29 deletions

File tree

src/commons.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ export default class Commons {
113113
const extSettings = this.GetSettings();
114114
const cusSettings = await this.GetCustomSettings();
115115

116-
if (
117-
cusSettings.downloadPublicGist
118-
? !extSettings.gist
119-
: !cusSettings.token || !extSettings.gist
120-
) {
121-
this.webviewService.OpenLandingPage();
122-
}
123-
124116
settings.customConfig = cusSettings;
125117
settings.extConfig = extSettings;
126118
return settings;

src/service/github.oauth.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class GitHubOAuthService {
1414
this.app.use(express.json(), express.urlencoded({ extended: false }));
1515
}
1616

17-
public async StartProcess() {
17+
public async StartProcess(cmd?: string) {
1818
const customSettings = await state.commons.GetCustomSettings();
1919
const host = customSettings.githubEnterpriseUrl
2020
? new URL(customSettings.githubEnterpriseUrl)
@@ -60,9 +60,7 @@ export class GitHubOAuthService {
6060

6161
const gists: any[] = await this.getGists(token, user, host);
6262

63-
if (gists.length) {
64-
state.commons.webviewService.OpenGistSelectionpage(gists);
65-
}
63+
state.commons.webviewService.OpenGistSelectionpage(gists, cmd)
6664
} catch (err) {
6765
const error = new Error(err);
6866
Commons.LogException(error, state.commons.ERROR_MESSAGE, true);

src/service/webview.service.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ export class WebviewService {
189189
{
190190
find: "@GISTS",
191191
replace: "gists"
192+
},
193+
{
194+
find: "@SKIP",
195+
replace: "skip"
192196
}
193197
]
194198
}
@@ -316,7 +320,7 @@ export class WebviewService {
316320
}
317321
}
318322

319-
public OpenLandingPage() {
323+
public OpenLandingPage(cmd?: string) {
320324
const webview = this.webviews[0];
321325
const releaseNotes = require("../../release-notes.json");
322326
const content: string = this.GenerateContent({
@@ -327,7 +331,7 @@ export class WebviewService {
327331
if (webview.webview) {
328332
webview.webview.webview.html = content;
329333
webview.webview.reveal();
330-
return webview;
334+
return webview.webview;
331335
}
332336
const landingPanel = vscode.window.createWebviewPanel(
333337
"landingPage",
@@ -341,7 +345,7 @@ export class WebviewService {
341345
landingPanel.webview.onDidReceiveMessage(async message => {
342346
switch (message.command) {
343347
case "loginWithGitHub":
344-
new GitHubOAuthService(54321).StartProcess();
348+
new GitHubOAuthService(54321).StartProcess(cmd);
345349
const customSettings = await state.commons.GetCustomSettings();
346350
const host = customSettings.githubEnterpriseUrl
347351
? new URL(customSettings.githubEnterpriseUrl)
@@ -398,17 +402,20 @@ export class WebviewService {
398402
return landingPanel;
399403
}
400404

401-
public OpenGistSelectionpage(gists: any) {
405+
public OpenGistSelectionpage(gists: any, cmd?: string) {
402406
const webview = this.webviews[2];
403407
const content: string = this.GenerateContent({
404408
content: webview.htmlContent,
405409
items: webview.replaceables,
406-
gists
410+
gists,
411+
skip: cmd !== "extension.downloadSettings"
412+
? `<a href="#" onclick="vscode.postMessage({close: true});" title="Skip (new one will be created upon first upload)" class="btn btn-primary mt-4">Skip (new one will be created upon first upload)</a>`
413+
: ""
407414
});
408415
if (webview.webview) {
409416
webview.webview.webview.html = content;
410417
webview.webview.reveal();
411-
return webview;
418+
return webview.webview;
412419
}
413420
const gistSelectionPanel = vscode.window.createWebviewPanel(
414421
"selectGist",
@@ -428,6 +435,9 @@ export class WebviewService {
428435
} else {
429436
gistSelectionPanel.dispose();
430437
}
438+
if (cmd) {
439+
vscode.commands.executeCommand(cmd);
440+
}
431441
});
432442
webview.webview = gistSelectionPanel;
433443
gistSelectionPanel.onDidDispose(() => (webview.webview = null));

src/sync.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ export class Sync {
6969
// @ts-ignore
7070
const args = arguments;
7171
let github: GitHubService = null;
72-
let localConfig = new LocalConfig();
72+
const localConfig = await state.commons.InitalizeSettings();
73+
74+
if (!localConfig.customConfig.token) {
75+
state.commons.webviewService.OpenLandingPage("extension.updateSettings");
76+
return;
77+
}
78+
7379
const allSettingFiles: File[] = [];
7480
let uploadedExtensions: ExtensionInformation[] = [];
7581
const ignoredExtensions: ExtensionInformation[] = [];
7682
const dateNow = new Date();
7783
await state.commons.HandleStopWatching();
7884

7985
try {
80-
localConfig = await state.commons.InitalizeSettings();
8186
localConfig.publicGist = false;
8287
if (args.length > 0) {
8388
if (args[0] === "publicGIST") {
@@ -434,11 +439,22 @@ export class Sync {
434439
* Download setting from github gist
435440
*/
436441
public async download(): Promise<void> {
437-
let localSettings: LocalConfig = new LocalConfig();
442+
const localSettings: LocalConfig = await state.commons.InitalizeSettings();
443+
444+
if (
445+
localSettings.customConfig.downloadPublicGist
446+
? !localSettings.extConfig.gist
447+
: !localSettings.customConfig.token || !localSettings.extConfig.gist
448+
) {
449+
state.commons.webviewService.OpenLandingPage(
450+
"extension.downloadSettings"
451+
);
452+
return;
453+
}
454+
438455
await state.commons.HandleStopWatching();
439456

440457
try {
441-
localSettings = await state.commons.InitalizeSettings();
442458
await StartDownload(localSettings.extConfig, localSettings.customConfig);
443459
} catch (err) {
444460
Commons.LogException(err, state.commons.ERROR_MESSAGE, true);

ui/gist-selection/gist-selection.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ <h3 class="mx-auto mt-2 mb-3 text-white-50a">
3030
Select Your Existing Gist
3131
</h3>
3232
<div id="selectionContainer" class="list-group mx-auto text-left"></div>
33-
<a
34-
href="#"
35-
onclick="vscode.postMessage({close: true});"
36-
title="Skip (new one will be created automatically)"
37-
class="btn btn-primary mt-4"
38-
>Skip (new one will be created automatically)</a
39-
>
33+
<div id="skipContainer"></div>
4034
</div>
4135
<div
4236
class="modal fade"
@@ -90,6 +84,7 @@ <h5 class="modal-title" id="exampleModalCenterTitle">
9084
<font-injector></font-injector>
9185
<script defer>
9286
const gists = JSON.parse(`@GISTS`);
87+
const skip = @SKIP;
9388
</script>
9489
<script defer src="@PWD/ui/gist-selection/gist-selection.js"></script>
9590
</body>

ui/gist-selection/gist-selection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// @ts-nocheck
22

3+
function appendHTML(parent, html) {
4+
var div = document.createElement("div");
5+
div.innerHTML = html;
6+
while (div.children.length > 0) {
7+
parent.appendChild(div.children[0]);
8+
}
9+
div.remove();
10+
}
11+
312
const vscode = acquireVsCodeApi();
413

514
/* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */
@@ -52,6 +61,9 @@ document
5261
document.body.className.includes("vscode-dark") ? "bg-dark" : "bg-light"
5362
);
5463

64+
const skipContainer = document.querySelector("#skipContainer");
65+
appendHTML(skipContainer, skip);
66+
5567
const selectionTemplate = `
5668
<button type="button" onclick="saveGistId('@id')" class="list-group-item list-group-item-action">@description (@id) – Updated @timestamp ago</button>`;
5769

0 commit comments

Comments
 (0)