diff --git a/services/web/frontend/js/features/chat/context/chat-context.tsx b/services/web/frontend/js/features/chat/context/chat-context.tsx index e6d93f1d64..89c464737e 100644 --- a/services/web/frontend/js/features/chat/context/chat-context.tsx +++ b/services/web/frontend/js/features/chat/context/chat-context.tsx @@ -176,7 +176,10 @@ export const ChatContext = createContext< >(undefined) export const ChatProvider: FC = ({ children }) => { - const clientId = useRef(uuid()) + const clientId = useRef() + if (clientId.current === undefined) { + clientId.current = uuid() + } const user = useUserContext() const { _id: projectId } = useProjectContext() diff --git a/services/web/frontend/js/features/ide-react/components/file-tree.tsx b/services/web/frontend/js/features/ide-react/components/file-tree.tsx index 44cd86d3d2..b6f26eb86b 100644 --- a/services/web/frontend/js/features/ide-react/components/file-tree.tsx +++ b/services/web/frontend/js/features/ide-react/components/file-tree.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from 'react' +import React, { memo, useCallback, useState } from 'react' import { useUserContext } from '@/shared/context/user-context' import { useReferencesContext } from '@/features/ide-react/context/references-context' import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context' @@ -7,7 +7,7 @@ import { RefProviders } from '../../../../../types/user' import FileTreeRoot from '@/features/file-tree/components/file-tree-root' import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context' -export function FileTree() { +export const FileTree = memo(function FileTree() { const user = useUserContext() const { indexAllReferences } = useReferencesContext() const { setStartedFreeTrial } = useIdeReactContext() @@ -44,4 +44,4 @@ export function FileTree() { /> ) -} +}) diff --git a/services/web/frontend/js/features/outline/components/outline-item-toggle-button.tsx b/services/web/frontend/js/features/outline/components/outline-item-toggle-button.tsx new file mode 100644 index 0000000000..e2e8ff063a --- /dev/null +++ b/services/web/frontend/js/features/outline/components/outline-item-toggle-button.tsx @@ -0,0 +1,24 @@ +import { memo, type Dispatch, type SetStateAction } from 'react' +import Icon from '@/shared/components/icon' +import { useTranslation } from 'react-i18next' + +export const OutlineItemToggleButton = memo<{ + expanded: boolean + setExpanded: Dispatch> +}>(({ expanded, setExpanded }) => { + const { t } = useTranslation() + + return ( + + ) +}) +OutlineItemToggleButton.displayName = 'OutlineItemToggleButton' diff --git a/services/web/frontend/js/features/outline/components/outline-item.jsx b/services/web/frontend/js/features/outline/components/outline-item.jsx index 1cf7840d04..7b7c51e5e7 100644 --- a/services/web/frontend/js/features/outline/components/outline-item.jsx +++ b/services/web/frontend/js/features/outline/components/outline-item.jsx @@ -2,9 +2,8 @@ import { useState, useEffect, useRef, memo } from 'react' import PropTypes from 'prop-types' import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed' import classNames from 'classnames' -import { useTranslation } from 'react-i18next' import OutlineList from './outline-list' -import Icon from '../../../shared/components/icon' +import { OutlineItemToggleButton } from '@/features/outline/components/outline-item-toggle-button' const OutlineItem = memo(function OutlineItem({ outlineItem, @@ -13,8 +12,6 @@ const OutlineItem = memo(function OutlineItem({ matchesHighlightedLine, containsHighlightedLine, }) { - const { t } = useTranslation() - const [expanded, setExpanded] = useState(true) const titleElementRef = useRef() const isHighlightedRef = useRef(false) @@ -30,10 +27,6 @@ const OutlineItem = memo(function OutlineItem({ 'outline-item-link-highlight': isHighlighted, }) - function handleExpandCollapseClick() { - setExpanded(!expanded) - } - function handleOutlineItemLinkClick(event) { const syncToPdf = event.detail === 2 // double-click = sync to PDF jumpToLine(outlineItem.line, syncToPdf) @@ -65,18 +58,12 @@ const OutlineItem = memo(function OutlineItem({ aria-label={outlineItem.title} >
- {outlineItem.children ? ( - - ) : null} + {!!outlineItem.children && ( + + )} + {isOpen && (
diff --git a/services/web/frontend/js/features/outline/components/outline-toggle-button.tsx b/services/web/frontend/js/features/outline/components/outline-toggle-button.tsx new file mode 100644 index 0000000000..66f145cc31 --- /dev/null +++ b/services/web/frontend/js/features/outline/components/outline-toggle-button.tsx @@ -0,0 +1,44 @@ +import Icon from '@/shared/components/icon' +import Tooltip from '@/shared/components/tooltip' +import React, { memo } from 'react' +import { useTranslation } from 'react-i18next' + +export const OutlineToggleButton = memo<{ + isTexFile: boolean + toggleExpanded: () => void + expanded?: boolean + isOpen: boolean + isPartial: boolean +}>(({ isTexFile, toggleExpanded, expanded, isOpen, isPartial }) => { + const { t } = useTranslation() + + return ( + + ) +}) +OutlineToggleButton.displayName = 'OutlineToggleButton' diff --git a/services/web/frontend/js/shared/context/user-context.tsx b/services/web/frontend/js/shared/context/user-context.tsx index df6888e206..9ea7e8daa8 100644 --- a/services/web/frontend/js/shared/context/user-context.tsx +++ b/services/web/frontend/js/shared/context/user-context.tsx @@ -1,11 +1,11 @@ -import { createContext, FC, useContext } from 'react' +import { createContext, FC, useContext, useMemo } from 'react' import getMeta from '../../utils/meta' import { User } from '../../../../types/user' export const UserContext = createContext(undefined) export const UserProvider: FC = ({ children }) => { - const user = getMeta('ol-user') + const user = useMemo(() => getMeta('ol-user'), []) return {children} } diff --git a/services/web/frontend/js/shared/hooks/use-browser-window.ts b/services/web/frontend/js/shared/hooks/use-browser-window.ts index 47a8965e4f..58e3975b4b 100644 --- a/services/web/frontend/js/shared/hooks/use-browser-window.ts +++ b/services/web/frontend/js/shared/hooks/use-browser-window.ts @@ -43,7 +43,7 @@ function setTitle(title: string) { } function useBrowserWindow() { - const [hasFocus, setHasFocus] = useState(document.hasFocus()) + const [hasFocus, setHasFocus] = useState(() => document.hasFocus()) useEffect(() => { function handleFocusEvent() {