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

Refactor semesters to plans #858

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions scripts/track-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ async function trackUsers() {
return;
}

const semesters = getFirstPlan(doc.data());
const plan = getFirstPlan(doc.data());

let oldSemesterCount = 0;
let newSemesterCount = 0;
semesters.forEach((semester: { year: number; season: string }) => {
plan.semesters.forEach((semester: { year: number; season: string }) => {
if (isOld(semester)) {
oldSemesterCount += 1;
} else {
Expand All @@ -152,7 +152,7 @@ async function trackUsers() {
activeUsersCount += 1;
}

numSemestersPerUser.push(semesters.length);
numSemestersPerUser.push(plan.semesters.length);
oldSemesters.push(oldSemesterCount);
newSemesters.push(newSemesterCount);
});
Expand Down
3 changes: 2 additions & 1 deletion src/components/Course/CourseCaution.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const getCourseCautions = (
isPlaceholderCourse(course) &&
((!store.state.orderByNewest && semesterIndex !== course.startingSemester) ||
(store.state.orderByNewest &&
store.state.semesters.length - semesterIndex + 1 !== course.startingSemester));
store.getters.getCurrentPlanSemesters.length - semesterIndex + 1 !==
course.startingSemester));
return {
noMatchedRequirement,
typicallyOfferedWarning,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/EditSemester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineComponent({
},
computed: {
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
return store.getters.getCurrentPlanSemesters;
},
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/NewSemesterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default defineComponent({
},
computed: {
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
return store.getters.getCurrentPlanSemesters;
},
},
methods: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Modals/Onboarding/Onboarding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import {
import timeline1Text from '@/assets/images/timeline1text.svg';
import timeline2Text from '@/assets/images/timeline2text.svg';
import timeline3Text from '@/assets/images/timeline3text.svg';
import store from '@/store';

const timelineTexts = [timeline1Text, timeline2Text, timeline3Text];

Expand Down Expand Up @@ -251,7 +252,7 @@ export default defineComponent({
this.clearTransferCreditIfGraduate();
setAppOnboardingData(this.name, revised);
// indicates first time user onboarding
if (!this.isEditingProfile) populateSemesters(revised);
if (!this.isEditingProfile) populateSemesters(store.state.currentPlan, revised);
this.$emit('onboard');
},
goBack() {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Requirements/CompletedSubReqCourse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default defineComponent({
}),
computed: {
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
return store.getters.getCurrentPlanSemesters;
},
isTransferCredit(): boolean {
const { uniqueId } = this.courseTaken;
Expand Down Expand Up @@ -111,7 +111,8 @@ export default defineComponent({
deleteTransferCredit(this.courseTaken.code);
} else {
const { uniqueId } = this.courseTaken;
if (typeof uniqueId === 'number') deleteCourseFromSemesters(uniqueId, this.$gtag);
if (typeof uniqueId === 'number')
deleteCourseFromSemesters(store.state.currentPlan, uniqueId, this.$gtag);
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/components/Requirements/IncompleteSelfCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export default defineComponent({
// and courses that do not fulfill the requirement checker
selfCheckCourses(): Record<string, FirestoreSemesterCourse> {
const courses: Record<string, FirestoreSemesterCourse> = {};
store.state.semesters
(
store.state.plans.find(p => p === store.state.currentPlan)?.semesters ??
store.state.plans[0].semesters
)
.flatMap(it => it.courses)
.forEach(course => {
if (
Expand Down Expand Up @@ -165,6 +168,7 @@ export default defineComponent({
this.showDropdown = false;
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(course);
addCourseToSemester(
store.state.currentPlan,
year,
season,
newCourse,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Requirements/RequirementSideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default defineComponent({
return featureFlagCheckers.isRequirementDebuggerEnabled();
},
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
return store.getters.getCurrentPlanSemesters;
},
onboardingData(): AppOnboardingData {
return store.state.onboardingData;
Expand Down
42 changes: 36 additions & 6 deletions src/components/Semester/Semester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export default defineComponent({
set(newCourses: readonly AppFirestoreSemesterCourseWithRequirementID[]) {
const courses = newCourses.map(({ requirementID: _, ...rest }) => rest);
editSemester(
store.state.currentPlan,
this.year,
this.season,
(semester: FirestoreSemester): FirestoreSemester => ({
Expand Down Expand Up @@ -411,7 +412,14 @@ export default defineComponent({
addCourse(data: CornellCourseRosterCourse, choice: FirestoreCourseOptInOptOutChoices) {
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(data);
// Since the course is new, we know the old choice does not exist.
addCourseToSemester(this.year, this.season, newCourse, () => choice, this.$gtag);
addCourseToSemester(
store.state.currentPlan,
this.year,
this.season,
newCourse,
() => choice,
this.$gtag
);

const courseCode = `${data.subject} ${data.catalogNbr}`;
this.openConfirmationModal(`Added ${courseCode} to ${this.season} ${this.year}`);
Expand All @@ -429,7 +437,14 @@ export default defineComponent({
};

// add the course to the semeser (with no choice made)
addCourseToSemester(this.year, this.season, newCourse, () => choice, this.$gtag);
addCourseToSemester(
store.state.currentPlan,
this.year,
this.season,
newCourse,
() => choice,
this.$gtag
);
this.closeCourseModal();

const conflicts = store.state.courseToRequirementsInConstraintViolations.get(
Expand All @@ -455,15 +470,28 @@ export default defineComponent({
this.openConfirmationModal(`Added ${course.code} to ${this.season} ${this.year}`);
},
deleteCourseWithoutModal(uniqueID: number) {
deleteCourseFromSemester(this.year, this.season, uniqueID, this.$gtag);
deleteCourseFromSemester(
store.state.currentPlan,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass the current plan as an argument?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there's no case where you aren't deleting from the current plan currently but it was just the way I wrote the firestore functions to modify the plan that is passed in.

this.year,
this.season,
uniqueID,
this.$gtag
);
},
deleteCourse(courseCode: string, uniqueID: number) {
deleteCourseFromSemester(this.year, this.season, uniqueID, this.$gtag);
deleteCourseFromSemester(
store.state.currentPlan,
this.year,
this.season,
uniqueID,
this.$gtag
);
// Update requirements menu
this.openConfirmationModal(`Removed ${courseCode} from ${this.season} ${this.year}`);
},
colorCourse(color: string, uniqueID: number, courseCode: string) {
editSemester(
store.state.currentPlan,
this.year,
this.season,
(semester: FirestoreSemester): FirestoreSemester => ({
Expand All @@ -485,7 +513,7 @@ export default defineComponent({
: course
),
});
editSemesters(oldSemesters => oldSemesters.map(sem => updater(sem)));
editSemesters(store.state.currentPlan, oldSemesters => oldSemesters.map(sem => updater(sem)));
updateSubjectColorData(color, subject);
this.openConfirmationModal(`Changed color for ${subject}`);
},
Expand All @@ -494,6 +522,7 @@ export default defineComponent({
},
editCourseCredit(credit: number, uniqueID: number) {
editSemester(
store.state.currentPlan,
this.year,
this.season,
(semester: FirestoreSemester): FirestoreSemester => ({
Expand Down Expand Up @@ -543,6 +572,7 @@ export default defineComponent({
},
editSemester(seasonInput: string, yearInput: number) {
editSemester(
store.state.currentPlan,
this.year,
this.season,
(oldSemester: FirestoreSemester): FirestoreSemester => ({
Expand All @@ -559,7 +589,7 @@ export default defineComponent({
this.isClearSemesterOpen = false;
},
clearSemester() {
deleteAllCoursesFromSemester(this.year, this.season, this.$gtag);
deleteAllCoursesFromSemester(store.state.currentPlan, this.year, this.season, this.$gtag);
this.openConfirmationModal(`Cleared ${this.season} ${this.year} in plan`);
},
walkthroughText() {
Expand Down
9 changes: 6 additions & 3 deletions src/components/Semester/SemesterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export default defineComponent({
},
computed: {
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
if (store.state.plans.length === 0) {
return [];
}
return store.getters.getCurrentPlanSemesters;
},
noSemesters(): boolean {
return this.semesters.length === 0;
Expand Down Expand Up @@ -145,11 +148,11 @@ export default defineComponent({
this.isSemesterModalOpen = false;
},
addSemester(season: string, year: number) {
addSemester(year, season as FirestoreSemesterSeason, this.$gtag);
addSemester(store.state.currentPlan, year, season as FirestoreSemesterSeason, this.$gtag);
this.openSemesterConfirmationModal(season as FirestoreSemesterSeason, year, true);
},
deleteSemester(season: string, year: number) {
deleteSemester(year, season as FirestoreSemesterSeason, this.$gtag);
deleteSemester(store.state.currentPlan, year, season as FirestoreSemesterSeason, this.$gtag);
this.openSemesterConfirmationModal(season as FirestoreSemesterSeason, year, false);
},
courseOnClick(course: FirestoreSemesterCourse) {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default defineComponent({
return store.state.onboardingData;
},
semesters(): readonly FirestoreSemester[] {
return store.state.semesters;
return store.getters.getCurrentPlanSemesters;
},
hasBottomCourses(): boolean {
return immutableBottomBarState.bottomCourses.length > 0;
Expand Down
Loading
Loading