diff --git a/TODO.md b/TODO.md index b8ff420d..e81d4549 100644 --- a/TODO.md +++ b/TODO.md @@ -14,10 +14,12 @@ - [ ] Separated server vs client settings + interface (new events?) - [x] Schema validation + default with valibot - [ ] Use invariant in state handlers + other places +- [ ] Get rid of /writers endpoint and send that data along with relevant responses +- [ ] Switch to node subpath imports ## Schemas -- [ ] Write tests for schemas package +- [x] Write tests for schemas package ## Backend @@ -49,7 +51,7 @@ - [ ] Use new events from BE - [ ] Refactor into concept of `content` - [ ] Render navigator's bar extra icons in controller -- [ ] Better settings management via hooks +- [x] Better settings management via hooks ## Electron diff --git a/apps/frontend/package.json b/apps/frontend/package.json index f5b16b4e..985b0ba8 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -29,6 +29,7 @@ "@fortawesome/free-solid-svg-icons": "^6.6.0", "@fortawesome/react-fontawesome": "^0.2.2", "@mui/material": "^5.16.6", + "@presenter/schemas": "*", "@presenter/swiss-knife": "*", "@presenter/themes": "*", "@sentry/browser": "^6.19.7", @@ -36,6 +37,7 @@ "@tanstack/router-zod-adapter": "^1.51.6", "classnames": "^2.3.1", "copy-to-clipboard": "^3.3.1", + "dequal": "^2.0.3", "detect-browser": "^5.3.0", "eventemitter3": "^5.0.1", "gurmukhi-utils": "^3.2.2", @@ -66,7 +68,7 @@ "@types/scroll-into-view": "^1.16.0", "@types/testing-library__jest-dom": "^5.14.5", "@vitejs/plugin-react": "^4.3.1", - "@vitest/ui": "^1.6.0", + "@vitest/ui": "^2.1.4", "happy-dom": "^14.11.0", "jest-environment-jsdom": "^29.5.0", "source-map-explorer": "^2.5.2", diff --git a/apps/frontend/src/app/__root.tsx b/apps/frontend/src/app/__root.tsx index bb067890..be6a817f 100644 --- a/apps/frontend/src/app/__root.tsx +++ b/apps/frontend/src/app/__root.tsx @@ -5,6 +5,7 @@ import { RecommendedSources, Writer } from '@presenter/contract' import { createRootRoute, Navigate, Outlet } from '@tanstack/react-router' import classNames from 'classnames' import { Provider } from 'jotai' +import { DevTools } from 'jotai-devtools' import { SnackbarProvider } from 'notistack' import { PureComponent, Suspense } from 'react' @@ -13,16 +14,9 @@ import { API_URL, isDesktop, isMobile, isTablet } from '~/helpers/consts' import { HistoryContext, RecommendedSourcesContext, - SettingsContext, WritersContext, } from '~/helpers/contexts' -import { DEFAULT_OPTIONS } from '~/helpers/options' -import { merge } from '~/helpers/utils' import { store } from '~/services/jotai' -// import controller from '~/services/controller' - -// const loadSettings = () => merge( { local: controller.readSettings() }, DEFAULT_OPTIONS ) -const loadSettings = () => DEFAULT_OPTIONS class App extends PureComponent { state = { @@ -31,25 +25,16 @@ class App extends PureComponent { latestLines: {}, recommendedSources: {} as RecommendedSources['recommendedSources'], writers: {}, - settings: loadSettings(), } componentDidMount() { - // Register controller event - // controller.on( 'history:viewed-lines', this.onViewedLines ) - // controller.on( 'history:transitions', this.onTransitionHistory ) - // controller.on( 'history:latest-lines', this.onLatestLineHistory ) - // controller.on( 'banis:list', this.onBanis ) - // controller.on( 'settings', this.onSettings ) - - // Get recommended sources and set as settings, if there are none void fetch( `${API_URL}/sources` ) .then( ( res ) => res.json() ) .then( ( { recommendedSources }: { recommendedSources: RecommendedSources['recommendedSources'] } ) => { //* Update default options and settings with fetched recommended sources - DEFAULT_OPTIONS.local.sources = recommendedSources + // DEFAULT_OPTIONS.local.sources = recommendedSources //! Re-load settings since we've modified DEFAULT_OPTIONS directly - this.setState( { recommendedSources, settings: loadSettings() } ) + this.setState( { recommendedSources } ) } ) // Get writers @@ -58,40 +43,6 @@ class App extends PureComponent { .then( ( { writers }: { writers: Writer[] } ) => this.setState( { writers } ) ) } - componentWillUnmount() { - // Deregister event listeners from controller - // controller.off( 'shabads:current', this.onShabad ) - // controller.off( 'lines:current', this.onLine ) - // controller.off( 'history:transitions', this.onTransitionHistory ) - // controller.off( 'history:latest-lines', this.onLatestLineHistory ) - // controller.off( 'lines:main', this.onMainLine ) - // controller.off( 'lines:next', this.onNextLine ) - // controller.off( 'lines:viewed', this.onViewedLines ) - // controller.off( 'banis:list', this.onBanis ) - // controller.off( 'banis:current', this.onBani ) - // controller.off( 'settings', this.onSettings ) - } - - onBanis = ( banis: any[] ) => this.setState( { banis } ) - - onSettings = ( { global = {}, local = {}, ...settings } ) => { - // controller.saveLocalSettings( local, false ) - - this.setState( ( state: typeof this.state ) => ( { - settings: { - ...Object - .entries( settings ) - .filter( ( [ , config ] ) => config ) - .reduce( ( deviceSettings, [ host, config ] ) => ( { - ...deviceSettings, - [ host ]: merge( DEFAULT_OPTIONS.local, config ), - } ), {} ), - // local: controller.readSettings(), - global: merge( state.settings.global, global ), - }, - } ) ) - } - render() { const { recommendedSources, @@ -99,7 +50,6 @@ class App extends PureComponent { viewedLines, transitionHistory, latestLines, - settings, } = this.state return ( @@ -107,17 +57,15 @@ class App extends PureComponent { }> - - - - - - - - - - - + + + + + + + + + diff --git a/apps/frontend/src/app/overlay/index.lazy.tsx b/apps/frontend/src/app/overlay/index.lazy.tsx index 86e16750..f611375a 100644 --- a/apps/frontend/src/app/overlay/index.lazy.tsx +++ b/apps/frontend/src/app/overlay/index.lazy.tsx @@ -1,44 +1,40 @@ import { createLazyFileRoute } from '@tanstack/react-router' import classNames from 'classnames' -import { mapValues } from 'radashi' -import { useContext } from 'react' +import { mapValues, sift } from 'radashi' -import { SettingsContext } from '~/helpers/contexts' import { LANGUAGES } from '~/helpers/data' import { customiseLine, getTransliterators } from '~/helpers/line' -import { filterFalsyValues } from '~/helpers/utils' -import { useCurrentLine, useTranslations } from '~/hooks' +import { useTranslations } from '~/hooks' +import { useContent } from '~/services/content' +import { useGlobalSettings } from '~/services/settings' import { useStatus } from '~/services/status' import Line from './-components/Line' import ThemeLoader from './-components/ThemeLoader' const Overlay = () => { - const settings = useContext( SettingsContext ) const { connected } = useStatus() - const { global: globalSettings } = settings || {} - const { overlay: { overlayName, ...overlay } } = globalSettings || {} + const [ { overlay: { name, ...overlay, lineEnding } } ] = useGlobalSettings() - const [ line ] = useCurrentLine() + const { line } = useContent() const { typeId } = line - const { lineEnding } = overlay const translations = mapValues( - useTranslations( filterFalsyValues( [ + useTranslations( sift( [ overlay.englishTranslation && LANGUAGES.english, overlay.punjabiTranslation && LANGUAGES.punjabi, overlay.spanishTranslation && LANGUAGES.spanish, - ] ) as number[] ), + ] ) ), ( line ) => customiseLine( line, { lineEnding, typeId } ) ) const transliterators = mapValues( - getTransliterators( filterFalsyValues( [ + getTransliterators( sift( [ overlay.englishTransliteration && LANGUAGES.english, overlay.hindiTransliteration && LANGUAGES.hindi, overlay.urduTransliteration && LANGUAGES.urdu, - ] ) as number[] ), + ] ) ), ( transliterate ) => ( text: string ) => transliterate( customiseLine( text, { lineEnding, typeId } ) ), @@ -48,7 +44,7 @@ const Overlay = () => { return (
- + , -} - -const Display = ( { settings }: DisplayProps ) => { - const { - layout, - display, - vishraams, - theme: { - simpleGraphics: simple, - backgroundImage: background, - highlightCurrentLine: highlight, - dimNextAndPrevLines: dim, +const Display = () => { + const [ { + accessibility: { + reducedMotion: simple, }, - } = settings - - const { lineEnding } = display + dimNextAndPrevLines: dim, + backgroundImage: background, + highlightCurrentLine: highlight, + lineEnding, + nextLines: nextLineCount, + previousLines: previousLineCount, + translations: translationSettings, + transliterations, + } ] = useLocalSettings() // Find the correct line in the Shabad const { line, lineIndex, lines } = useContent() // Get the next lines - const { nextLines: nextLineCount, previousLines: previousLineCount } = display const previousLines = previousLineCount && lineIndex ? lines.slice( Math.max( lineIndex - previousLineCount, 0 ), lineIndex ) : [] const nextLines = line ? lines.slice( lineIndex + 1, lineIndex + nextLineCount + 1 ) : [] const translations = mapValues( - useTranslations( filterFalsyValues( [ - display.englishTranslation && LANGUAGES.english, - display.punjabiTranslation && LANGUAGES.punjabi, - display.spanishTranslation && LANGUAGES.spanish, - ] ) as number[] ), + useTranslations( sift( [ + translationSettings.english && LANGUAGES.english, + translationSettings.punjabi && LANGUAGES.punjabi, + translationSettings.spanish && LANGUAGES.spanish, + ] ) ), ( line ) => customiseLine( line, { lineEnding, typeId: line.typeId } ), ) const transliterators = mapValues( - getTransliterators( filterFalsyValues( [ - display.englishTransliteration && LANGUAGES.english, - display.hindiTransliteration && LANGUAGES.hindi, - display.urduTransliteration && LANGUAGES.urdu, - ] ) as number[] ), + getTransliterators( sift( [ + transliterations.english && LANGUAGES.english, + transliterations.hindi && LANGUAGES.hindi, + transliterations.urdu && LANGUAGES.urdu, + ] ) ), ( transliterate ) => ( text: string ) => transliterate( customiseLine( text, { lineEnding, typeId: line?.typeId } ), ), @@ -70,10 +64,6 @@ const Display = ( { settings }: DisplayProps ) => { ) )} @@ -82,13 +72,9 @@ const Display = ( { settings }: DisplayProps ) => { {line && ( )} @@ -97,10 +83,6 @@ const Display = ( { settings }: DisplayProps ) => { ) )} diff --git a/apps/frontend/src/app/presenter/-components/Line/index.tsx b/apps/frontend/src/app/presenter/-components/Line/index.tsx index 7ef2c430..f70a1ae7 100644 --- a/apps/frontend/src/app/presenter/-components/Line/index.tsx +++ b/apps/frontend/src/app/presenter/-components/Line/index.tsx @@ -14,134 +14,72 @@ import { Transliterators, } from '~/helpers/data' import { classifyWords, partitionLine, sortBy } from '~/helpers/line' -import { DEFAULT_OPTIONS } from '~/helpers/options' -import { filterFalsyObjectValues } from '~/helpers/utils' +import { useLocalSettings } from '~/services/settings' type LineProps = { className?: string, gurmukhi: string, translations?: Translations, transliterators?: Transliterators, - syllabicWeights?: boolean, - syllableCount?: boolean, - inlineTransliteration?: boolean, - inlineColumnGuides?: boolean, - spacing?: string, - centerText?: boolean, - justifyText?: boolean, - larivaarGurbani?: boolean, - larivaarAssist?: boolean, - vishraamColors?: boolean, - vishraamCharacters?: boolean, - vishraamLight?: boolean, - vishraamMedium?: boolean, - vishraamHeavy?: boolean, - splitOnVishraam?: boolean, - simpleGraphics?: boolean, - presenterFontSize?: number, - relativeGurmukhiFontSize?: number, - relativeEnglishFontSize?: number, - relativePunjabiFontSize?: number, - relativeHindiFontSize?: number, - relativeUrduFontSize?: number, } -const { - display: { - syllabicWeights: defaultSyllabicWeights, - syllableCount: defaultSyllableCount, - larivaarAssist: defaultLarivaarAssist, - larivaarGurbani: defaultLarivaarGurbani, - }, - layout: { - spacing: defaultSpacing, - centerText: defaultCenterText, - justifyText: defaultJustifyText, - inlineTransliteration: defaultInlineTransliteration, - inlineColumnGuides: defaultInlineColumnGuides, - splitOnVishraam: defaultSplitOnVishraam, - presenterFontSize: defaultPresenterFontSize, - relativeGurmukhiFontSize: defaultRelativeGurmukhiFontSize, - relativeEnglishFontSize: defaultRelativeEnglishFontSize, - relativePunjabiFontSize: defaultRelativePunjabiFontSize, - relativeHindiFontSize: defaultRelativeHindiFontSize, - relativeUrduFontSize: defaultRelativeUrduFontSize, - }, - vishraams: { - vishraamColors: defaultVishraamColors, - vishraamCharacters: defaultVishraamCharacters, - vishraamHeavy: defaultVishraamHeavy, - vishraamMedium: defaultVishraamMedium, - vishraamLight: defaultVishraamLight, - }, - theme: { simpleGraphics }, -} = DEFAULT_OPTIONS.local - const Line = ( { className = undefined, gurmukhi, translations = {}, transliterators = {}, - syllabicWeights = defaultSyllabicWeights, - syllableCount = defaultSyllableCount, - inlineTransliteration = defaultInlineTransliteration, - inlineColumnGuides = defaultInlineColumnGuides, - spacing = defaultSpacing, - centerText = defaultCenterText, - justifyText = defaultJustifyText, - presenterFontSize = defaultPresenterFontSize, - relativeGurmukhiFontSize = defaultRelativeGurmukhiFontSize, - relativeEnglishFontSize = defaultRelativeEnglishFontSize, - relativePunjabiFontSize = defaultRelativePunjabiFontSize, - relativeHindiFontSize = defaultRelativeHindiFontSize, - relativeUrduFontSize = defaultRelativeUrduFontSize, - larivaarGurbani: larivaar = defaultLarivaarGurbani, - larivaarAssist = defaultLarivaarAssist, - vishraamColors: vishraams = defaultVishraamColors, - vishraamCharacters = defaultVishraamCharacters, - vishraamLight = defaultVishraamLight, - vishraamMedium = defaultVishraamMedium, - vishraamHeavy = defaultVishraamHeavy, - splitOnVishraam: partition = defaultSplitOnVishraam, - simpleGraphics: simple, }: LineProps ) => { - const fontSizes = filterFalsyObjectValues( { - [ LANGUAGES.english ]: relativeEnglishFontSize, - [ LANGUAGES.spanish ]: relativeEnglishFontSize, - [ LANGUAGES.punjabi ]: relativePunjabiFontSize, - [ LANGUAGES.hindi ]: relativeHindiFontSize, - [ LANGUAGES.urdu ]: relativeUrduFontSize, - } ) + const [ { + fontSizes, + larivaarGurbani, + larivaarAssist, + pauses, + accessibility: { reducedMotion }, + spacing, + centerText, + inlineColumnGuides, + inlineTransliteration, + syllabicWeights, + syllableCount, + } ] = useLocalSettings() + + const languageFontSizes = { + [ LANGUAGES.english ]: fontSizes.relativeEnglish, + [ LANGUAGES.spanish ]: fontSizes.relativeEnglish, + [ LANGUAGES.punjabi ]: fontSizes.relativePunjabi, + [ LANGUAGES.hindi ]: fontSizes.relativeHindi, + [ LANGUAGES.urdu ]: fontSizes.relativeUrdu, + } return (

- {partitionLine( gurmukhi, !vishraamCharacters ).map( + {partitionLine( gurmukhi, !pauses.characters ).map( ( line, lineIndex ) => ( {line.map( ( { word, type }, i ) => ( @@ -157,7 +95,7 @@ const Line = ( { || syllabicWeights || inlineColumnGuides, } )} - style={relativeGurmukhiFontSize ? { fontSize: `${relativeGurmukhiFontSize}em` } : {}} + style={{ fontSize: `${fontSizes.relativeGurmukhi}em` }} > {word} @@ -173,8 +111,8 @@ const Line = ( { .map( ( [ languageId, transliterate ] ) => ( {transliterate( word )} @@ -201,10 +139,10 @@ const Line = ( { >

{translation}

@@ -222,14 +160,14 @@ const Line = ( { >

{classifyWords( transliterate( gurmukhi ), - !vishraamCharacters + !pauses.characters ).map( ( { word, type }, i ) => ( { } }, [ history, lines, previousLines, navigate, pathname ] ) - const settings = useContext( SettingsContext ) - const { local: { theme: { simpleGraphics: simple } } } = settings + const [ { accessibility: { reducedMotion: simple } } ] = useLocalSettings() return (

diff --git a/apps/frontend/src/app/presenter/controller/search/-components/Result.tsx b/apps/frontend/src/app/presenter/controller/search/-components/Result.tsx index bbbdb2ff..b888c6db 100644 --- a/apps/frontend/src/app/presenter/controller/search/-components/Result.tsx +++ b/apps/frontend/src/app/presenter/controller/search/-components/Result.tsx @@ -2,11 +2,11 @@ import { ListItem } from '@mui/material' import classNames from 'classnames' import { forwardRef, useContext } from 'react' -import { RecommendedSourcesContext, SettingsContext, WritersContext } from '~/helpers/contexts' +import { RecommendedSourcesContext, WritersContext } from '~/helpers/contexts' import { LANGUAGE_NAMES, SOURCE_ABBREVIATIONS, TRANSLITERATORS } from '~/helpers/data' import { customiseLine, getTranslation } from '~/helpers/line' import { setContent } from '~/services/content' -import controller from '~/services/controller' +import { useLocalSettings } from '~/services/settings' type ResultProps = { gurmukhi: string, @@ -33,31 +33,31 @@ const Result = forwardRef( ( { sourcePage, translations, }: ResultProps, ref ) => { - const { local: { + const [ { sources, - search: { - showResultCitations, - resultTransliterationLanguage, - resultTranslationLanguage, + results: { + citations, + transliterationLanguage, + translationLanguage, lineEnding, }, - } = {} } = useContext( SettingsContext ) + } ] = useLocalSettings() const writers = useContext( WritersContext ) const recommendedSources = useContext( RecommendedSourcesContext ) - const transliteration = resultTransliterationLanguage && customiseLine( - TRANSLITERATORS[ resultTransliterationLanguage ]( gurmukhi ), + const transliteration = transliterationLanguage && customiseLine( + TRANSLITERATORS[ transliterationLanguage ]( gurmukhi ), { lineEnding, typeId }, ) - const translation = resultTranslationLanguage && translations && customiseLine( + const translation = translationLanguage && translations && customiseLine( getTranslation( { line: { translations }, shabad: { sourceId }, recommendedSources, sources, - languageId: resultTranslationLanguage, + languageId: translationLanguage, } ), { lineEnding, typeId }, ) @@ -71,7 +71,7 @@ const Result = forwardRef( ( { const onClick = () => setContent( { id: shabadId, lineId, type: 'shabad' } ) // Helper render functions for citation - const showCitation = showResultCitations && shabad?.section + const showCitation = citations && shabad?.section const getEnglish = ( { nameEnglish } ) => nameEnglish const getWriterName = () => getEnglish( writers[ shabad.writerId ] ) const getPageName = () => recommendedSources[ shabad.sourceId ].pageNameEnglish @@ -87,13 +87,13 @@ const Result = forwardRef( ( { {translation && ( -
+
{translation}
)} {transliteration && ( -
+
{translitBeforeMatch && {translitBeforeMatch}} {translitMatch && {translitMatch}} {translitAfterMatch && {translitAfterMatch}} diff --git a/apps/frontend/src/app/presenter/controller/search/index.tsx b/apps/frontend/src/app/presenter/controller/search/index.tsx index 1d35747e..a1a46b1c 100644 --- a/apps/frontend/src/app/presenter/controller/search/index.tsx +++ b/apps/frontend/src/app/presenter/controller/search/index.tsx @@ -5,7 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { IconButton, Input, InputAdornment, List } from '@mui/material' import { createFileRoute, useNavigate } from '@tanstack/react-router' import classNames from 'classnames' -import { useCallback, useContext, useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import { withNavigationHotkeys } from '~/components/NavigationHotkeys' import { @@ -14,8 +14,8 @@ import { SEARCH_CHARS, SEARCH_TYPES, } from '~/helpers/consts' -import { SettingsContext } from '~/helpers/contexts' import { search, useSearchResults } from '~/services/search' +import { useLocalSettings } from '~/services/settings' import Result from './-components/Result' import getHighlighter from './-match-highlighter' @@ -44,13 +44,13 @@ type SearchProps = { } const Search = ( { updateFocus, register, focused }: SearchProps ) => { - const { local: { - search: { - showResultCitations, - resultTransliterationLanguage, - resultTranslationLanguage, + const [ { + results: { + citations, + transliterationLanguage, + translationLanguage, }, - } = {} } = useContext( SettingsContext ) + } ] = useLocalSettings() // Set the initial search query from URL const navigate = useNavigate() @@ -86,9 +86,9 @@ const Search = ( { updateFocus, register, focused }: SearchProps ) => { query: searchValue, type: searchType, options: { - translations: !!resultTranslationLanguage, - transliterations: !!resultTransliterationLanguage, - citations: !!showResultCitations, + translations: !!translationLanguage, + transliterations: !!transliterationLanguage, + citations: !!citations, }, } ) } else clearResults() @@ -106,9 +106,9 @@ const Search = ( { updateFocus, register, focused }: SearchProps ) => { } ) }, [ navigate, - resultTranslationLanguage, - resultTransliterationLanguage, - showResultCitations, + translationLanguage, + transliterationLanguage, + citations, ] ) const filterInputKeys = ( event ) => { @@ -129,9 +129,9 @@ const Search = ( { updateFocus, register, focused }: SearchProps ) => { }, [ onChange, anchor, - resultTransliterationLanguage, - resultTranslationLanguage, - showResultCitations, + transliterationLanguage, + translationLanguage, + citations, ] ) useEffect( () => { highlightSearch() }, [] ) diff --git a/apps/frontend/src/app/presenter/route.lazy.tsx b/apps/frontend/src/app/presenter/route.lazy.tsx index daa32bf3..81810ca9 100644 --- a/apps/frontend/src/app/presenter/route.lazy.tsx +++ b/apps/frontend/src/app/presenter/route.lazy.tsx @@ -6,7 +6,7 @@ import { CssBaseline } from '@mui/material' import IconButton from '@mui/material/IconButton' import { createLazyFileRoute, Outlet, useLocation } from '@tanstack/react-router' import classNames from 'classnames' -import { lazy, Suspense, useContext, useRef, useState } from 'react' +import { lazy, Suspense, useRef, useState } from 'react' import { EventsType, useIdleTimer } from 'react-idle-timer' import CopyHotkeys from '~/components/CopyHotkeys' @@ -16,12 +16,12 @@ import Loader from '~/components/Loader' import NavigatorHotKeys from '~/components/NavigatorHotkeys' import ThemeLoader from '~/components/ThemeLoader' import { isDesktop } from '~/helpers/consts' -import { SettingsContext } from '~/helpers/contexts' import { toggleFullscreen } from '~/helpers/electron-utils' import { GLOBAL_SHORTCUTS } from '~/helpers/keyMap' import { CLIENT_OPTIONS } from '~/helpers/options' import { useNavigateUtils } from '~/hooks/navigate' import { clearLine, useContent } from '~/services/content' +import { useLocalSettings } from '~/services/settings' import StatusToast from './-components/StatusToast' import { ControllerLocationHistoryProvider } from './-controller-location-history' @@ -62,23 +62,22 @@ const Presenter = () => { const { lines } = useContent() - const { local: localSettings } = useContext( SettingsContext ) - const { - theme: { themeName }, - layout: { controllerZoom: zoom }, + const [ { + themeName, + controllerZoom, hotkeys, - } = localSettings + } ] = useLocalSettings() const toggleController = () => void navigate( { to: isControllerOpen ? '/' : '/presenter/controller' } ) - const { controllerZoom } = CLIENT_OPTIONS + // const { controllerZoom } = CLIENT_OPTIONS // const setZoom = ( controllerZoom: number ) => controller.setSettings( { // layout: { controllerZoom }, // } ) const setZoom = () => {} - const zoomInController = () => setZoom( Math.min( controllerZoom.max, zoom + 0.1 ) ) - const zoomOutController = () => setZoom( Math.max( controllerZoom.min, zoom - 0.1 ) ) + const zoomInController = () => setZoom( Math.min( CLIENT_OPTIONS.controllerZoom.max, zoom + 0.1 ) ) + const zoomOutController = () => setZoom( Math.max( CLIENT_OPTIONS.controllerZoom.min, zoom - 0.1 ) ) const zoomResetController = () => setZoom( 1 ) const toggleFullscreenController = () => { @@ -131,10 +130,10 @@ const Presenter = () => { }> - {!( isControllerOpen && controllerOnly ) && } + {!( isControllerOpen && controllerOnly ) && } -
+
diff --git a/apps/frontend/src/app/settings/-components/DynamicOptions.tsx b/apps/frontend/src/app/settings/-components/DynamicOptions.tsx index 23ba881e..053b8034 100644 --- a/apps/frontend/src/app/settings/-components/DynamicOptions.tsx +++ b/apps/frontend/src/app/settings/-components/DynamicOptions.tsx @@ -2,11 +2,10 @@ import { IconProp } from '@fortawesome/fontawesome-svg-core' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { Grid, Typography } from '@mui/material' import { ClientSettings, Settings } from '@presenter/contract' -import { useContext } from 'react' -import { SettingsContext } from '~/helpers/contexts' -import { CLIENT_OPTIONS, DEFAULT_OPTIONS, FLAT_OPTION_GROUPS } from '~/helpers/options' +import { CLIENT_OPTIONS, FLAT_OPTION_GROUPS } from '~/helpers/options' import controller from '~/services/controller' +import { useClientsSettings, useLocalSettings } from '~/services/settings' import SettingComponentFactory, { Button } from './SettingsComponents' @@ -85,12 +84,13 @@ type DynamicOptionsProps = { } const DynamicOptions = ( { device, group }: DynamicOptionsProps ) => { - const settings = useContext( SettingsContext ) + const [ clients ] = useClientsSettings() + const [ local ] = useLocalSettings() - const selectedDeviceSettings = settings[ device ] || settings.local + const selectedDeviceSettings = clients[ device ] ?? local const isGlobal = device === 'global' - const defaultSettings = isGlobal ? DEFAULT_OPTIONS.global : DEFAULT_OPTIONS.local + // const defaultSettings = isGlobal ? DEFAULT_OPTIONS.global : DEFAULT_OPTIONS.local const setSettings =