Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Save user preferred font size in local storage #1162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getPlainFromStorage,
LANGUAGE_KEY,
savePlainToStorage,
USER_FONT_SIZE_KEY,
} from '../../../client/src/services/storage';
import { LocaleType } from '../../../client/src/types/general';
import { polling } from '../../../client/src/utils/requestUtils';
Expand Down Expand Up @@ -165,12 +166,25 @@ function App() {
.getPropertyValue('font-size');
const fontSize = parseFloat(style);

(root as HTMLElement).style.fontSize =
(e.key === '0' ? 16 : fontSize + (e.key === '=' ? 1 : -1)) + 'px';
const newFontSize =
e.key === '0' ? 16 : fontSize + (e.key === '=' ? 1 : -1);
(root as HTMLElement).style.fontSize = newFontSize + 'px';
savePlainToStorage(USER_FONT_SIZE_KEY, newFontSize);
}
}, []);
useKeyboardNavigation(handleKeyEvent);

useEffect(() => {
const root = document.querySelector(':root');
if (!root) {
return;
}
const newFontSize = getPlainFromStorage(USER_FONT_SIZE_KEY);
if (newFontSize) {
(root as HTMLElement).style.fontSize = newFontSize + 'px';
}
}, []);

useEffect(() => {
let intervalId: number;
if (!Object.keys(envConfig).length) {
Expand Down
1 change: 1 addition & 0 deletions client/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export const ANSWER_SPEED_KEY = 'answer_speed_key';
export const HIDE_TUTORIALS_KEY = 'hide_tutorials';
export const ACCESS_TOKEN_KEY = 'access_token';
export const REFRESH_TOKEN_KEY = 'refresh_token';
export const USER_FONT_SIZE_KEY = 'user_font_size';