@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 31 lines 1.17 KB
Raw
1 import { UsageProviderKind } from "@t3tools/contracts";
2 import * as Schema from "effect/Schema";
3
4 import { getLocalStorageItem, setLocalStorageItem } from "../../hooks/useLocalStorage";
5
6 const STORAGE_KEY = "t3code:usage-page-preferences:v1";
7 const UsagePagePreferencesSchema = Schema.Struct({
8 metric: Schema.Literals(["cost", "tokens", "limits"]),
9 windowDays: Schema.Literals([1, 7, 30, 90]),
10 hiddenProviders: Schema.optional(Schema.Array(UsageProviderKind)),
11 });
12 export type UsagePagePreferences = typeof UsagePagePreferencesSchema.Type;
13
14 const DEFAULT_PREFERENCES: UsagePagePreferences = { metric: "limits", windowDays: 30 };
15
16 export function readUsagePagePreferences(): UsagePagePreferences {
17 try {
18 return getLocalStorageItem(STORAGE_KEY, UsagePagePreferencesSchema) ?? DEFAULT_PREFERENCES;
19 } catch (error) {
20 console.error("Could not read Usage page preferences.", error);
21 return DEFAULT_PREFERENCES;
22 }
23 }
24
25 export function saveUsagePagePreferences(preferences: UsagePagePreferences): void {
26 try {
27 setLocalStorageItem(STORAGE_KEY, preferences, UsagePagePreferencesSchema);
28 } catch (error) {
29 console.error("Could not save Usage page preferences.", error);
30 }
31 }