From b387370aaf96c7bb6fae4c4aafcd364afa0f7856 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:22:53 +0530 Subject: [PATCH] Add setting for page zoom (#1835) * add setting for page zoom * parse integer in zoom change listener * fix zoom input width * fix null gets saved as page zoom --- src/app/organisms/settings/Settings.jsx | 451 +++++++++++++------ src/app/pages/client/ClientNonUIFeatures.tsx | 26 ++ src/app/pages/client/ClientRoot.tsx | 17 +- src/app/state/settings.ts | 2 + 4 files changed, 341 insertions(+), 155 deletions(-) diff --git a/src/app/organisms/settings/Settings.jsx b/src/app/organisms/settings/Settings.jsx index 779931d..6329a57 100644 --- a/src/app/organisms/settings/Settings.jsx +++ b/src/app/organisms/settings/Settings.jsx @@ -1,13 +1,13 @@ import React, { useState, useEffect } from 'react'; +import { Input, toRem } from 'folds'; +import { isKeyHotkey } from 'is-hotkey'; import './Settings.scss'; import { clearCacheAndReload, logoutClient } from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import settings from '../../../client/state/settings'; import navigation from '../../../client/state/navigation'; -import { - toggleSystemTheme, -} from '../../../client/action/settings'; +import { toggleSystemTheme } from '../../../client/action/settings'; import { usePermissionState } from '../../hooks/usePermission'; import Text from '../../atoms/text/Text'; @@ -55,14 +55,41 @@ function AppearanceSection() { const [messageLayout, setMessageLayout] = useSetting(settingsAtom, 'messageLayout'); const [messageSpacing, setMessageSpacing] = useSetting(settingsAtom, 'messageSpacing'); const [twitterEmoji, setTwitterEmoji] = useSetting(settingsAtom, 'twitterEmoji'); + const [pageZoom, setPageZoom] = useSetting(settingsAtom, 'pageZoom'); const [isMarkdown, setIsMarkdown] = useSetting(settingsAtom, 'isMarkdown'); - const [hideMembershipEvents, setHideMembershipEvents] = useSetting(settingsAtom, 'hideMembershipEvents'); - const [hideNickAvatarEvents, setHideNickAvatarEvents] = useSetting(settingsAtom, 'hideNickAvatarEvents'); + const [hideMembershipEvents, setHideMembershipEvents] = useSetting( + settingsAtom, + 'hideMembershipEvents' + ); + const [hideNickAvatarEvents, setHideNickAvatarEvents] = useSetting( + settingsAtom, + 'hideNickAvatarEvents' + ); const [mediaAutoLoad, setMediaAutoLoad] = useSetting(settingsAtom, 'mediaAutoLoad'); const [urlPreview, setUrlPreview] = useSetting(settingsAtom, 'urlPreview'); const [encUrlPreview, setEncUrlPreview] = useSetting(settingsAtom, 'encUrlPreview'); const [showHiddenEvents, setShowHiddenEvents] = useSetting(settingsAtom, 'showHiddenEvents'); - const spacings = ['0', '100', '200', '300', '400', '500'] + const spacings = ['0', '100', '200', '300', '400', '500']; + + const [currentZoom, setCurrentZoom] = useState(`${pageZoom}`); + + const handleZoomChange = (evt) => { + setCurrentZoom(evt.target.value); + }; + + const handleZoomEnter = (evt) => { + if (isKeyHotkey('escape', evt)) { + evt.stopPropagation(); + setCurrentZoom(pageZoom); + } + if (isKeyHotkey('enter', evt)) { + const newZoom = parseInt(evt.target.value, 10); + if (Number.isNaN(newZoom)) return; + const safeZoom = Math.max(Math.min(newZoom, 150), 75); + setPageZoom(safeZoom); + setCurrentZoom(safeZoom); + } + }; return (