diff --git a/packages/pl-fe/src/actions/settings.ts b/packages/pl-fe/src/actions/settings.ts index 0b5726f73..9d2fbf957 100644 --- a/packages/pl-fe/src/actions/settings.ts +++ b/packages/pl-fe/src/actions/settings.ts @@ -23,115 +23,10 @@ type SettingOpts = { const saveSuccessMessage = defineMessage({ id: 'settings.save.success', defaultMessage: 'Your preferences have been saved!' }); -// const defaultSettings = ImmutableMap({ -// onboarded: false, -// skinTone: 1, -// reduceMotion: false, -// underlineLinks: false, -// autoPlayGif: true, -// displayMedia: 'default', -// displaySpoilers: false, -// unfollowModal: true, -// boostModal: false, -// deleteModal: true, -// missingDescriptionModal: true, -// defaultPrivacy: 'public', -// defaultContentType: 'text/plain', -// themeMode: 'system', -// locale: navigator.language || 'en', -// showExplanationBox: true, -// explanationBox: true, -// autoloadTimelines: true, -// autoloadMore: false, -// preserveSpoilers: true, -// autoTranslate: false, -// knownLanguages: ImmutableOrderedSet(), - -// systemFont: false, -// demetricator: false, - -// isDeveloper: false, - -// chats: ImmutableMap({ -// panes: ImmutableList(), -// mainWindow: 'minimized', -// sound: true, -// }), - -// home: ImmutableMap({ -// shows: ImmutableMap({ -// reblog: true, -// reply: true, -// direct: false, -// }), -// }), - -// notifications: ImmutableMap({ -// quickFilter: ImmutableMap({ -// active: 'all', -// show: true, -// advanced: false, -// }), - -// sounds: ImmutableMap({ -// follow: false, -// follow_request: false, -// favourite: false, -// reblog: false, -// mention: false, -// poll: false, -// move: false, -// emoji_reaction: false, -// }), -// }), - -// 'public:local': ImmutableMap({ -// shows: ImmutableMap({ -// reblog: false, -// reply: true, -// direct: false, -// }), -// other: ImmutableMap({ -// onlyMedia: false, -// }), -// }), - -// public: ImmutableMap({ -// shows: ImmutableMap({ -// reblog: true, -// reply: true, -// direct: false, -// }), -// other: ImmutableMap({ -// onlyMedia: false, -// }), -// }), - -// direct: ImmutableMap({ -// }), - -// account_timeline: ImmutableMap({ -// shows: ImmutableMap({ -// reblog: true, -// pinned: true, -// direct: false, -// }), -// }), - -// trends: ImmutableMap({ -// show: true, -// }), - -// remote_timeline: ImmutableMap({ -// pinnedHosts: ImmutableList(), -// }), -// }); - -const changeSetting = (path: string[], value: any, opts?: SettingOpts) => - (dispatch: AppDispatch) => { - useSettingsStore.getState().changeSetting(path, value); - return dispatch(saveSettings(opts)); - }; +const changeSetting = (path: string[], value: any, opts?: SettingOpts) => { + useSettingsStore.getState().changeSetting(path, value); + return saveSettings(opts); +}; const saveSettings = (opts?: SettingOpts) => (dispatch: AppDispatch, getState: () => RootState) => { diff --git a/packages/pl-fe/src/features/bubble-timeline/index.tsx b/packages/pl-fe/src/features/bubble-timeline/index.tsx index f12b1f3a1..40743a433 100644 --- a/packages/pl-fe/src/features/bubble-timeline/index.tsx +++ b/packages/pl-fe/src/features/bubble-timeline/index.tsx @@ -19,7 +19,7 @@ const BubbleTimeline = () => { const theme = useTheme(); const settings = useSettings(); - const onlyMedia = settings.bubble.other.onlyMedia; + const onlyMedia = settings.timelines.bubble?.other.onlyMedia ?? false; const timelineId = 'bubble'; const isMobile = useIsMobile(); diff --git a/packages/pl-fe/src/features/community-timeline/index.tsx b/packages/pl-fe/src/features/community-timeline/index.tsx index f45f35b87..7f9d3a482 100644 --- a/packages/pl-fe/src/features/community-timeline/index.tsx +++ b/packages/pl-fe/src/features/community-timeline/index.tsx @@ -20,7 +20,7 @@ const CommunityTimeline = () => { const theme = useTheme(); const settings = useSettings(); - const onlyMedia = settings['public:local'].other.onlyMedia; + const onlyMedia = settings.timelines['public:local']?.other.onlyMedia ?? false; const timelineId = 'public:local'; const isMobile = useIsMobile(); diff --git a/packages/pl-fe/src/features/public-timeline/index.tsx b/packages/pl-fe/src/features/public-timeline/index.tsx index d717b594b..37a2a8e13 100644 --- a/packages/pl-fe/src/features/public-timeline/index.tsx +++ b/packages/pl-fe/src/features/public-timeline/index.tsx @@ -25,7 +25,7 @@ const CommunityTimeline = () => { const instance = useInstance(); const settings = useSettings(); - const onlyMedia = settings.public.other.onlyMedia; + const onlyMedia = settings.timelines.public?.other.onlyMedia ?? false; const timelineId = 'public'; const isMobile = useIsMobile(); diff --git a/packages/pl-fe/src/features/remote-timeline/index.tsx b/packages/pl-fe/src/features/remote-timeline/index.tsx index 7f12d23e7..d23f1ff3d 100644 --- a/packages/pl-fe/src/features/remote-timeline/index.tsx +++ b/packages/pl-fe/src/features/remote-timeline/index.tsx @@ -29,7 +29,7 @@ const RemoteTimeline: React.FC = ({ params }) => { const settings = useSettings(); const timelineId = 'remote'; - const onlyMedia = settings.remote.other.onlyMedia; + const onlyMedia = settings.timelines.remote?.other.onlyMedia ?? false; const pinned = settings.remote_timeline.pinnedHosts.includes(instance); const isMobile = useIsMobile(); diff --git a/packages/pl-fe/src/schemas/pl-fe/settings.ts b/packages/pl-fe/src/schemas/pl-fe/settings.ts index a57c1679f..6d2ecd9e5 100644 --- a/packages/pl-fe/src/schemas/pl-fe/settings.ts +++ b/packages/pl-fe/src/schemas/pl-fe/settings.ts @@ -16,11 +16,10 @@ const settingsSchema = z.object({ autoPlayGif: z.boolean().catch(true), displayMedia: z.enum(['default', 'hide_all', 'show_all']).catch('default'), displaySpoilers: z.boolean().catch(false), - preserveSpoilers: z.boolean().catch(false), - unfollowModal: z.boolean().catch(false), + unfollowModal: z.boolean().catch(true), boostModal: z.boolean().catch(false), deleteModal: z.boolean().catch(true), - missingDescriptionModal: z.boolean().catch(false), + missingDescriptionModal: z.boolean().catch(true), defaultPrivacy: z.enum(['public', 'unlisted', 'private', 'direct']).catch('public'), defaultContentType: z.enum(['text/plain', 'text/markdown']).catch('text/plain'), themeMode: z.enum(['system', 'light', 'dark', 'black']).catch('system'), @@ -29,60 +28,20 @@ const settingsSchema = z.object({ explanationBox: z.boolean().catch(true), autoloadTimelines: z.boolean().catch(true), autoloadMore: z.boolean().catch(true), + preserveSpoilers: z.boolean().catch(false), + autoTranslate: z.boolean().catch(false), + knownLanguages: z.array(z.string()).catch([]), + 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), - }), - }), - 'public:local': coerceObject({ - other: coerceObject({ - onlyMedia: z.boolean().catch(false), - }), - }), - remote: coerceObject({ - other: coerceObject({ - onlyMedia: z.boolean().catch(false), - }), - }), - bubble: 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), - }), - sounds: z.record(z.boolean()).catch({}), - }), - autoTranslate: z.boolean().catch(false), - knownLanguages: z.array(z.string()).catch([]), - frequentlyUsedEmojis: z.record(z.number()).catch({}), - frequentlyUsedLanguages: z.record(z.number()).catch({}), + timelines: z.record(coerceObject({ shows: coerceObject({ reblog: z.boolean().catch(true), @@ -94,7 +53,31 @@ const settingsSchema = z.object({ }), })).catch({}), + account_timeline: coerceObject({ + shows: coerceObject({ + pinned: z.boolean().catch(true), + }), + }), + + remote_timeline: coerceObject({ + pinnedHosts: z.string().array().catch([]), + }), + + notifications: coerceObject({ + quickFilter: coerceObject({ + active: z.string().catch('all'), + advanced: z.boolean().catch(false), + show: z.boolean().catch(true), + }), + sounds: z.record(z.boolean()).catch({}), + }), + + frequentlyUsedEmojis: z.record(z.number()).catch({}), + frequentlyUsedLanguages: z.record(z.number()).catch({}), + saved: z.boolean().catch(true), + + demo: z.boolean().catch(false), }); type Settings = z.infer;