Files
photon-tbw/src/lib/session.ts
T
Xylight 5651ad475d feat: use state based auth instead of store based (#488)
* misc: switch to state for auth

* fix: class based auth not working
2025-02-08 13:49:09 -08:00

37 lines
841 B
TypeScript

import { browser } from '$app/environment'
import type { Community } from 'lemmy-js-client'
interface SessionStorage {
lastSeenCommunity: Community | undefined
postDraft:
| {
community: Community | null
title: string
body: string
image: FileList | null
url: string | undefined
nsfw: boolean
loading: boolean
}
| undefined
}
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)!)
}