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 viewMode: ViewMode
sidebarWidth: number sidebarWidth: number
announcementHash: string announcementHash: string
fontSizePercentage: number
} }
export interface StarRequest { export interface StarRequest {

View File

@@ -36,6 +36,7 @@ export const initialLocalSettings: LocalSettings = {
viewMode: "detailed", viewMode: "detailed",
sidebarWidth: 360, sidebarWidth: 360,
announcementHash: "no-hash", announcementHash: "no-hash",
fontSizePercentage: 100,
} }
const initialState: UserState = { const initialState: UserState = {
@@ -49,6 +50,9 @@ export const userSlice = createSlice({
setViewMode: (state, action: PayloadAction<ViewMode>) => { setViewMode: (state, action: PayloadAction<ViewMode>) => {
state.localSettings.viewMode = action.payload state.localSettings.viewMode = action.payload
}, },
setFontSizePercentage: (state, action: PayloadAction<number>) => {
state.localSettings.fontSizePercentage = action.payload
},
setSidebarWidth: (state, action: PayloadAction<number>) => { setSidebarWidth: (state, action: PayloadAction<number>) => {
state.localSettings.sidebarWidth = action.payload 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 rtl: boolean
showSelectionIndicator: boolean showSelectionIndicator: boolean
maxWidth?: number 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 let backgroundColor: string
if (colorScheme === "dark") { if (colorScheme === "dark") {
backgroundColor = read ? "inherit" : theme.colors.dark[5] backgroundColor = read ? "inherit" : theme.colors.dark[5]
@@ -83,10 +84,12 @@ const useStyles = tss
}, },
}, },
headerLink: { headerLink: {
fontSize: `${fontSizePercentage}%`,
color: "inherit", color: "inherit",
textDecoration: "none", textDecoration: "none",
}, },
body: { body: {
fontSize: `${fontSizePercentage}%`,
direction: rtl ? "rtl" : "ltr", direction: rtl ? "rtl" : "ltr",
maxWidth: maxWidth ?? "100%", maxWidth: maxWidth ?? "100%",
}, },
@@ -95,6 +98,7 @@ const useStyles = tss
export function FeedEntry(props: FeedEntryProps) { export function FeedEntry(props: FeedEntryProps) {
const viewMode = useAppSelector(state => state.user.localSettings.viewMode) const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
const fontSizePercentage = useAppSelector(state => state.user.localSettings.fontSizePercentage)
const { classes, cx } = useStyles({ const { classes, cx } = useStyles({
read: props.entry.read, read: props.entry.read,
expanded: props.expanded, expanded: props.expanded,
@@ -102,6 +106,7 @@ export function FeedEntry(props: FeedEntryProps) {
rtl: props.entry.rtl, rtl: props.entry.rtl,
showSelectionIndicator: props.showSelectionIndicator, showSelectionIndicator: props.showSelectionIndicator,
maxWidth: props.maxWidth, maxWidth: props.maxWidth,
fontSizePercentage,
}) })
const externalLinkDisplayMode = useAppSelector(state => state.user.settings?.externalLinkIconDisplayMode) const externalLinkDisplayMode = useAppSelector(state => state.user.settings?.externalLinkIconDisplayMode)

View File

@@ -7,6 +7,7 @@ import {
Menu, Menu,
SegmentedControl, SegmentedControl,
type SegmentedControlItem, type SegmentedControlItem,
Slider,
useMantineColorScheme, useMantineColorScheme,
} from "@mantine/core" } from "@mantine/core"
import { showNotification } from "@mantine/notifications" 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 { redirectToAbout, redirectToAdminUsers, redirectToDonate, redirectToMetrics, redirectToSettings } from "app/redirect/thunks"
import { useAppDispatch, useAppSelector } from "app/store" import { useAppDispatch, useAppSelector } from "app/store"
import type { ViewMode } from "app/types" 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 { reloadProfile } from "app/user/thunks"
import dayjs from "dayjs" import dayjs from "dayjs"
import { useNow } from "hooks/useNow" import { useNow } from "hooks/useNow"
@@ -100,6 +101,7 @@ export function ProfileMenu(props: ProfileMenuProps) {
const admin = useAppSelector(state => state.user.profile?.admin) const admin = useAppSelector(state => state.user.profile?.admin)
const viewMode = useAppSelector(state => state.user.localSettings.viewMode) const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
const forceRefreshCooldownDuration = useAppSelector(state => state.server.serverInfos?.forceRefreshCooldownDuration) const forceRefreshCooldownDuration = useAppSelector(state => state.server.serverInfos?.forceRefreshCooldownDuration)
const fontSizePercentage = useAppSelector(state => state.user.localSettings.fontSizePercentage)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const { colorScheme, setColorScheme } = useMantineColorScheme() const { colorScheme, setColorScheme } = useMantineColorScheme()
@@ -184,6 +186,22 @@ export function ProfileMenu(props: ProfileMenuProps) {
mb="xs" 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 && ( {admin && (
<> <>
<Divider /> <Divider />