Skip to content

Commit

Permalink
feat: Refresh the explorer after submitting (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Jun 3, 2019
1 parent cdb46d0 commit 41b3d32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/commands/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import { leetCodeTreeDataProvider } from "../explorer/LeetCodeTreeDataProvider";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
Expand All @@ -24,5 +25,8 @@ export async function submitSolution(uri?: vscode.Uri): Promise<void> {
leetCodeSubmissionProvider.show(result);
} catch (error) {
await promptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.", DialogType.error);
return;
}

leetCodeTreeDataProvider.refresh();
}
13 changes: 8 additions & 5 deletions src/explorer/LeetCodeTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import { LeetCodeNode } from "./LeetCodeNode";

export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCodeNode> {

private onDidChangeTreeDataEvent: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
private context: vscode.ExtensionContext;

private onDidChangeTreeDataEvent: vscode.EventEmitter<LeetCodeNode | undefined | null> = new vscode.EventEmitter<LeetCodeNode | undefined | null>();
// tslint:disable-next-line:member-ordering
public readonly onDidChangeTreeData: vscode.Event<any> = this.onDidChangeTreeDataEvent.event;

constructor(private context: vscode.ExtensionContext) { }
public initialize(context: vscode.ExtensionContext): void {
this.context = context;
}

public async refresh(): Promise<void> {
await explorerNodeManager.refreshCache();
Expand All @@ -26,7 +30,6 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
if (element.id === "notSignIn") {
return {
label: element.name,
id: element.id,
collapsibleState: vscode.TreeItemCollapsibleState.None,
command: {
command: "leetcode.signin",
Expand All @@ -35,11 +38,9 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
};
}

const idPrefix: number = Date.now();
return {
label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
tooltip: this.getSubCategoryTooltip(element),
id: `${idPrefix}.${element.id}`,
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
contextValue: element.isProblem ? "problem" : element.id.toLowerCase(),
iconPath: this.parseIconPathFromProblemState(element),
Expand Down Expand Up @@ -128,3 +129,5 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
].join(os.EOL);
}
}

export const leetCodeTreeDataProvider: LeetCodeTreeDataProvider = new LeetCodeTreeDataProvider();
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as submit from "./commands/submit";
import * as test from "./commands/test";
import { explorerNodeManager } from "./explorer/explorerNodeManager";
import { LeetCodeNode } from "./explorer/LeetCodeNode";
import { LeetCodeTreeDataProvider } from "./explorer/LeetCodeTreeDataProvider";
import { leetCodeTreeDataProvider } from "./explorer/LeetCodeTreeDataProvider";
import { leetCodeChannel } from "./leetCodeChannel";
import { leetCodeExecutor } from "./leetCodeExecutor";
import { leetCodeManager } from "./leetCodeManager";
Expand All @@ -34,7 +34,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
leetCodeTreeDataProvider.refresh();
});

const leetCodeTreeDataProvider: LeetCodeTreeDataProvider = new LeetCodeTreeDataProvider(context);
leetCodeTreeDataProvider.initialize(context);

context.subscriptions.push(
leetCodeStatusBarController,
Expand Down

0 comments on commit 41b3d32

Please sign in to comment.