Refactor useSettings hook, parse with zod schema
This commit is contained in:
@ -2,6 +2,8 @@ import { z } from 'zod';
|
||||
|
||||
import { locales } from 'soapbox/messages';
|
||||
|
||||
import { coerceObject } from '../utils';
|
||||
|
||||
const skinToneSchema = z.union([
|
||||
z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6),
|
||||
]);
|
||||
@ -14,6 +16,7 @@ const settingsSchema = z.object({
|
||||
autoPlayGif: z.boolean().catch(true),
|
||||
displayMedia: z.enum(['default', 'hide_all', 'show_all']).catch('default'),
|
||||
expandSpoilers: z.boolean().catch(false),
|
||||
preserveSpoilers: z.boolean().catch(false),
|
||||
unfollowModal: z.boolean().catch(false),
|
||||
boostModal: z.boolean().catch(false),
|
||||
deleteModal: z.boolean().catch(true),
|
||||
@ -29,6 +32,47 @@ const settingsSchema = z.object({
|
||||
systemFont: z.boolean().catch(false),
|
||||
demetricator: z.boolean().catch(false),
|
||||
isDeveloper: z.boolean().catch(false),
|
||||
demo: z.boolean().catch(false),
|
||||
chats: coerceObject({
|
||||
mainWindow: z.enum(['minimized', 'open']).catch('minimized'),
|
||||
sound: z.boolean().catch(true),
|
||||
}),
|
||||
home: coerceObject({
|
||||
shows: coerceObject({
|
||||
reblog: z.boolean().catch(true),
|
||||
reply: z.boolean().catch(true),
|
||||
}),
|
||||
}),
|
||||
account_timeline: coerceObject({
|
||||
shows: coerceObject({
|
||||
pinned: z.boolean().catch(true),
|
||||
}),
|
||||
}),
|
||||
remote_timeline: coerceObject({
|
||||
pinnedHosts: z.string().array().catch([]),
|
||||
}),
|
||||
public: coerceObject({
|
||||
other: coerceObject({
|
||||
onlyMedia: z.boolean().catch(false),
|
||||
}),
|
||||
}),
|
||||
community: coerceObject({
|
||||
other: coerceObject({
|
||||
onlyMedia: z.boolean().catch(false),
|
||||
}),
|
||||
}),
|
||||
remote: coerceObject({
|
||||
other: coerceObject({
|
||||
onlyMedia: z.boolean().catch(false),
|
||||
}),
|
||||
}),
|
||||
notifications: coerceObject({
|
||||
quickFilter: coerceObject({
|
||||
active: z.string().catch('all'),
|
||||
advanced: z.boolean().catch(false),
|
||||
show: z.boolean().catch(true),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
type Settings = z.infer<typeof settingsSchema>;
|
||||
|
||||
Reference in New Issue
Block a user