diff options
| author | Brandon Eng <bce25@cornell.edu> | 2024-01-16 22:41:46 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-16 10:41:46 -0500 |
| commit | 36cc4f1ef745a027540050ad668db3bcdc08d4b2 (patch) | |
| tree | 73d45c30b1e17e92b676701ba9ee3f6fb1071870 /src/app/groups/recent-groups-helpers.ts | |
| parent | 1141501edb6611b7ac147b6ceefb963ba1f83606 (diff) | |
Ability to archive groups when they’re settled up (#45)
* Settled up icon on group card
* remove logs
* archived groups
* remove settled up
* remove more settled up
* recent-group-list-card
* sortGroups
* archiveGroup
* unarchiveGroup
* clean up
* more clean up
* Prettier, fix TS errors, add titles
---------
Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
Diffstat (limited to 'src/app/groups/recent-groups-helpers.ts')
| -rw-r--r-- | src/app/groups/recent-groups-helpers.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/app/groups/recent-groups-helpers.ts b/src/app/groups/recent-groups-helpers.ts index 72c5d28..0d718e2 100644 --- a/src/app/groups/recent-groups-helpers.ts +++ b/src/app/groups/recent-groups-helpers.ts @@ -8,12 +8,14 @@ export const recentGroupsSchema = z.array( ) export const starredGroupsSchema = z.array(z.string()) +export const archivedGroupsSchema = z.array(z.string()) export type RecentGroups = z.infer<typeof recentGroupsSchema> export type RecentGroup = RecentGroups[number] const STORAGE_KEY = 'recentGroups' const STARRED_GROUPS_STORAGE_KEY = 'starredGroups' +const ARCHIVED_GROUPS_STORAGE_KEY = 'archivedGroups' export function getRecentGroups() { const groupsInStorageJson = localStorage.getItem(STORAGE_KEY) @@ -64,3 +66,28 @@ export function unstarGroup(groupId: string) { JSON.stringify(starredGroups.filter((g) => g !== groupId)), ) } + +export function getArchivedGroups() { + const archivedGroupsJson = localStorage.getItem(ARCHIVED_GROUPS_STORAGE_KEY) + const archivedGroupsRaw = archivedGroupsJson + ? JSON.parse(archivedGroupsJson) + : [] + const parseResult = archivedGroupsSchema.safeParse(archivedGroupsRaw) + return parseResult.success ? parseResult.data : [] +} + +export function archiveGroup(groupId: string) { + const archivedGroups = getArchivedGroups() + localStorage.setItem( + ARCHIVED_GROUPS_STORAGE_KEY, + JSON.stringify([...archivedGroups, groupId]), + ) +} + +export function unarchiveGroup(groupId: string) { + const archivedGroups = getArchivedGroups() + localStorage.setItem( + ARCHIVED_GROUPS_STORAGE_KEY, + JSON.stringify(archivedGroups.filter((g) => g !== groupId)), + ) +} |
