-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requirement builder with the new data format
- Loading branch information
1 parent
3429c9c
commit 7265ffa
Showing
15 changed files
with
253 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { overriddenFulfillmentChoicesCollection } from '../firebase-frontend-config'; | ||
import store from '../store'; | ||
|
||
export const updateRequirementChoice = ( | ||
courseUniqueID: string | number, | ||
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices | ||
): void => { | ||
overriddenFulfillmentChoicesCollection.doc(store.state.currentFirebaseUser.email).set({ | ||
...store.state.overriddenFulfillmentChoices, | ||
[courseUniqueID]: choiceUpdater( | ||
store.state.overriddenFulfillmentChoices[courseUniqueID] || { | ||
arbitraryOptIn: {}, | ||
acknowledgedCheckerWarningOptIn: [], | ||
optOut: [], | ||
} | ||
), | ||
}); | ||
}; | ||
|
||
export const updateRequirementChoices = ( | ||
updater: ( | ||
oldChoices: FirestoreOverriddenFulfillmentChoices | ||
) => FirestoreOverriddenFulfillmentChoices | ||
): void => { | ||
overriddenFulfillmentChoicesCollection | ||
.doc(store.state.currentFirebaseUser.email) | ||
.set(updater(store.state.overriddenFulfillmentChoices)); | ||
}; | ||
|
||
export const deleteCourseFromRequirementChoices = (courseUniqueID: string | number): void => | ||
deleteCoursesFromRequirementChoices([courseUniqueID]); | ||
|
||
export const deleteCoursesFromRequirementChoices = ( | ||
courseUniqueIds: readonly (string | number)[] | ||
): void => { | ||
const courseUniqueIdStrings = new Set(courseUniqueIds.map(uniqueId => uniqueId.toString())); | ||
overriddenFulfillmentChoicesCollection | ||
.doc(store.state.currentFirebaseUser.email) | ||
.set( | ||
Object.fromEntries( | ||
Object.entries(store.state.overriddenFulfillmentChoices).filter( | ||
([k]) => !courseUniqueIdStrings.has(k) | ||
) | ||
) | ||
); | ||
}; |
80 changes: 0 additions & 80 deletions
80
src/global-firestore-data/selectable-requirement-choices.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.