mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-28 03:06:50 +00:00
♻️(frontend) drop useSettingsDialogs hook
The useSettingsDialogs hook only encapsulated Valtio store manipulation that should be declared at the module level. Keeping it as a hook triggered unnecessary re-renders in components that used it, subscribing to the store. Remove the hook and use the store actions directly at the module level.
This commit is contained in:
committed by
aleb_the_flash
parent
0a0306b0a2
commit
86fcc2c7fe
@@ -23,7 +23,6 @@ import { VStack } from '@/styled-system/jsx'
|
|||||||
import { Checkbox } from '@/primitives/Checkbox.tsx'
|
import { Checkbox } from '@/primitives/Checkbox.tsx'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useSettingsDialog,
|
|
||||||
SettingsDialogExtendedKey,
|
SettingsDialogExtendedKey,
|
||||||
useTranscriptionLanguage,
|
useTranscriptionLanguage,
|
||||||
} from '@/features/settings'
|
} from '@/features/settings'
|
||||||
@@ -35,6 +34,7 @@ import { useIsMetadataCollectorEnabled } from '../hooks/useMetadataCollectorEnab
|
|||||||
import { useSidePanel } from '@/features/rooms/livekit/hooks/useSidePanel'
|
import { useSidePanel } from '@/features/rooms/livekit/hooks/useSidePanel'
|
||||||
import { useIsAdminOrOwner } from '@/features/rooms/livekit/hooks/useIsAdminOrOwner'
|
import { useIsAdminOrOwner } from '@/features/rooms/livekit/hooks/useIsAdminOrOwner'
|
||||||
import { LimitDescription } from './LimitDescription'
|
import { LimitDescription } from './LimitDescription'
|
||||||
|
import { openSettingsDialog } from '@/stores/settings'
|
||||||
|
|
||||||
export const TranscriptSidePanel = () => {
|
export const TranscriptSidePanel = () => {
|
||||||
const { data } = useConfig()
|
const { data } = useConfig()
|
||||||
@@ -48,8 +48,6 @@ export const TranscriptSidePanel = () => {
|
|||||||
const { selectedLanguageKey, selectedLanguageLabel, isLanguageSetToAuto } =
|
const { selectedLanguageKey, selectedLanguageLabel, isLanguageSetToAuto } =
|
||||||
useTranscriptionLanguage()
|
useTranscriptionLanguage()
|
||||||
|
|
||||||
const { openSettingsDialog } = useSettingsDialog()
|
|
||||||
|
|
||||||
const hasTranscriptAccess = useHasRecordingAccess(
|
const hasTranscriptAccess = useHasRecordingAccess(
|
||||||
RecordingMode.Transcript,
|
RecordingMode.Transcript,
|
||||||
FeatureFlags.Transcript
|
FeatureFlags.Transcript
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { HStack } from '@/styled-system/jsx'
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { navigateTo } from '@/navigation/navigateTo'
|
import { navigateTo } from '@/navigation/navigateTo'
|
||||||
import { useScreenReaderAnnounce } from '@/hooks/useScreenReaderAnnounce'
|
import { useScreenReaderAnnounce } from '@/hooks/useScreenReaderAnnounce'
|
||||||
import { useSettingsDialog } from '@/features/settings/hook/useSettingsDialog'
|
|
||||||
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
||||||
import { useHumanizeDuration } from '@/hooks/useHumanizeDuration'
|
import { useHumanizeDuration } from '@/hooks/useHumanizeDuration'
|
||||||
|
import { openSettingsDialog } from '@/stores/settings'
|
||||||
|
|
||||||
const IDLE_DISCONNECT_TIMEOUT_MS = 120000 // 2 minutes
|
const IDLE_DISCONNECT_TIMEOUT_MS = 120000 // 2 minutes
|
||||||
const COUNTDOWN_ANNOUNCEMENT_SECONDS = new Set([90, 60, 30])
|
const COUNTDOWN_ANNOUNCEMENT_SECONDS = new Set([90, 60, 30])
|
||||||
@@ -94,7 +94,6 @@ const Description = () => {
|
|||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const { t } = useTranslation('rooms', { keyPrefix: 'isIdleDisconnectModal' })
|
const { t } = useTranslation('rooms', { keyPrefix: 'isIdleDisconnectModal' })
|
||||||
const { openSettingsDialog } = useSettingsDialog()
|
|
||||||
return (
|
return (
|
||||||
<P>
|
<P>
|
||||||
{t('settingsPrefix')}{' '}
|
{t('settingsPrefix')}{' '}
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,7 @@ import { Button } from '@/primitives'
|
|||||||
import { RiSettings3Line } from '@remixicon/react'
|
import { RiSettings3Line } from '@remixicon/react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
||||||
import { useSettingsDialog } from '@/features/settings/hook/useSettingsDialog'
|
import { openSettingsDialog } from '@/stores/settings'
|
||||||
|
|
||||||
export const SettingsButton = ({
|
export const SettingsButton = ({
|
||||||
settingTab,
|
settingTab,
|
||||||
@@ -12,7 +12,6 @@ export const SettingsButton = ({
|
|||||||
onPress?: () => void
|
onPress?: () => void
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
|
const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
|
||||||
const { openSettingsDialog } = useSettingsDialog()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
+1
-2
@@ -2,11 +2,10 @@ import { RiSettings3Line } from '@remixicon/react'
|
|||||||
import { MenuItem } from 'react-aria-components'
|
import { MenuItem } from 'react-aria-components'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { menuRecipe } from '@/primitives/menuRecipe'
|
import { menuRecipe } from '@/primitives/menuRecipe'
|
||||||
import { useSettingsDialog } from '@/features/settings/hook/useSettingsDialog'
|
import { openSettingsDialog } from '@/stores/settings'
|
||||||
|
|
||||||
export const SettingsMenuItem = () => {
|
export const SettingsMenuItem = () => {
|
||||||
const { t } = useTranslation('rooms', { keyPrefix: 'options.items' })
|
const { t } = useTranslation('rooms', { keyPrefix: 'options.items' })
|
||||||
const { openSettingsDialog } = useSettingsDialog()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { CameraSwitchButton } from '../../components/controls/CameraSwitchButton
|
|||||||
import { useConfig } from '@/api/useConfig'
|
import { useConfig } from '@/api/useConfig'
|
||||||
import { AudioDevicesControl } from '../../components/controls/Device/AudioDevicesControl'
|
import { AudioDevicesControl } from '../../components/controls/Device/AudioDevicesControl'
|
||||||
import { VideoDeviceControl } from '../../components/controls/Device/VideoDeviceControl'
|
import { VideoDeviceControl } from '../../components/controls/Device/VideoDeviceControl'
|
||||||
import { useSettingsDialog } from '@/features/settings/hook/useSettingsDialog'
|
import { openSettingsDialog } from '@/stores/settings'
|
||||||
import { ControlBarRegion } from '@/features/layout/components/ControlBarRegion'
|
import { ControlBarRegion } from '@/features/layout/components/ControlBarRegion'
|
||||||
import { ReactionsToggle } from '@/features/reactions/components/ReactionsToggle'
|
import { ReactionsToggle } from '@/features/reactions/components/ReactionsToggle'
|
||||||
|
|
||||||
@@ -35,7 +35,6 @@ export function MobileControlBar({
|
|||||||
const [isMenuOpened, setIsMenuOpened] = React.useState(false)
|
const [isMenuOpened, setIsMenuOpened] = React.useState(false)
|
||||||
const browserSupportsScreenSharing = supportsScreenSharing()
|
const browserSupportsScreenSharing = supportsScreenSharing()
|
||||||
const { toggleEffects } = useSidePanel()
|
const { toggleEffects } = useSidePanel()
|
||||||
const { openSettingsDialog } = useSettingsDialog()
|
|
||||||
|
|
||||||
const { data } = useConfig()
|
const { data } = useConfig()
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { SettingsDialogExtended } from './SettingsDialogExtended'
|
import { SettingsDialogExtended } from './SettingsDialogExtended'
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSnapshot } from 'valtio'
|
||||||
import { settingsStore } from '@/stores/settings'
|
import { settingsStore, toggleSettingsDialog } from '@/stores/settings'
|
||||||
import {
|
import {
|
||||||
SettingsDialogExtendedKey,
|
SettingsDialogExtendedKey,
|
||||||
useSettingsDialog,
|
|
||||||
} from '@/features/settings'
|
} from '@/features/settings'
|
||||||
import { useRegisterKeyboardShortcut } from '@/features/shortcuts/useRegisterKeyboardShortcut'
|
import { useRegisterKeyboardShortcut } from '@/features/shortcuts/useRegisterKeyboardShortcut'
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
@@ -11,13 +10,11 @@ import { useCallback } from 'react'
|
|||||||
export const SettingsDialogProvider = () => {
|
export const SettingsDialogProvider = () => {
|
||||||
const { areSettingsOpen, defaultSelectedTab } = useSnapshot(settingsStore)
|
const { areSettingsOpen, defaultSelectedTab } = useSnapshot(settingsStore)
|
||||||
|
|
||||||
const { toggleSettingsDialog } = useSettingsDialog()
|
|
||||||
|
|
||||||
useRegisterKeyboardShortcut({
|
useRegisterKeyboardShortcut({
|
||||||
id: 'open-shortcuts',
|
id: 'open-shortcuts',
|
||||||
handler: useCallback(() => {
|
handler: useCallback(() => {
|
||||||
toggleSettingsDialog(SettingsDialogExtendedKey.SHORTCUTS)
|
toggleSettingsDialog(SettingsDialogExtendedKey.SHORTCUTS)
|
||||||
}, [toggleSettingsDialog]),
|
}, []),
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { useSnapshot } from 'valtio'
|
|
||||||
import { settingsStore } from '@/stores/settings'
|
|
||||||
import type { SettingsDialogExtendedKey } from '@/features/settings/type'
|
|
||||||
|
|
||||||
export const useSettingsDialog = () => {
|
|
||||||
const { areSettingsOpen } = useSnapshot(settingsStore)
|
|
||||||
|
|
||||||
const openSettingsDialog = (
|
|
||||||
defaultSelectedTab?: SettingsDialogExtendedKey
|
|
||||||
) => {
|
|
||||||
if (areSettingsOpen) return
|
|
||||||
if (defaultSelectedTab)
|
|
||||||
settingsStore.defaultSelectedTab = defaultSelectedTab
|
|
||||||
settingsStore.areSettingsOpen = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const closeSettingsDialog = () => {
|
|
||||||
settingsStore.areSettingsOpen = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleSettingsDialog = (
|
|
||||||
defaultSelectedTab?: SettingsDialogExtendedKey
|
|
||||||
) => {
|
|
||||||
if (areSettingsOpen) {
|
|
||||||
closeSettingsDialog()
|
|
||||||
} else {
|
|
||||||
if (defaultSelectedTab)
|
|
||||||
settingsStore.defaultSelectedTab = defaultSelectedTab
|
|
||||||
settingsStore.areSettingsOpen = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
openSettingsDialog,
|
|
||||||
closeSettingsDialog,
|
|
||||||
toggleSettingsDialog,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,5 @@ export { SettingsButton } from './components/SettingsButton'
|
|||||||
export { SettingsDialog } from './components/SettingsDialog'
|
export { SettingsDialog } from './components/SettingsDialog'
|
||||||
|
|
||||||
export { useTranscriptionLanguage } from './hook/useTranscriptionLanguage'
|
export { useTranscriptionLanguage } from './hook/useTranscriptionLanguage'
|
||||||
export { useSettingsDialog } from './hook/useSettingsDialog'
|
|
||||||
|
|
||||||
export { SettingsDialogExtendedKey } from './type.ts'
|
export { SettingsDialogExtendedKey } from './type.ts'
|
||||||
|
|||||||
@@ -10,3 +10,25 @@ export const settingsStore = proxy<State>({
|
|||||||
areSettingsOpen: false,
|
areSettingsOpen: false,
|
||||||
defaultSelectedTab: undefined,
|
defaultSelectedTab: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const openSettingsDialog = (
|
||||||
|
defaultSelectedTab?: SettingsDialogExtendedKey
|
||||||
|
) => {
|
||||||
|
if (settingsStore.areSettingsOpen) return
|
||||||
|
if (defaultSelectedTab) settingsStore.defaultSelectedTab = defaultSelectedTab
|
||||||
|
settingsStore.areSettingsOpen = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export const closeSettingsDialog = () => {
|
||||||
|
settingsStore.areSettingsOpen = false
|
||||||
|
}
|
||||||
|
|
||||||
|
export const toggleSettingsDialog = (
|
||||||
|
defaultSelectedTab?: SettingsDialogExtendedKey
|
||||||
|
) => {
|
||||||
|
if (settingsStore.areSettingsOpen) {
|
||||||
|
closeSettingsDialog()
|
||||||
|
} else {
|
||||||
|
openSettingsDialog(defaultSelectedTab)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user