Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve UX
  • Loading branch information
shanalikhan authored Jul 18, 2019
2 parents 8fb8c0e + 7e37e49 commit 4fdfc25
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 38 deletions.
8 changes: 0 additions & 8 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ export default class Commons {
const extSettings = this.GetSettings();
const cusSettings = await this.GetCustomSettings();

if (
cusSettings.downloadPublicGist
? !extSettings.gist
: !cusSettings.token || !extSettings.gist
) {
this.webviewService.OpenLandingPage();
}

settings.customConfig = cusSettings;
settings.extConfig = extSettings;
return settings;
Expand Down
6 changes: 2 additions & 4 deletions src/service/github.oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class GitHubOAuthService {
this.app.use(express.json(), express.urlencoded({ extended: false }));
}

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

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

if (gists.length) {
state.commons.webviewService.OpenGistSelectionpage(gists);
}
state.commons.webviewService.OpenGistSelectionpage(gists, cmd);
} catch (err) {
const error = new Error(err);
Commons.LogException(error, state.commons.ERROR_MESSAGE, true);
Expand Down
37 changes: 24 additions & 13 deletions src/service/webview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export class WebviewService {
{
find: "@RELEASE_NOTES",
replace: "releaseNotes"
},
{
find: "@CHECKED",
replace: "checked"
}
]
},
Expand Down Expand Up @@ -189,6 +193,10 @@ export class WebviewService {
{
find: "@GISTS",
replace: "gists"
},
{
find: "@SKIP",
replace: "skip"
}
]
}
Expand Down Expand Up @@ -306,28 +314,24 @@ export class WebviewService {
}

public IsLandingPageEnabled(): boolean {
const dontShowThisAgain = state.context.globalState.get<boolean>(
return !state.context.globalState.get<boolean>(
"landingPage.dontShowThisAgain"
);
if (dontShowThisAgain) {
return false;
} else {
return true;
}
}

public OpenLandingPage() {
public OpenLandingPage(cmd?: string) {
const webview = this.webviews[0];
const releaseNotes = require("../../release-notes.json");
const content: string = this.GenerateContent({
content: webview.htmlContent,
items: webview.replaceables,
releaseNotes
releaseNotes,
checked: this.IsLandingPageEnabled()
});
if (webview.webview) {
webview.webview.webview.html = content;
webview.webview.reveal();
return webview;
return webview.webview;
}
const landingPanel = vscode.window.createWebviewPanel(
"landingPage",
Expand All @@ -341,7 +345,7 @@ export class WebviewService {
landingPanel.webview.onDidReceiveMessage(async message => {
switch (message.command) {
case "loginWithGitHub":
new GitHubOAuthService(54321).StartProcess();
new GitHubOAuthService(54321).StartProcess(cmd);
const customSettings = await state.commons.GetCustomSettings();
const host = customSettings.githubEnterpriseUrl
? new URL(customSettings.githubEnterpriseUrl)
Expand Down Expand Up @@ -398,17 +402,21 @@ export class WebviewService {
return landingPanel;
}

public OpenGistSelectionpage(gists: any) {
public OpenGistSelectionpage(gists: any, cmd?: string) {
const webview = this.webviews[2];
const content: string = this.GenerateContent({
content: webview.htmlContent,
items: webview.replaceables,
gists
gists,
skip:
cmd !== "extension.downloadSettings"
? `<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>`
: ""
});
if (webview.webview) {
webview.webview.webview.html = content;
webview.webview.reveal();
return webview;
return webview.webview;
}
const gistSelectionPanel = vscode.window.createWebviewPanel(
"selectGist",
Expand All @@ -428,6 +436,9 @@ export class WebviewService {
} else {
gistSelectionPanel.dispose();
}
if (cmd) {
vscode.commands.executeCommand(cmd);
}
});
webview.webview = gistSelectionPanel;
gistSelectionPanel.onDidDispose(() => (webview.webview = null));
Expand Down
24 changes: 20 additions & 4 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ export class Sync {
// @ts-ignore
const args = arguments;
let github: GitHubService = null;
let localConfig = new LocalConfig();
const localConfig = await state.commons.InitalizeSettings();

if (!localConfig.customConfig.token) {
state.commons.webviewService.OpenLandingPage("extension.updateSettings");
return;
}

const allSettingFiles: File[] = [];
let uploadedExtensions: ExtensionInformation[] = [];
const ignoredExtensions: ExtensionInformation[] = [];
const dateNow = new Date();
await state.commons.HandleStopWatching();

try {
localConfig = await state.commons.InitalizeSettings();
localConfig.publicGist = false;
if (args.length > 0) {
if (args[0] === "publicGIST") {
Expand Down Expand Up @@ -434,11 +439,22 @@ export class Sync {
* Download setting from github gist
*/
public async download(): Promise<void> {
let localSettings: LocalConfig = new LocalConfig();
const localSettings: LocalConfig = await state.commons.InitalizeSettings();

if (
localSettings.customConfig.downloadPublicGist
? !localSettings.extConfig.gist
: !localSettings.customConfig.token || !localSettings.extConfig.gist
) {
state.commons.webviewService.OpenLandingPage(
"extension.downloadSettings"
);
return;
}

await state.commons.HandleStopWatching();

try {
localSettings = await state.commons.InitalizeSettings();
await StartDownload(localSettings.extConfig, localSettings.customConfig);
} catch (err) {
Commons.LogException(err, state.commons.ERROR_MESSAGE, true);
Expand Down
9 changes: 2 additions & 7 deletions ui/gist-selection/gist-selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ <h3 class="mx-auto mt-2 mb-3 text-white-50a">
Select Your Existing Gist
</h3>
<div id="selectionContainer" class="list-group mx-auto text-left"></div>
<a
href="#"
onclick="vscode.postMessage({close: true});"
title="Skip (new one will be created automatically)"
class="btn btn-primary mt-4"
>Skip (new one will be created automatically)</a
>
<div id="skipContainer"></div>
</div>
<div
class="modal fade"
Expand Down Expand Up @@ -90,6 +84,7 @@ <h5 class="modal-title" id="exampleModalCenterTitle">
<font-injector></font-injector>
<script defer>
const gists = JSON.parse(`@GISTS`);
const skip = @SKIP;
</script>
<script defer src="@PWD/ui/gist-selection/gist-selection.js"></script>
</body>
Expand Down
12 changes: 12 additions & 0 deletions ui/gist-selection/gist-selection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// @ts-nocheck

function appendHTML(parent, html) {
var div = document.createElement("div");
div.innerHTML = html;
while (div.children.length > 0) {
parent.appendChild(div.children[0]);
}
div.remove();
}

const vscode = acquireVsCodeApi();

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

const skipContainer = document.querySelector("#skipContainer");
appendHTML(skipContainer, skip);

const selectionTemplate = `
<button type="button" onclick="saveGistId('@id')" class="list-group-item list-group-item-action">@description (@id) – Updated @timestamp ago</button>`;

Expand Down
5 changes: 3 additions & 2 deletions ui/landing-page/landing-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ <h3 class="mx-auto mb-3 text-white-50a">
>Questions & Issues</a
>
<br />
<a href="https://github.com/shanalikhan/code-settings-sync/blob/master/CONTRIBUTING.md"
<a
href="https://github.com/shanalikhan/code-settings-sync/blob/master/CONTRIBUTING.md"
>Contribute</a
>
<br />
Expand All @@ -154,7 +155,6 @@ <h3 class="mb-3">Sponsors</h3>
class="custom-control-input checkbox"
type="checkbox"
id="customCheck1"
checked="true"
onclick="sendCommand('dontShowThisAgain', !this.checked)"
/>
<label for="customCheck1" class="custom-control-label">
Expand All @@ -167,6 +167,7 @@ <h3 class="mb-3">Sponsors</h3>
<font-injector></font-injector>
<script defer>
const releaseNotes = JSON.parse(`@RELEASE_NOTES`);
const checked = "@CHECKED";
</script>
<script defer src="@PWD/ui/landing-page/landing-page.js"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions ui/landing-page/landing-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ releaseNotes.changes.forEach(change => {

const currentVersionElement = document.querySelector("#current-version");
currentVersionElement.innerHTML = releaseNotes.currentVersion;

document.querySelector("#customCheck1").checked = checked === "true";

0 comments on commit 4fdfc25

Please sign in to comment.