-
Notifications
You must be signed in to change notification settings - Fork 11
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
[Saved Courses] add collection into firesbase #921
Conversation
[diff-counting] Significant lines: 147. |
Visit the preview URL for this PR (updated for commit 1d44852): https://cornelldti-courseplan-dev--pr921-hannah-add-firestore-hmirtull.web.app (expires Fri, 31 May 2024 22:02:33 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 6d4e0437c4559ed895272bbd63991394f1e0e933 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Hannah! And I appreciate that this is still a quasi-draft PR (make sure that you open things appropriately in the future when not fully ready for review), so makes sense that there are some of the console.log
s and TODO
s. Just please ensure that these are all removed when all the other commits are finished, for the reasons I outlined.
In general, looks fantastic and you did a really good job with TypeScript too. Good to have a chance to start working with Vuex, that's very critical to the web app. In terms of future work, would just encourage you to do some minor refactoring (maybe not now, but at least before the merge request proper) and test that the Firebase writing works. Whenever you need any help finishing stuff up feel free to message or find me.
Also, if it would be possible to update the description for this PR that would be great, I think you may have left some parts of the initial boilerplate intact.
export const editCollections = async ( | ||
updater: (oldCollections: readonly Collection[]) => readonly Collection[] | ||
): Promise<void> => { | ||
console.log('edit Collections'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't need this for further debugging, would be great to remove — don't want to unnecessarily clutter the console.
console.log('edit Collections'); | ||
const collections = updater(store.state.collections); | ||
store.commit('setCollections', collections); | ||
await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If / when you are testing this on Firebase, you might get a warning about insufficient permissions
. Nidhi and I just went through this last week. So a heads up if that does pop up: you need to update the 'rules' for that collection in the Firebase. Happy to help if you're experiencing trouble with that and not 100% sure what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ok for now -- the semestersCollection already allows for read and write
@@ -56,6 +77,17 @@ export const editPlan = (name: string, updater: (oldPlan: Plan) => Plan): void = | |||
editPlans(oldPlan => oldPlan.map(plan => (plan.name === name ? updater(plan) : plan))); | |||
}; | |||
|
|||
const createCollection = ( | |||
name: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to abstract this into a local type? Improves a bit on maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok for codebase consistency -- we initialize most of our objects (semester, plan, etc) like that
courses: readonly FirestoreSemesterCourse[] | ||
): { | ||
name: string; | ||
courses: readonly FirestoreSemesterCourse[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of some advanced TS features, I don't think I've ever used readonly
or even properly understand it 😁
@@ -88,6 +120,15 @@ export const semesterEquals = ( | |||
season: FirestoreSemesterSeason | |||
): boolean => semester.year === year && semester.season === season; | |||
|
|||
export const addCollection = async ( | |||
name: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above — could abstract this (the first two parameters) and then connect to the optional parameter using the ampersand operator.
gtag?: VueGtag | ||
): void => { | ||
// TODO: 1) add course to collection 2) delete course from semester | ||
// 3) cannot add course to collection if it is already in the collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine there will be a bit of a lull in development of other features at the beginning of next semester. See that you have a lot of TODOs; if you need any help am always available.
|
||
type Collection = { | ||
readonly name: string; | ||
// TODO: add potential more fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned earlier about using a local collection type — is this it? Maybe could use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, it's really coming along Hannah!! I know some of the stuff Simon mentioned are present in the existing codebase so it's ok to leave to later to address. Thanks for working on this!
console.log('edit Collections'); | ||
const collections = updater(store.state.collections); | ||
store.commit('setCollections', collections); | ||
await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ok for now -- the semestersCollection already allows for read and write
await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), { | ||
collections, | ||
}); | ||
store.commit('setOrderByNewest', store.state.orderByNewest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary here since editing collections should not change the ordering of the semesters
@@ -56,6 +77,17 @@ export const editPlan = (name: string, updater: (oldPlan: Plan) => Plan): void = | |||
editPlans(oldPlan => oldPlan.map(plan => (plan.name === name ? updater(plan) : plan))); | |||
}; | |||
|
|||
const createCollection = ( | |||
name: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok for codebase consistency -- we initialize most of our objects (semester, plan, etc) like that
Summary
This pull request is the first step towards adding collection into Firebase for implementing the Save Courses Feature.
- [ ] only for save course modal [Saved Courses] add save modal #912
Remaining TODOs
Depends on #{number of PR}
need to make sure it works with #912
Test Plan
Notes
Blockers
Breaking Changes
collections
, need to update alot of code withsemesters