Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not block on invalid token #258

Merged
merged 1 commit into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,22 @@ export default async function execute<T>(
? INVALID_TOKEN_MSG(environment)
: MISSING_TOKEN_MSG(environment);

// Get the user's action.
const selectedButton = await window.showErrorMessage(
// Get the user's action. We cannot use async/await here since this
// will block processing.
window.showErrorMessage(
`${msg} To correctly set up your token in Visual Studio Code, click the Instructions button below.`,
VIEW_INSTRUCTIONS_ACTION,
OPEN_SETTINGS_ACTION,
);

// Handle the action.
if (selectedButton === VIEW_INSTRUCTIONS_ACTION) {
// Open the instructions in the user's web browser.
env.openExternal(TOKEN_INSTUCTIONS_URL);
} else if (selectedButton === OPEN_SETTINGS_ACTION) {
// Open the token settings.
commands.executeCommand("dodona.settings.token");
}
).then(action => {
// Handle the action.
if (action === VIEW_INSTRUCTIONS_ACTION) {
// Open the instructions in the user's web browser.
env.openExternal(TOKEN_INSTUCTIONS_URL);
} else if (action === OPEN_SETTINGS_ACTION) {
// Open the token settings.
commands.executeCommand("dodona.settings.token");
}
});
}

// Empty response.
Expand Down
9 changes: 5 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commands, ExtensionContext, window, workspace } from "vscode";
import RootDataProvider from "./treeView/dataProvider";
import { createNewExercise } from "./commands/createNewExercise";
import { getApiEnvironment } from "./configuration";
import { CONFIG_KEY, getApiEnvironment } from "./configuration";
import { openCourse } from "./commands/openCourse";
import { openSeries } from "./commands/openSeries";
import { submitSolution } from "./commands/submitSolution";
Expand Down Expand Up @@ -99,11 +99,12 @@ export function activate(context: ExtensionContext) {

// Register and create the activity tree view for the plugin.
window.registerTreeDataProvider("dodona-activities", treeDataProvider);
window.createTreeView("dodona-activities", { treeDataProvider });

// Refresh the treeview when the API domain is changed.
workspace.onDidChangeConfiguration(() => {
treeDataProvider.refresh();
workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(CONFIG_KEY)) {
treeDataProvider.refresh();
}
});

notificationsInterval();
Expand Down
44 changes: 21 additions & 23 deletions src/treeView/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { AbstractTreeItem } from "./items/abstractTreeItem";
import execute from "../api/client";
import { YearTreeItem } from "./items/yearTreeItem";
import {
getCourseFilter,
getSortOption,
getYearFilter,
getCourseFilter,
} from "../configuration";
import { Course } from "../api/resources/course";

Expand All @@ -23,9 +23,7 @@ import { Course } from "../api/resources/course";

export default class RootDataProvider
implements TreeDataProvider<AbstractTreeItem> {
private _onDidChangeTreeData: EventEmitter<
AbstractTreeItem | undefined
> = new EventEmitter<AbstractTreeItem | undefined>();
private _onDidChangeTreeData: EventEmitter<AbstractTreeItem | undefined> = new EventEmitter<AbstractTreeItem | undefined>();
readonly onDidChangeTreeData: Event<AbstractTreeItem | undefined> = this
._onDidChangeTreeData.event;

Expand All @@ -38,19 +36,19 @@ export default class RootDataProvider
}

// Get the courses the user is subscribed to.
return (
execute(dodona => dodona.courses.subscribed)
// Sort courses & apply filters
.then(cs =>
RootDataProvider.sortCourses(this.filterCourses(cs || [])),
)
// Convert them to tree items.
.then(cs =>
this.getYears(cs).map(
y => new YearTreeItem(y, this.getCoursesForYear(y, cs)),
),
)
);
return execute(dodona => dodona.courses.subscribed)
// Sort courses & apply filters
.then(cs =>
RootDataProvider.sortCourses(this.filterCourses(cs || [])),
)
// Convert them to tree items.
.then(cs =>
this.getYears(cs).map(
y => new YearTreeItem(y, this.getCoursesForYear(y, cs)),
),
)
// Error handling.
.catch(() => []);
}

/**
Expand Down Expand Up @@ -90,12 +88,12 @@ export default class RootDataProvider
a.year < b.year
? 1
: a.year > b.year
? -1
: a.name < b.name
? priority
: a.name > b.name
? -priority
: 0,
? -1
: a.name < b.name
? priority
: a.name > b.name
? -priority
: 0,
);
}

Expand Down