customizable font size (#1462)

This commit is contained in:
Athou
2025-05-03 22:17:55 +02:00
parent 680c927e1d
commit b02aa923d7
4 changed files with 31 additions and 3 deletions

View File

@@ -260,6 +260,7 @@ export interface LocalSettings {
viewMode: ViewMode
sidebarWidth: number
announcementHash: string
fontSizePercentage: number
}
export interface StarRequest {

View File

@@ -36,6 +36,7 @@ export const initialLocalSettings: LocalSettings = {
viewMode: "detailed",
sidebarWidth: 360,
announcementHash: "no-hash",
fontSizePercentage: 100,
}
const initialState: UserState = {
@@ -49,6 +50,9 @@ export const userSlice = createSlice({
setViewMode: (state, action: PayloadAction<ViewMode>) => {
state.localSettings.viewMode = action.payload
},
setFontSizePercentage: (state, action: PayloadAction<number>) => {
state.localSettings.fontSizePercentage = action.payload
},
setSidebarWidth: (state, action: PayloadAction<number>) => {
state.localSettings.sidebarWidth = action.payload
},
@@ -162,4 +166,4 @@ export const userSlice = createSlice({
},
})
export const { setViewMode, setSidebarWidth, setAnnouncementHash } = userSlice.actions
export const { setViewMode, setSidebarWidth, setAnnouncementHash, setFontSizePercentage } = userSlice.actions

View File

@@ -32,8 +32,9 @@ const useStyles = tss
rtl: boolean
showSelectionIndicator: boolean
maxWidth?: number
fontSizePercentage: number
}>()
.create(({ theme, colorScheme, read, expanded, viewMode, rtl, showSelectionIndicator, maxWidth }) => {
.create(({ theme, colorScheme, read, expanded, viewMode, rtl, showSelectionIndicator, maxWidth, fontSizePercentage }) => {
let backgroundColor: string
if (colorScheme === "dark") {
backgroundColor = read ? "inherit" : theme.colors.dark[5]
@@ -83,10 +84,12 @@ const useStyles = tss
},
},
headerLink: {
fontSize: `${fontSizePercentage}%`,
color: "inherit",
textDecoration: "none",
},
body: {
fontSize: `${fontSizePercentage}%`,
direction: rtl ? "rtl" : "ltr",
maxWidth: maxWidth ?? "100%",
},
@@ -95,6 +98,7 @@ const useStyles = tss
export function FeedEntry(props: FeedEntryProps) {
const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
const fontSizePercentage = useAppSelector(state => state.user.localSettings.fontSizePercentage)
const { classes, cx } = useStyles({
read: props.entry.read,
expanded: props.expanded,
@@ -102,6 +106,7 @@ export function FeedEntry(props: FeedEntryProps) {
rtl: props.entry.rtl,
showSelectionIndicator: props.showSelectionIndicator,
maxWidth: props.maxWidth,
fontSizePercentage,
})
const externalLinkDisplayMode = useAppSelector(state => state.user.settings?.externalLinkIconDisplayMode)

View File

@@ -7,6 +7,7 @@ import {
Menu,
SegmentedControl,
type SegmentedControlItem,
Slider,
useMantineColorScheme,
} from "@mantine/core"
import { showNotification } from "@mantine/notifications"
@@ -14,7 +15,7 @@ import { client } from "app/client"
import { redirectToAbout, redirectToAdminUsers, redirectToDonate, redirectToMetrics, redirectToSettings } from "app/redirect/thunks"
import { useAppDispatch, useAppSelector } from "app/store"
import type { ViewMode } from "app/types"
import { setViewMode } from "app/user/slice"
import { setFontSizePercentage, setViewMode } from "app/user/slice"
import { reloadProfile } from "app/user/thunks"
import dayjs from "dayjs"
import { useNow } from "hooks/useNow"
@@ -100,6 +101,7 @@ export function ProfileMenu(props: ProfileMenuProps) {
const admin = useAppSelector(state => state.user.profile?.admin)
const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
const forceRefreshCooldownDuration = useAppSelector(state => state.server.serverInfos?.forceRefreshCooldownDuration)
const fontSizePercentage = useAppSelector(state => state.user.localSettings.fontSizePercentage)
const dispatch = useAppDispatch()
const { colorScheme, setColorScheme } = useMantineColorScheme()
@@ -184,6 +186,22 @@ export function ProfileMenu(props: ProfileMenuProps) {
mb="xs"
/>
<Divider />
<Menu.Label>
<Trans>Font size</Trans>
</Menu.Label>
<Slider
min={50}
max={150}
step={5}
marks={[{ value: 100, label: "100%" }]}
label={v => `${v}%`}
mb="xl"
value={fontSizePercentage}
onChange={value => dispatch(setFontSizePercentage(value))}
/>
{admin && (
<>
<Divider />