impr: restructure src/lib

This commit is contained in:
Xylight committed 2025-09-24 17:12:19 -07:00
1 parent d85b889409
commit 75f907743e
376 files changed
+1000 -1033

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import { browser } from '$app/environment'
import type { CommunityView } from '$lib/client/types'
interface SessionStorage {
lastSeenCommunity?: CommunityView
postDraft?: {
community: CommunityView | null
title: string
body?: string
image: FileList | null
url?: string
nsfw: boolean
loading: boolean
}
}
export const setSessionStorage = (
key: keyof SessionStorage,
value: SessionStorage[typeof key],
) => {
if (!browser) return
if (value == undefined) {
sessionStorage.removeItem(key)
} else {
sessionStorage.setItem(key, JSON.stringify(value))
}
}
export const getSessionStorage = (
key: keyof SessionStorage,
): SessionStorage[typeof key] => {
if (!browser) return
return JSON.parse(sessionStorage.getItem(key)!)
}