fix(settings): name descending size sort explicitly
The library sort setting used `size` for largest-first sorting while the ascending option used `sizeAsc`. That made the pair asymmetric and left the current settings model carrying a legacy-looking key. Rename the current descending key to `sizeDesc` in the type, menu, and sort logic. Stored `size` values are normalized to `sizeDesc` on read, so existing users keep the same largest-first behavior while new writes use the explicit key. Test Plan: - deno task build - RUSTC_WRAPPER= CARGO_BUILD_RUSTC_WRAPPER= just build - git diff --check Refs: local review feedback
This commit is contained in:
@@ -17,6 +17,9 @@ export interface UISettings {
|
||||
filter: GameFilter;
|
||||
}
|
||||
|
||||
type StoredGameSort = GameSort | 'size';
|
||||
type StoredUISettings = Partial<Omit<UISettings, 'sort'> & { sort: StoredGameSort }>;
|
||||
|
||||
export const ACCENT_OPTIONS = [
|
||||
{ value: '#3b82f6', label: 'Blue' },
|
||||
{ value: '#22d3ee', label: 'Cyan' },
|
||||
@@ -53,15 +56,19 @@ export const DEFAULT_SETTINGS: UISettings = {
|
||||
filter: 'local',
|
||||
};
|
||||
|
||||
const sanitize = (raw: Partial<UISettings> | undefined): UISettings => ({
|
||||
const sanitize = (raw: StoredUISettings | undefined): UISettings => ({
|
||||
accent: raw?.accent ?? DEFAULT_SETTINGS.accent,
|
||||
bg: raw?.bg ?? DEFAULT_SETTINGS.bg,
|
||||
density: raw?.density ?? DEFAULT_SETTINGS.density,
|
||||
aspect: raw?.aspect ?? DEFAULT_SETTINGS.aspect,
|
||||
sort: raw?.sort ?? DEFAULT_SETTINGS.sort,
|
||||
sort: sanitizeSort(raw?.sort),
|
||||
filter: raw?.filter ?? DEFAULT_SETTINGS.filter,
|
||||
});
|
||||
|
||||
const sanitizeSort = (sort: StoredGameSort | undefined): GameSort => (
|
||||
sort === 'size' ? 'sizeDesc' : sort ?? DEFAULT_SETTINGS.sort
|
||||
);
|
||||
|
||||
export interface UseSettings {
|
||||
settings: UISettings;
|
||||
set: <K extends keyof UISettings>(key: K, value: UISettings[K]) => void;
|
||||
@@ -82,7 +89,7 @@ export const useSettings = (): UseSettings => {
|
||||
const init = async () => {
|
||||
try {
|
||||
const store = await load(SETTINGS_FILE, SETTINGS_FILE_OPTIONS);
|
||||
const saved = await store.get<Partial<UISettings>>(UI_SETTINGS_KEY);
|
||||
const saved = await store.get<StoredUISettings>(UI_SETTINGS_KEY);
|
||||
if (!cancelled) {
|
||||
setSettings(sanitize(saved ?? undefined));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user