Skip to content

Commit

Permalink
ensure selected theme exists (Memmy-App#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf authored Jun 28, 2023
1 parent fb925e5 commit 56ad99a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { writeToLog } from "./helpers/LogHelper";
import { lemmyAuthToken, lemmyInstance } from "./lemmy/LemmyInstance";
import { loadAccounts } from "./slices/accounts/accountsActions";
import { selectAccountsLoaded } from "./slices/accounts/accountsSlice";
import { loadSettings } from "./slices/settings/settingsActions";
import { loadSettings, setSetting } from "./slices/settings/settingsActions";
import { selectSettings } from "./slices/settings/settingsSlice";
import { getUnreadCount } from "./slices/site/siteActions";
import { useAppDispatch, useAppSelector } from "./store";
import getFontScale from "./theme/fontSize";
import { darkTheme } from "./theme/theme";
import { ThemeOptionsMap } from "./theme/themeOptions";
import { ThemeOptionsArr, ThemeOptionsMap } from "./theme/themeOptions";

const logError = (e, info) => {
writeToLog(e.toString());
Expand Down Expand Up @@ -87,8 +87,17 @@ function Start() {
};

useEffect(() => {
let usedTheme = theme;

// @ts-ignore
if (!ThemeOptionsArr.includes(usedTheme)) {
usedTheme = "Dark";

dispatch(setSetting({ theme: usedTheme }));
}

const newTheme = extendTheme({
...ThemeOptionsMap[theme],
...ThemeOptionsMap[usedTheme],
...(isSystemTextSize
? {
components: {
Expand Down
2 changes: 1 addition & 1 deletion slices/settings/settingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const initialState: SettingsState = {
compactView: false,
compactThumbnailPosition: "Left",
compactShowVotingButtons: true,
theme: "Brown",
theme: "Dark",
isSystemTextSize: true,
fontSize: 2,
haptics: "Medium",
Expand Down

0 comments on commit 56ad99a

Please sign in to comment.