mirror of
https://github.com/modrinth/code.git
synced 2026-08-30 11:36:05 +00:00
* add account switcher, migrate context menus to overflow menu system, update version filter controls, only pad instance icons * app account switcher, improve some context menus, theme stuff * prepr * handle reauthentication * fix a couple sign in issues, admin page cleanup, fix org status badges, fix official account badge, open in local keybind, publish plus icons * rename generic menus to ButtonMenu (& types) * fix hydration issue w/ dropdowns + middleware error
30 lines
694 B
TypeScript
30 lines
694 B
TypeScript
const STORAGE_KEY = 'modrinth-account-appearances'
|
|
|
|
function readCache(): Record<string, { auto: boolean; theme: string }> {
|
|
try {
|
|
const parsed = JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '')
|
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
|
|
return parsed
|
|
} catch {
|
|
return {}
|
|
}
|
|
}
|
|
|
|
export function rememberAccountAppearance(
|
|
userId: string,
|
|
appearance: { auto: boolean; theme: string },
|
|
) {
|
|
try {
|
|
window.localStorage.setItem(
|
|
STORAGE_KEY,
|
|
JSON.stringify({ ...readCache(), [userId]: appearance }),
|
|
)
|
|
} catch {
|
|
// storage blocked or full
|
|
}
|
|
}
|
|
|
|
export function getAccountAppearance(userId: string) {
|
|
return readCache()[userId]
|
|
}
|