Skip to content

Commit

Permalink
Fix dark font on dark background by default
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Nov 26, 2024
1 parent 21a3710 commit 8583455
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions client/src/util/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JsonWebToken, SavedOAuthToken, UserTheme } from "@fumix/fu-blog-common";
import { base64UrlToBuffer, isOAuthType } from "@fumix/fu-blog-common";
import { base64UrlToBuffer, isOAuthType, isUserTheme } from "@fumix/fu-blog-common";

type OAuthState = { key: string; redirect_uri?: string };
const idTokenKey = "id_token";
Expand Down Expand Up @@ -67,7 +67,17 @@ export function saveCssPreference(css: UserTheme) {
}

export function loadCssPreference(): UserTheme {
return loadFromStorageAsString(window.localStorage, "cssTheme", "lightTheme") as UserTheme;
return loadFromStorage(
window.localStorage,
"cssTheme",
(saved) => {
if (isUserTheme(saved)) {
return saved;
}
return null;
},
"light",
);
}

//
Expand Down
7 changes: 6 additions & 1 deletion common/src/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export type UserWithOAuthProviders = User & {
oauthProviders: OAuthProviderId[];
};

export type UserTheme = "light" | "dark";
const userThemes = ["light", "dark"] as const;
export type UserTheme = (typeof userThemes)[number];

export function isUserTheme(s: string): s is UserTheme {
return userThemes.some((it) => it === s);
}

0 comments on commit 8583455

Please sign in to comment.