Skip to content

Commit

Permalink
Remove sample classes on tour close
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhxNguyen7 committed Jan 26, 2024
1 parent 491c612 commit 79836ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apps/antalmanac/src/components/Tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { useTour } from '@reactour/tour';
import { useEffect, useMemo } from 'react';
import { stepsFactory, tourShouldRun } from '$lib/TutorialHelpers';
import useCoursePaneStore from '$stores/CoursePaneStore';
import { removeSampleClasses } from '$lib/tourExampleGeneration';

export function Tutorial() {
const { setCurrentStep, setIsOpen, setSteps } = useTour();
const { setCurrentStep, setIsOpen, setSteps, isOpen } = useTour();
const [displaySearch, disableManualSearch] = useCoursePaneStore((state) => [
state.displaySearch,
state.disableManualSearch,
Expand All @@ -26,6 +27,12 @@ export function Tutorial() {

useEffect(() => setIsOpen(tourShouldRun), [setIsOpen]);

// Remove sample classes when the tour is closed.
useEffect(() => {
if (isOpen) return;
removeSampleClasses();
}, [isOpen]);

// The steps need to be generated here, in the component, because Reactour hooks can only be used in components.
useEffect(() => {
if (setSteps == null || setCurrentStep == null) return;
Expand Down
11 changes: 10 additions & 1 deletion apps/antalmanac/src/lib/tourExampleGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
} from 'peterportal-api-next-types';
import AppStore from '$stores/AppStore';

const CURRENT_TERM = '2024 Winter'; // TODO: Check the current term when that PR's in
let sampleClassesSectionCodes: Array<string> = [];

export function addSampleClasses() {
if (AppStore.getAddedCourses().length > 0) return;

Expand Down Expand Up @@ -54,9 +57,15 @@ export function addSampleClasses() {

sampleClasses.forEach((sampleClass) => {
AppStore.addCourse(sampleClass);
sampleClassesSectionCodes.push(sampleClass.section.sectionCode);
});
}

export function removeSampleClasses() {
AppStore.deleteCourses(sampleClassesSectionCodes, CURRENT_TERM);
sampleClassesSectionCodes = [];
}

export function randint(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Expand Down Expand Up @@ -158,7 +167,7 @@ export function sampleClassFactory({
courseTitle: courseTitle,
deptCode: deptCode,
prerequisiteLink: '',
term: '2024 Winter', // TODO: Check the current term when that PR's in
term: CURRENT_TERM,
section: {
color: '#FF0000',
instructors: instructors,
Expand Down
6 changes: 6 additions & 0 deletions apps/antalmanac/src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ class AppStore extends EventEmitter {
this.emit('addedCoursesChange');
}

deleteCourses(sectionCodes: string[], term: string) {
sectionCodes.forEach((sectionCode) => this.deleteCourse(sectionCode, term));
this.unsavedChanges = true;
this.emit('addedCoursesChange');
}

undoAction() {
this.schedule.revertState();
this.unsavedChanges = true;
Expand Down

0 comments on commit 79836ba

Please sign in to comment.