impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -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)!)
|
||||
}
|
||||
Reference in new issue
Block a user