aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/recent-groups-helpers.ts
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2024-01-08 15:49:07 -0500
committerSebastien Castiel <sebastien@castiel.me>2024-01-08 15:49:07 -0500
commit55883ce414f5358a75780fbffb755f5464e211d4 (patch)
treedadfe2abf1029194e7c5703542b64f9b3d1e4dbd /src/app/groups/recent-groups-helpers.ts
parentbec1dd270a1d3184ea13f0b849f192176354fc00 (diff)
Mark a group as favorite (fixes #29)
Diffstat (limited to 'src/app/groups/recent-groups-helpers.ts')
-rw-r--r--src/app/groups/recent-groups-helpers.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/app/groups/recent-groups-helpers.ts b/src/app/groups/recent-groups-helpers.ts
index 5d52141..5ccb5ae 100644
--- a/src/app/groups/recent-groups-helpers.ts
+++ b/src/app/groups/recent-groups-helpers.ts
@@ -7,10 +7,13 @@ export const recentGroupsSchema = z.array(
}),
)
+export const starredGroupsSchema = 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'
export function getRecentGroups() {
const groupsInStorageJson = localStorage.getItem(STORAGE_KEY)
@@ -28,3 +31,28 @@ export function saveRecentGroup(group: RecentGroup) {
JSON.stringify([group, ...recentGroups.filter((rg) => rg.id !== group.id)]),
)
}
+
+export function getStarredGroups() {
+ const starredGroupsJson = localStorage.getItem(STARRED_GROUPS_STORAGE_KEY)
+ const starredGroupsRaw = starredGroupsJson
+ ? JSON.parse(starredGroupsJson)
+ : []
+ const parseResult = starredGroupsSchema.safeParse(starredGroupsRaw)
+ return parseResult.success ? parseResult.data : []
+}
+
+export function starGroup(groupId: string) {
+ const starredGroups = getStarredGroups()
+ localStorage.setItem(
+ STARRED_GROUPS_STORAGE_KEY,
+ JSON.stringify([...starredGroups, groupId]),
+ )
+}
+
+export function unstarGroup(groupId: string) {
+ const starredGroups = getStarredGroups()
+ localStorage.setItem(
+ STARRED_GROUPS_STORAGE_KEY,
+ JSON.stringify(starredGroups.filter((g) => g !== groupId)),
+ )
+}