mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
[web] Move UI scope to React states (#26403)
* Move `ui.view` to setState
* Move `openFile` to setState
* Move `ui.leftMenuShown` to setState
* Move `ui.miniReviewPanelVisible` to setState
* Move `ui.pdfLayout` to setState
* Move `ui.chatOpen` to setState
* Move `ui.reviewPanelOpen` to setState
* Cleanup: remove layout-context-adapter and imports
* Replace `ui` scope by mocked `LayoutProvider` in tests
* Update test
* Remove unnecessary `scopeStore.set('ui.chatOpen' ...`
GitOrigin-RevId: 81578bfdc958239eac492905f714a6074c81d0f5
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
||||
FC,
|
||||
useState,
|
||||
} from 'react'
|
||||
import useScopeValue from '../hooks/use-scope-value'
|
||||
import useDetachLayout from '../hooks/use-detach-layout'
|
||||
import localStorage from '../../infrastructure/local-storage'
|
||||
import getMeta from '../../utils/meta'
|
||||
@@ -21,6 +20,7 @@ import useEventListener from '@/shared/hooks/use-event-listener'
|
||||
import { isMac } from '@/shared/utils/os'
|
||||
import { sendSearchEvent } from '@/features/event-tracking/search-events'
|
||||
import { useRailContext } from '@/features/ide-redesign/contexts/rail-context'
|
||||
import usePersistedState from '@/shared/hooks/use-persisted-state'
|
||||
|
||||
export type IdeLayout = 'sideBySide' | 'flat'
|
||||
export type IdeView = 'editor' | 'file' | 'pdf' | 'history'
|
||||
@@ -55,6 +55,8 @@ export type LayoutContextValue = {
|
||||
pdfPreviewOpen: boolean
|
||||
projectSearchIsOpen: boolean
|
||||
setProjectSearchIsOpen: Dispatch<SetStateAction<boolean>>
|
||||
openFile: BinaryFile | null
|
||||
setOpenFile: Dispatch<SetStateAction<BinaryFile | null>>
|
||||
}
|
||||
|
||||
const debugPdfDetach = getMeta('ol-debugPdfDetach')
|
||||
@@ -70,10 +72,12 @@ function setLayoutInLocalStorage(pdfLayout: IdeLayout) {
|
||||
)
|
||||
}
|
||||
|
||||
const reviewPanelStorageKey = `ui.reviewPanelOpen.${getMeta('ol-project_id')}`
|
||||
|
||||
export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
// what to show in the "flat" view (editor or pdf)
|
||||
const [view, _setView] = useScopeValue<IdeView | null>('ui.view')
|
||||
const [openFile] = useScopeValue<BinaryFile | null>('openFile')
|
||||
const [view, _setView] = useState<IdeView | null>('editor')
|
||||
const [openFile, setOpenFile] = useState<BinaryFile | null>(null)
|
||||
const historyToggleEmitter = useScopeEventEmitter('history:toggle', true)
|
||||
const { isOpen: railIsOpen, setIsOpen: setRailIsOpen } = useRailContext()
|
||||
const [prevRailIsOpen, setPrevRailIsOpen] = useState(railIsOpen)
|
||||
@@ -118,19 +122,23 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
)
|
||||
|
||||
// whether the chat pane is open
|
||||
const [chatIsOpen, setChatIsOpen] = useScopeValue<boolean>('ui.chatOpen')
|
||||
const [chatIsOpen, setChatIsOpen] = usePersistedState<boolean>(
|
||||
'ui.chatOpen',
|
||||
false
|
||||
)
|
||||
|
||||
// whether the review pane is open
|
||||
const [reviewPanelOpen, setReviewPanelOpen] =
|
||||
useScopeValue<boolean>('ui.reviewPanelOpen')
|
||||
const [reviewPanelOpen, setReviewPanelOpen] = usePersistedState<boolean>(
|
||||
reviewPanelStorageKey,
|
||||
false
|
||||
)
|
||||
|
||||
// whether the review pane is collapsed
|
||||
const [miniReviewPanelVisible, setMiniReviewPanelVisible] =
|
||||
useScopeValue<boolean>('ui.miniReviewPanelVisible')
|
||||
useState<boolean>(false)
|
||||
|
||||
// whether the menu pane is open
|
||||
const [leftMenuShown, setLeftMenuShown] =
|
||||
useScopeValue<boolean>('ui.leftMenuShown')
|
||||
const [leftMenuShown, setLeftMenuShown] = useState<boolean>(false)
|
||||
|
||||
// whether the project search is open
|
||||
const [projectSearchIsOpen, setProjectSearchIsOpen] = useState(false)
|
||||
@@ -173,7 +181,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
)
|
||||
|
||||
// whether to display the editor and preview side-by-side or full-width ("flat")
|
||||
const [pdfLayout, setPdfLayout] = useScopeValue<IdeLayout>('ui.pdfLayout')
|
||||
const [pdfLayout, setPdfLayout] = useState<IdeLayout>('sideBySide')
|
||||
|
||||
// whether stylesheet on theme is loading
|
||||
const [loadingStyleSheet, setLoadingStyleSheet] = useState(false)
|
||||
@@ -238,6 +246,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
changeLayout,
|
||||
chatIsOpen,
|
||||
leftMenuShown,
|
||||
openFile,
|
||||
pdfLayout,
|
||||
pdfPreviewOpen,
|
||||
projectSearchIsOpen,
|
||||
@@ -247,6 +256,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
loadingStyleSheet,
|
||||
setChatIsOpen,
|
||||
setLeftMenuShown,
|
||||
setOpenFile,
|
||||
setPdfLayout,
|
||||
setReviewPanelOpen,
|
||||
setMiniReviewPanelVisible,
|
||||
@@ -262,6 +272,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
changeLayout,
|
||||
chatIsOpen,
|
||||
leftMenuShown,
|
||||
openFile,
|
||||
pdfLayout,
|
||||
pdfPreviewOpen,
|
||||
projectSearchIsOpen,
|
||||
@@ -271,6 +282,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
||||
loadingStyleSheet,
|
||||
setChatIsOpen,
|
||||
setLeftMenuShown,
|
||||
setOpenFile,
|
||||
setPdfLayout,
|
||||
setReviewPanelOpen,
|
||||
setMiniReviewPanelVisible,
|
||||
|
||||
Reference in New Issue
Block a user