mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #31957 from overleaf/ds-removing-useIsNewEditorEnabled-5
[Part 5] Removing the usage of `useIsNewEditorEnabled` for editor tear down GitOrigin-RevId: 086183b196a44b393dc0c0f60f7bfbc5738901fc
This commit is contained in:
@@ -1,49 +1,21 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import MaterialIcon from '@/shared/components/material-icon'
|
import MaterialIcon from '@/shared/components/material-icon'
|
||||||
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
||||||
|
|
||||||
function FileTreeFolderIcons({
|
function FileTreeFolderIcons({ expanded }: { expanded: boolean }) {
|
||||||
expanded,
|
|
||||||
onExpandCollapseClick,
|
|
||||||
}: {
|
|
||||||
expanded: boolean
|
|
||||||
onExpandCollapseClick?: () => void
|
|
||||||
}) {
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const newEditor = useIsNewEditorEnabled()
|
|
||||||
|
|
||||||
if (newEditor) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div
|
|
||||||
// TODO ide-redesign-cleanup: rename the class now its no longer a button
|
|
||||||
className="folder-expand-collapse-button"
|
|
||||||
aria-label={expanded ? t('collapse') : t('expand')}
|
|
||||||
>
|
|
||||||
<MaterialIcon
|
|
||||||
type={expanded ? 'expand_more' : 'chevron_right'}
|
|
||||||
className="file-tree-expand-icon"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<button
|
<div
|
||||||
onClick={onExpandCollapseClick}
|
// TODO ide-redesign-cleanup: rename the class now its no longer a button
|
||||||
|
className="folder-expand-collapse-button"
|
||||||
aria-label={expanded ? t('collapse') : t('expand')}
|
aria-label={expanded ? t('collapse') : t('expand')}
|
||||||
>
|
>
|
||||||
<MaterialIcon
|
<MaterialIcon
|
||||||
type={expanded ? 'expand_more' : 'chevron_right'}
|
type={expanded ? 'expand_more' : 'chevron_right'}
|
||||||
className="file-tree-expand-icon"
|
className="file-tree-expand-icon"
|
||||||
/>
|
/>
|
||||||
</button>
|
</div>
|
||||||
<MaterialIcon
|
|
||||||
type={expanded ? 'folder_open' : 'folder'}
|
|
||||||
className="file-tree-folder-icon"
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { Folder } from '../../../../../types/folder'
|
|||||||
import { Doc } from '../../../../../types/doc'
|
import { Doc } from '../../../../../types/doc'
|
||||||
import { FileRef } from '../../../../../types/file-ref'
|
import { FileRef } from '../../../../../types/file-ref'
|
||||||
import FileTreeFolderIcons from './file-tree-folder-icons'
|
import FileTreeFolderIcons from './file-tree-folder-icons'
|
||||||
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
||||||
|
|
||||||
function FileTreeFolder({
|
function FileTreeFolder({
|
||||||
name,
|
name,
|
||||||
@@ -29,7 +28,6 @@ function FileTreeFolder({
|
|||||||
docs: Doc[]
|
docs: Doc[]
|
||||||
files: FileRef[]
|
files: FileRef[]
|
||||||
}) {
|
}) {
|
||||||
const newEditor = useIsNewEditorEnabled()
|
|
||||||
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
||||||
id,
|
id,
|
||||||
'folder'
|
'folder'
|
||||||
@@ -53,10 +51,8 @@ function FileTreeFolder({
|
|||||||
}, [setExpanded])
|
}, [setExpanded])
|
||||||
|
|
||||||
const onClick = useCallback(() => {
|
const onClick = useCallback(() => {
|
||||||
if (newEditor) {
|
handleExpandCollapseClick()
|
||||||
handleExpandCollapseClick()
|
}, [handleExpandCollapseClick])
|
||||||
}
|
|
||||||
}, [newEditor, handleExpandCollapseClick])
|
|
||||||
|
|
||||||
const { isOver: isOverRoot, dropRef: dropRefRoot } = useDroppable(id)
|
const { isOver: isOverRoot, dropRef: dropRefRoot } = useDroppable(id)
|
||||||
const { isOver: isOverList, dropRef: dropRefList } = useDroppable(id)
|
const { isOver: isOverList, dropRef: dropRefList } = useDroppable(id)
|
||||||
@@ -82,12 +78,7 @@ function FileTreeFolder({
|
|||||||
type="folder"
|
type="folder"
|
||||||
isSelected={isSelected}
|
isSelected={isSelected}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
icons={
|
icons={<FileTreeFolderIcons expanded={expanded} />}
|
||||||
<FileTreeFolderIcons
|
|
||||||
expanded={expanded}
|
|
||||||
onExpandCollapseClick={handleExpandCollapseClick}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
{expanded ? (
|
{expanded ? (
|
||||||
|
|||||||
+5
-51
@@ -1,7 +1,6 @@
|
|||||||
import { useState, useEffect, RefObject } from 'react'
|
import { useState, useEffect, RefObject } from 'react'
|
||||||
import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
|
import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
|
||||||
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
||||||
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
||||||
|
|
||||||
function FileTreeItemName({
|
function FileTreeItemName({
|
||||||
name,
|
name,
|
||||||
@@ -12,8 +11,7 @@ function FileTreeItemName({
|
|||||||
isSelected: boolean
|
isSelected: boolean
|
||||||
setIsDraggable: (isDraggable: boolean) => void
|
setIsDraggable: (isDraggable: boolean) => void
|
||||||
}) {
|
}) {
|
||||||
const { isRenaming, startRenaming, finishRenaming, error, cancel } =
|
const { isRenaming, finishRenaming, error, cancel } = useFileTreeActionable()
|
||||||
useFileTreeActionable()
|
|
||||||
|
|
||||||
const isRenamingEntity = isRenaming && isSelected && !error
|
const isRenamingEntity = isRenaming && isSelected && !error
|
||||||
|
|
||||||
@@ -30,58 +28,14 @@ function FileTreeItemName({
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return <DisplayName name={name} />
|
||||||
<DisplayName
|
|
||||||
name={name}
|
|
||||||
isSelected={isSelected}
|
|
||||||
startRenaming={startRenaming}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function DisplayName({
|
function DisplayName({ name }: { name: string }) {
|
||||||
name,
|
|
||||||
isSelected,
|
|
||||||
startRenaming,
|
|
||||||
}: {
|
|
||||||
name: string
|
|
||||||
isSelected: boolean
|
|
||||||
startRenaming: () => void
|
|
||||||
}) {
|
|
||||||
const [clicksInSelectedCount, setClicksInSelectedCount] = useState(0)
|
|
||||||
const newEditor = useIsNewEditorEnabled()
|
|
||||||
|
|
||||||
function onClick() {
|
|
||||||
setClicksInSelectedCount(clicksInSelectedCount + 1)
|
|
||||||
if (!isSelected) setClicksInSelectedCount(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDoubleClick() {
|
|
||||||
// only start renaming if the button got two or more clicks while the item
|
|
||||||
// was selected. This is to prevent starting a rename on an unselected item.
|
|
||||||
// When the item is being selected it can trigger a loss of focus which
|
|
||||||
// causes UI problems.
|
|
||||||
if (clicksInSelectedCount < 2) return
|
|
||||||
startRenaming()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEditor) {
|
|
||||||
return (
|
|
||||||
// TODO ide-redesign-cleanup: rename the class now its no longer a button
|
|
||||||
<div className="item-name-button">
|
|
||||||
<span>{name}</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<div className="item-name">
|
||||||
className="item-name-button"
|
|
||||||
onClick={onClick}
|
|
||||||
onDoubleClick={onDoubleClick}
|
|
||||||
>
|
|
||||||
<span>{name}</span>
|
<span>{name}</span>
|
||||||
</button>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { debugConsole } from '@/utils/debugging'
|
|||||||
import { useCallback, useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef } from 'react'
|
||||||
import useEventListener from '@/shared/hooks/use-event-listener'
|
import useEventListener from '@/shared/hooks/use-event-listener'
|
||||||
import useDomEventListener from '@/shared/hooks/use-dom-event-listener'
|
import useDomEventListener from '@/shared/hooks/use-dom-event-listener'
|
||||||
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
||||||
import {
|
import {
|
||||||
IdeLayout,
|
IdeLayout,
|
||||||
IdeView,
|
IdeView,
|
||||||
@@ -19,17 +18,15 @@ import {
|
|||||||
|
|
||||||
function createEditingSessionHeartbeatData(
|
function createEditingSessionHeartbeatData(
|
||||||
editorType: EditorType,
|
editorType: EditorType,
|
||||||
newEditor: boolean,
|
|
||||||
view: IdeView | null,
|
view: IdeView | null,
|
||||||
layout: IdeLayout,
|
layout: IdeLayout,
|
||||||
railOpen: boolean,
|
railOpen: boolean,
|
||||||
railTab: RailTabKey,
|
railTab: RailTabKey,
|
||||||
hasDetachedPdf: boolean
|
hasDetachedPdf: boolean
|
||||||
) {
|
) {
|
||||||
const newEditorSegmentation = newEditor ? { railOpen, railTab } : {}
|
const newEditorSegmentation = { railOpen, railTab }
|
||||||
return {
|
return {
|
||||||
editorType,
|
editorType,
|
||||||
editorRedesign: newEditor,
|
|
||||||
editorView: view,
|
editorView: view,
|
||||||
editorLayout: layout,
|
editorLayout: layout,
|
||||||
hasDetachedPdf,
|
hasDetachedPdf,
|
||||||
@@ -49,7 +46,6 @@ function sendEditingSessionHeartbeat(
|
|||||||
export function useEditingSessionHeartbeat() {
|
export function useEditingSessionHeartbeat() {
|
||||||
const { projectId } = useIdeReactContext()
|
const { projectId } = useIdeReactContext()
|
||||||
const { getEditorType } = useEditorManagerContext()
|
const { getEditorType } = useEditorManagerContext()
|
||||||
const newEditor = useIsNewEditorEnabled()
|
|
||||||
const { view, pdfLayout: layout, detachIsLinked } = useLayoutContext()
|
const { view, pdfLayout: layout, detachIsLinked } = useLayoutContext()
|
||||||
const { isOpen: railIsOpen, selectedTab: selectedRailTab } = useRailContext()
|
const { isOpen: railIsOpen, selectedTab: selectedRailTab } = useRailContext()
|
||||||
|
|
||||||
@@ -80,7 +76,6 @@ export function useEditingSessionHeartbeat() {
|
|||||||
|
|
||||||
const segmentation = createEditingSessionHeartbeatData(
|
const segmentation = createEditingSessionHeartbeatData(
|
||||||
editorType,
|
editorType,
|
||||||
newEditor,
|
|
||||||
view,
|
view,
|
||||||
layout,
|
layout,
|
||||||
railIsOpen,
|
railIsOpen,
|
||||||
@@ -109,7 +104,6 @@ export function useEditingSessionHeartbeat() {
|
|||||||
}, [
|
}, [
|
||||||
getEditorType,
|
getEditorType,
|
||||||
projectId,
|
projectId,
|
||||||
newEditor,
|
|
||||||
view,
|
view,
|
||||||
layout,
|
layout,
|
||||||
railIsOpen,
|
railIsOpen,
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
|
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
|
||||||
|
|
||||||
export const canUseNewEditor = () => {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useIsNewEditorEnabled = () => {
|
|
||||||
return canUseNewEditor()
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useIsNewToNewEditor = () => {
|
export const useIsNewToNewEditor = () => {
|
||||||
const { userSettings } = useUserSettingsContext()
|
const { userSettings } = useUserSettingsContext()
|
||||||
const newEditor = useIsNewEditorEnabled()
|
return !userSettings.enableNewEditorLegacy
|
||||||
|
|
||||||
return newEditor && !userSettings.enableNewEditorLegacy
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { ScopeEventEmitter } from '../../../../types/ide/scope-event-emitter'
|
|||||||
import { Socket } from '@/features/ide-react/connection/types/socket'
|
import { Socket } from '@/features/ide-react/connection/types/socket'
|
||||||
import { useUserSettingsContext } from './user-settings-context'
|
import { useUserSettingsContext } from './user-settings-context'
|
||||||
import { userStyles } from '../utils/styles'
|
import { userStyles } from '../utils/styles'
|
||||||
import { canUseNewEditor } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
||||||
import { useActiveOverallTheme } from '../hooks/use-active-overall-theme'
|
import { useActiveOverallTheme } from '../hooks/use-active-overall-theme'
|
||||||
|
|
||||||
export type Ide = {
|
export type Ide = {
|
||||||
@@ -59,7 +58,7 @@ export const IdeProvider: FC<
|
|||||||
fontFamily,
|
fontFamily,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
fontSize: userSettings.fontSize,
|
fontSize: userSettings.fontSize,
|
||||||
isNewEditor: canUseNewEditor() && userSettings.enableNewEditor,
|
isNewEditor: true,
|
||||||
})
|
})
|
||||||
}, [unstableStore, userSettings, activeOverallTheme])
|
}, [unstableStore, userSettings, activeOverallTheme])
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,7 @@
|
|||||||
gap: var(--spacing-02);
|
gap: var(--spacing-02);
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-name-button,
|
.item-name,
|
||||||
.folder-expand-collapse-button {
|
.folder-expand-collapse-button {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -183,7 +183,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-name-button {
|
.item-name {
|
||||||
margin-left: var(--spacing-02);
|
margin-left: var(--spacing-02);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
@@ -352,7 +352,7 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
&.item-name-button {
|
&.item-name {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -423,11 +423,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.file-tree-folder-icon {
|
|
||||||
margin-right: var(--spacing-02);
|
|
||||||
vertical-align: sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.file-tree-expand-icon {
|
&.file-tree-expand-icon {
|
||||||
margin-left: var(--spacing-04);
|
margin-left: var(--spacing-04);
|
||||||
vertical-align: sub;
|
vertical-align: sub;
|
||||||
|
|||||||
@@ -610,11 +610,6 @@ history-root {
|
|||||||
margin-left: var(--spacing-04);
|
margin-left: var(--spacing-04);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.file-tree-folder-icon {
|
|
||||||
margin-right: var(--spacing-02);
|
|
||||||
vertical-align: sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.file-tree-expand-icon {
|
&.file-tree-expand-icon {
|
||||||
margin-left: var(--spacing-04);
|
margin-left: var(--spacing-04);
|
||||||
vertical-align: sub;
|
vertical-align: sub;
|
||||||
|
|||||||
Reference in New Issue
Block a user