mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
[workbench] Improve asynchronous tool use (#30184)
GitOrigin-RevId: d1bd33469b557c29968049af99b9c3c85731151d
This commit is contained in:
+6
-3
@@ -20,7 +20,10 @@ const EditorNavigationToolbarRoot = React.memo(
|
||||
openShareProjectModal,
|
||||
}: {
|
||||
onlineUsersArray: OnlineUser[]
|
||||
openDoc: (doc: Doc, { gotoLine }: { gotoLine: number }) => void
|
||||
openDoc: (
|
||||
doc: Doc,
|
||||
{ gotoLine }: { gotoLine: number }
|
||||
) => Promise<Doc | undefined>
|
||||
openShareProjectModal: () => void
|
||||
}) {
|
||||
const {
|
||||
@@ -93,9 +96,9 @@ const EditorNavigationToolbarRoot = React.memo(
|
||||
}, [setLeftMenuShown])
|
||||
|
||||
const goToUser = useCallback(
|
||||
(user: OnlineUser) => {
|
||||
async (user: OnlineUser) => {
|
||||
if (user.doc && typeof user.row === 'number') {
|
||||
openDoc(user.doc, { gotoLine: user.row + 1 })
|
||||
return await openDoc(user.doc, { gotoLine: user.row + 1 })
|
||||
}
|
||||
},
|
||||
[openDoc]
|
||||
|
||||
+2
-1
@@ -11,13 +11,14 @@ import { getBackgroundColorForUserId } from '@/shared/utils/colors'
|
||||
import OLTooltip from '@/shared/components/ol/ol-tooltip'
|
||||
import MaterialIcon from '@/shared/components/material-icon'
|
||||
import { OnlineUser } from '@/features/ide-react/context/online-users-context'
|
||||
import { Doc } from '@ol-types/doc'
|
||||
|
||||
function OnlineUsersWidget({
|
||||
onlineUsers,
|
||||
goToUser,
|
||||
}: {
|
||||
onlineUsers: OnlineUser[]
|
||||
goToUser: (user: OnlineUser) => void
|
||||
goToUser: (user: OnlineUser) => Promise<Doc | undefined>
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ import TryNewEditorButton from '../try-new-editor-button'
|
||||
import { OnlineUser } from '@/features/ide-react/context/online-users-context'
|
||||
import { Cobranding } from '../../../../../types/cobranding'
|
||||
import { canUseNewEditor } from '@/features/ide-redesign/utils/new-editor-utils'
|
||||
import { Doc } from '@ol-types/doc'
|
||||
|
||||
const [publishModalModules] = importOverleafModules('publishModal') as {
|
||||
import: { default: ElementType }
|
||||
@@ -50,7 +51,7 @@ export type ToolbarHeaderProps = {
|
||||
toggleHistoryOpen: () => void
|
||||
unreadMessageCount: number
|
||||
onlineUsers: OnlineUser[]
|
||||
goToUser: (user: OnlineUser) => void
|
||||
goToUser: (user: OnlineUser) => Promise<Doc | undefined>
|
||||
isRestrictedTokenMember: boolean | undefined
|
||||
hasPublishPermissions: boolean
|
||||
chatVisible: boolean
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ export default function FileTreeCreateNewDoc() {
|
||||
})
|
||||
|
||||
if (doc) {
|
||||
openDoc(doc)
|
||||
return await openDoc(doc)
|
||||
}
|
||||
},
|
||||
[finishCreatingDoc, name, openDoc]
|
||||
|
||||
@@ -54,11 +54,14 @@ export type EditorManager = {
|
||||
getCurrentDocValue: () => string | null
|
||||
getCurrentDocumentId: () => DocId | null
|
||||
setIgnoringExternalUpdates: (value: boolean) => void
|
||||
openDocWithId: (docId: string, options?: OpenDocOptions) => void
|
||||
openDocWithId: (
|
||||
docId: string,
|
||||
options?: OpenDocOptions
|
||||
) => Promise<Doc | undefined>
|
||||
openDoc: (document: Doc, options?: OpenDocOptions) => Promise<Doc | undefined>
|
||||
openDocs: OpenDocuments
|
||||
openFileWithId: (fileId: string) => void
|
||||
openInitialDoc: (docId?: string) => void
|
||||
openInitialDoc: (docId?: string) => Promise<Doc | undefined>
|
||||
isLoading: boolean
|
||||
jumpToLine: (options: GotoLineOptions) => void
|
||||
debugTimers: React.MutableRefObject<Record<string, number>>
|
||||
@@ -486,12 +489,12 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
||||
)
|
||||
|
||||
const openDocWithId = useCallback(
|
||||
(docId: string, options: OpenDocOptions = {}) => {
|
||||
async (docId: string, options: OpenDocOptions = {}) => {
|
||||
const doc = findDocEntityById(fileTreeData, docId)
|
||||
if (!doc) {
|
||||
return
|
||||
}
|
||||
openDoc(doc, options)
|
||||
return await openDoc(doc, options)
|
||||
},
|
||||
[fileTreeData, openDoc]
|
||||
)
|
||||
@@ -513,11 +516,11 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
||||
)
|
||||
|
||||
const openInitialDoc = useCallback(
|
||||
(fallbackDocId?: string) => {
|
||||
async (fallbackDocId?: string) => {
|
||||
const docId =
|
||||
customLocalStorage.getItem(currentDocumentIdStorageKey) || fallbackDocId
|
||||
if (docId) {
|
||||
openDocWithId(docId)
|
||||
return await openDocWithId(docId)
|
||||
}
|
||||
},
|
||||
[currentDocumentIdStorageKey, openDocWithId]
|
||||
@@ -580,7 +583,7 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
||||
}
|
||||
|
||||
const handleProjectJoined = () => {
|
||||
openDoc(doc, { forceReopen: true })
|
||||
return openDoc(doc, { forceReopen: true })
|
||||
}
|
||||
|
||||
eventEmitter.once('project:joined', handleProjectJoined)
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ import {
|
||||
import classNames from 'classnames'
|
||||
import { useCallback, useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Doc } from '@ol-types/doc'
|
||||
|
||||
// Should be kept in sync with $max-user-circles-displayed CSS constant
|
||||
const MAX_USER_CIRCLES_DISPLAYED = 5
|
||||
@@ -26,7 +27,7 @@ export const OnlineUsersWidget = ({
|
||||
goToUser,
|
||||
}: {
|
||||
onlineUsers: OnlineUser[]
|
||||
goToUser: (user: OnlineUser) => void
|
||||
goToUser: (user: OnlineUser) => Promise<Doc | undefined>
|
||||
}) => {
|
||||
const hasOverflow = onlineUsers.length > MAX_USER_CIRCLES_DISPLAYED
|
||||
const usersBeforeOverflow = useMemo(
|
||||
|
||||
@@ -11,9 +11,9 @@ export const OnlineUsers = () => {
|
||||
const { onlineUsersArray } = useOnlineUsersContext()
|
||||
|
||||
const goToUser = useCallback(
|
||||
(user: OnlineUser) => {
|
||||
async (user: OnlineUser) => {
|
||||
if (user.doc && typeof user.row === 'number') {
|
||||
openDoc(user.doc, { gotoLine: user.row + 1 })
|
||||
return await openDoc(user.doc, { gotoLine: user.row + 1 })
|
||||
}
|
||||
},
|
||||
[openDoc]
|
||||
|
||||
@@ -33,7 +33,7 @@ export const startCompileKeypress = (
|
||||
}
|
||||
|
||||
export default function useCompileTriggers(
|
||||
startCompile: (...args: any[]) => void,
|
||||
startCompile: (...args: any[]) => Promise<void>,
|
||||
setChangedAt: (...args: any[]) => void
|
||||
) {
|
||||
const handleKeyDown = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user