refactor: login page

This commit is contained in:
Fredrik Burmester
2026-01-31 10:52:21 +01:00
parent 6e85c8d54a
commit 85a74a9a6a
27 changed files with 2422 additions and 1236 deletions

View File

@@ -0,0 +1,60 @@
import { atom } from "jotai";
import { storage } from "../mmkv";
const STORAGE_KEY = "selectedTVServer";
export interface SelectedTVServerState {
address: string;
name?: string;
}
/**
* Load the selected TV server from MMKV storage.
*/
function loadSelectedTVServer(): SelectedTVServerState | null {
const stored = storage.getString(STORAGE_KEY);
if (stored) {
try {
return JSON.parse(stored) as SelectedTVServerState;
} catch {
return null;
}
}
return null;
}
/**
* Save the selected TV server to MMKV storage.
*/
function saveSelectedTVServer(server: SelectedTVServerState | null): void {
if (server) {
storage.set(STORAGE_KEY, JSON.stringify(server));
} else {
storage.remove(STORAGE_KEY);
}
}
/**
* Base atom holding the selected TV server state.
*/
const baseSelectedTVServerAtom = atom<SelectedTVServerState | null>(
loadSelectedTVServer(),
);
/**
* Derived atom that persists changes to MMKV storage.
*/
export const selectedTVServerAtom = atom(
(get) => get(baseSelectedTVServerAtom),
(_get, set, newValue: SelectedTVServerState | null) => {
saveSelectedTVServer(newValue);
set(baseSelectedTVServerAtom, newValue);
},
);
/**
* Clear the selected TV server (used when changing servers).
*/
export function clearSelectedTVServer(): void {
storage.remove(STORAGE_KEY);
}

View File

@@ -0,0 +1,14 @@
import { atom } from "jotai";
import type {
SavedServer,
SavedServerAccount,
} from "@/utils/secureCredentials";
export type TVAccountActionModalState = {
server: SavedServer;
account: SavedServerAccount;
onLogin: () => void;
onDelete: () => void;
} | null;
export const tvAccountActionModalAtom = atom<TVAccountActionModalState>(null);

View File

@@ -6,9 +6,9 @@ import type {
export type TVAccountSelectModalState = {
server: SavedServer;
onAccountSelect: (account: SavedServerAccount) => void;
onAccountAction: (account: SavedServerAccount) => void;
onAddAccount: () => void;
onDeleteAccount: (account: SavedServerAccount) => void;
onDeleteServer: () => void;
} | null;
export const tvAccountSelectModalAtom = atom<TVAccountSelectModalState>(null);

View File

@@ -1,10 +0,0 @@
import { atom } from "jotai";
import type { SavedServer } from "@/utils/secureCredentials";
export type TVServerActionModalState = {
server: SavedServer;
onLogin: () => void;
onDelete: () => void;
} | null;
export const tvServerActionModalAtom = atom<TVServerActionModalState>(null);