|
|
@@ -23,6 +23,7 @@ import { debugConsole } from '@/utils/debugging'
|
|
|
import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view'
|
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
|
|
import { FileRef } from '../../../../../types/file-ref'
|
|
|
+import useEventListener from '@/shared/hooks/use-event-listener'
|
|
|
|
|
|
const FileTreeOpenContext = createContext<
|
|
|
| {
|
|
|
@@ -113,21 +114,19 @@ export const FileTreeOpenProvider: FC = ({ children }) => {
|
|
|
[eventEmitter, openDocId, openDocWithId, rootDocId]
|
|
|
)
|
|
|
|
|
|
- const openDocIdRef = useRef<typeof openDocId | null>(null)
|
|
|
-
|
|
|
// Synchronize the file tree when openDoc or openDocId is called on the editor
|
|
|
// manager context from elsewhere. If the file tree does change, it will
|
|
|
// trigger the onSelect handler in this component, which will update the local
|
|
|
// state.
|
|
|
- useEffect(() => {
|
|
|
- if (openDocId !== openDocIdRef.current) {
|
|
|
- debugConsole.log(`openDocId changed to ${openDocId}`)
|
|
|
- openDocIdRef.current = openDocId
|
|
|
- if (openDocId !== null) {
|
|
|
- selectEntity(openDocId)
|
|
|
- }
|
|
|
- }
|
|
|
- }, [openDocId, selectEntity])
|
|
|
+ useEventListener(
|
|
|
+ 'doc:after-opened',
|
|
|
+ useCallback(
|
|
|
+ (event: CustomEvent<{ docId: string }>) => {
|
|
|
+ selectEntity(event.detail.docId)
|
|
|
+ },
|
|
|
+ [selectEntity]
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
// Open a document once the file tree and project are ready
|
|
|
const initialOpenDoneRef = useRef(false)
|