cents/apps/web/src/data/ledgers.ts

73 lines
2.3 KiB
TypeScript

import { ledgerThemeAccents, type CurrencyCode, type LedgerThemeId } from "@cents/domain";
export const ledgerThemes: ReadonlyArray<{
id: LedgerThemeId;
name: string;
accent: string;
gradient: string;
}> = [
{ id: "jade", name: "翡翠", accent: ledgerThemeAccents.jade, gradient: "linear-gradient(135deg, #118b79 0%, #087f72 48%, #285765 100%)" },
{ id: "ocean", name: "海湾", accent: ledgerThemeAccents.ocean, gradient: "linear-gradient(135deg, #167b93 0%, #3459a4 52%, #4b3f7f 100%)" },
{ id: "coral", name: "晚霞", accent: ledgerThemeAccents.coral, gradient: "linear-gradient(135deg, #c94f45 0%, #ad4869 54%, #6e4d82 100%)" },
{ id: "berry", name: "莓果", accent: ledgerThemeAccents.berry, gradient: "linear-gradient(135deg, #a84378 0%, #71468d 52%, #40578a 100%)" },
{ id: "meadow", name: "森野", accent: ledgerThemeAccents.meadow, gradient: "linear-gradient(135deg, #25805f 0%, #4e794b 54%, #766b35 100%)" },
{ id: "graphite", name: "暮色", accent: ledgerThemeAccents.graphite, gradient: "linear-gradient(135deg, #35585d 0%, #4e556e 52%, #303f55 100%)" },
];
export function ledgerTheme(themeId?: string) {
return ledgerThemes.find((theme) => theme.id === themeId) ?? ledgerThemes[0];
}
export type LedgerRecord = {
id: string;
name: string;
color: string;
theme: LedgerThemeId;
defaultCurrency: CurrencyCode;
createdAt: string;
updatedAt: string;
archivedAt: string | null;
role?: "owner" | "member";
isPersonal: boolean;
};
export type UserPreference = {
id: string;
userId: string;
key: "currentLedgerId";
value: string;
updatedAt: string;
};
export function currentLedgerPreferenceId(userId: string) {
return `${userId}:currentLedgerId`;
}
export function createDefaultLedgers(): LedgerRecord[] {
const now = new Date().toISOString();
return [
{
id: "local-ledger",
name: "家庭日常",
color: "#087f72",
theme: "jade",
defaultCurrency: "CNY",
createdAt: now,
updatedAt: now,
archivedAt: null,
isPersonal: true,
},
{
id: "travel-ledger",
name: "旅行账本",
color: "#3478e5",
theme: "ocean",
defaultCurrency: "CNY",
createdAt: now,
updatedAt: now,
archivedAt: null,
isPersonal: false,
},
];
}