-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove extra `SavedContext` and corresponde `useSaved` hook. - Create `useSavedOrgs` hook to directly use `UserContext` to handle global state. - Add auto-fetch `organizationProfiles` into `UserContext` every time session refresh and listen to firebase updates. - Directly saved to `Session storage` which will save quotas and ensure speed.
- Loading branch information
Showing
14 changed files
with
138 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as useUser } from './useUser'; | ||
export { default as useSaved } from './useSaved'; | ||
export { default as useEvents } from './useEvents'; | ||
export { default as useSavedOrgs } from './useSavedOrgs'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import useUser from './useUser'; | ||
|
||
const useSavedOrgs = () => { | ||
const { user, updateProfile } = useUser(); | ||
|
||
if (!user || user.role !== 'donor') { | ||
return { | ||
savedOrgs: [], | ||
updateSavedOrgs: async () => { | ||
console.warn('This user is not a donor.'); | ||
}, | ||
}; | ||
} | ||
|
||
const donorProfile = user as DonorProfile; | ||
const savedOrgs = donorProfile.saved || []; | ||
|
||
const updateSavedOrgs = async (org: OrganizationProfile): Promise<void> => { | ||
const isAlreadySaved = savedOrgs.some( | ||
(organization: OrganizationProfile) => organization.uid === org.uid | ||
); | ||
|
||
// If exists, remove; else add | ||
const updatedSaved = isAlreadySaved | ||
? savedOrgs.filter( | ||
(organization: OrganizationProfile) => organization.uid !== org.uid | ||
) | ||
: [...savedOrgs, org]; | ||
|
||
try { | ||
await updateProfile({ saved: updatedSaved }); | ||
} catch (error) { | ||
console.error('Error toggling saved organization:', error); | ||
alert('Failed to update saved organizations. Please try again.'); | ||
} | ||
}; | ||
|
||
return { savedOrgs, updateSavedOrgs }; | ||
}; | ||
|
||
export default useSavedOrgs; |
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
Oops, something went wrong.