Skip to content

Commit

Permalink
Add button to go to course details in open exercise warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Heliozoa committed Nov 7, 2024
1 parent aaf7ead commit 93215ab
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion shared/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type CourseDetailsPanel = {
exerciseGroups?: Array<ExerciseGroup>;
updateableExercises?: Array<number>;
disabled?: boolean;
exerciseStatuses: Record<number, ExerciseStatus>;
exerciseStatuses?: Record<number, ExerciseStatus>;
};

export type SelectOrganizationPanel = {
Expand Down
1 change: 0 additions & 1 deletion src/actions/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export async function displayLocalCourseDetails(
type: "CourseDetails",
id: randomPanelId(),
courseId: course.id,
exerciseStatuses: {},
};
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);

Expand Down
19 changes: 16 additions & 3 deletions src/actions/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* -------------------------------------------------------------------------------------------------
*/

import * as vscode from "vscode";

import { compact } from "lodash";
import { Ok, Result } from "ts-results";
import { ExerciseStatus } from "../api/workspaceManager";
import { TmcPanel } from "../panels/TmcPanel";
import { ExtensionToWebview } from "../shared/shared";
import { randomPanelId, TmcPanel } from "../panels/TmcPanel";
import { CourseDetailsPanel, ExtensionToWebview } from "../shared/shared";
import { Logger } from "../utilities";
import * as systeminformation from "systeminformation";
import { ActionContext } from "./types";
Expand All @@ -18,6 +20,7 @@ import { ActionContext } from "./types";
* @param exerciseIdsToOpen Array of exercise IDs
*/
export async function openExercises(
context: vscode.ExtensionContext,
actionContext: ActionContext,
exerciseIdsToOpen: number[],
courseName: string,
Expand Down Expand Up @@ -52,7 +55,6 @@ export async function openExercises(

// check open exercise count and warn if it's too high
const under8GbRam = (await systeminformation.mem()).available < 9_000_000_000;
dialog.warningNotification(`${(await systeminformation.mem()).available}`);
const weakThreshold = 50;
const strongThreshold = 100;
const warningThreshold = under8GbRam ? weakThreshold : strongThreshold;
Expand All @@ -62,6 +64,17 @@ export async function openExercises(
if (openExercises.length > warningThreshold) {
dialog.warningNotification(
`You have over ${warningThreshold} exercises open, which may cause performance issues. You can close completed exercises from the TMC extension menu in the sidebar.`,
[
"Open course details",
(): void => {
const panel: CourseDetailsPanel = {
id: randomPanelId(),
type: "CourseDetails",
courseId: course.id,
};
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);
},
],
);
}

Expand Down
1 change: 0 additions & 1 deletion src/init/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export function registerCommands(
id: randomPanelId(),
type: "CourseDetails",
courseId,
exerciseStatuses: {},
});
}
}),
Expand Down
3 changes: 1 addition & 2 deletions src/panels/TmcPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ export class TmcPanel {
id: randomPanelId(),
type: "CourseDetails",
courseId: message.courseId,
exerciseStatuses: {},
},
webview,
);
Expand Down Expand Up @@ -616,6 +615,7 @@ export class TmcPanel {

// now, actually open the exercises
const result = await openExercises(
extensionContext,
actionContext,
message.ids,
message.courseName,
Expand Down Expand Up @@ -655,7 +655,6 @@ export class TmcPanel {
id: randomPanelId(),
type: "CourseDetails",
courseId: courseId,
exerciseStatuses: {},
},
webview,
);
Expand Down
2 changes: 2 additions & 0 deletions webview-ui/src/components/Card.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<script lang="ts"></script>

<div class="card">
<slot />
</div>
Expand Down
8 changes: 7 additions & 1 deletion webview-ui/src/panels/CourseDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
break;
}
case "exerciseStatusChange": {
if (panel.exerciseStatuses === undefined) {
panel.exerciseStatuses = {};
}
panel.exerciseStatuses[message.exerciseId] = message.status;
savePanelState(panel);
break;
Expand All @@ -58,6 +61,9 @@
break;
}
case "exerciseStatusChange": {
if (panel.exerciseStatuses === undefined) {
panel.exerciseStatuses = {};
}
panel.exerciseStatuses[message.exerciseId] = message.status;
savePanelState(panel);
break;
Expand Down Expand Up @@ -237,7 +243,7 @@
<div class="exercise-part">
<ExercisePart
{exerciseGroup}
exerciseStatuses={panel.exerciseStatuses}
exerciseStatuses={panel.exerciseStatuses ?? {}}
bind:checkedExercises={$checkedExercises}
onDownloadAll={(exercises) =>
panel.course && downloadExercises(panel.course, exercises)}
Expand Down

0 comments on commit 93215ab

Please sign in to comment.