From 9e480e66d7fe61f2602909562223eed89ba677fc Mon Sep 17 00:00:00 2001 From: aliang <1098486429@qq.com> Date: Fri, 10 May 2024 03:48:29 +0800 Subject: [PATCH] fix(ui): display a skeleton after switching repositories (#2080) * fix(ui): display a skeleton after switching repositories * update skeleton * update * refactor: main panel skeleton * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../app/files/components/file-tree.tsx | 23 +++-- .../files/components/source-code-browser.tsx | 86 +++++++++++-------- 2 files changed, 67 insertions(+), 42 deletions(-) diff --git a/ee/tabby-ui/app/files/components/file-tree.tsx b/ee/tabby-ui/app/files/components/file-tree.tsx index 4d8f1379072a..64eda4c0684c 100644 --- a/ee/tabby-ui/app/files/components/file-tree.tsx +++ b/ee/tabby-ui/app/files/components/file-tree.tsx @@ -275,7 +275,7 @@ const DirectoryTreeNode: React.FC = ({ onSelectTreeNode?.(node) } - const [loading] = useDebounceValue(isLoading, 300) + const [loading] = useDebounceValue(isLoading, 100) const existingChildren = !!node?.children?.length @@ -330,6 +330,13 @@ const FileTreeRenderer: React.FC = () => { React.useContext(FileTreeContext) const { repositorySpecifier } = resolveRepositoryInfoFromPath(activePath) + const hasSelectedRepo = !!repositorySpecifier + const hasNoRepoEntries = hasSelectedRepo && !fileTreeData?.length + const fetchingRepoEntries = + activePath && + fileMap?.[activePath]?.isRepository && + !fileMap?.[activePath]?.treeExpanded + if (!initialized) return if (isEmpty(fileMap)) @@ -339,16 +346,20 @@ const FileTreeRenderer: React.FC = () => { ) - if (repositorySpecifier && !fileTreeData?.length) { + if (!hasSelectedRepo) { + return null + } + + if (hasNoRepoEntries) { + if (fetchingRepoEntries) { + return + } + return (
No Data
) } - if (!repositorySpecifier) { - return null - } - return ( <> {fileTreeData?.map(node => { diff --git a/ee/tabby-ui/app/files/components/source-code-browser.tsx b/ee/tabby-ui/app/files/components/source-code-browser.tsx index 29da16606058..da740d0e192c 100644 --- a/ee/tabby-ui/app/files/components/source-code-browser.tsx +++ b/ee/tabby-ui/app/files/components/source-code-browser.tsx @@ -23,6 +23,7 @@ import { ResizablePanelGroup } from '@/components/ui/resizable' import { BANNER_HEIGHT, useShowDemoBanner } from '@/components/demo-banner' +import { ListSkeleton } from '@/components/skeleton' import { useTopbarProgress } from '@/components/topbar-progress-indicator' import { emitter, QuickActionEventPayload } from '../lib/event-emitter' @@ -260,7 +261,7 @@ const SourceCodeBrowserRenderer: React.FC = ({ }, [activePath, fileMap, initialized]) // fetch raw file - const { data: rawFileResponse, isLoading: isRawFileLoading } = + const { data: rawFileResponse, isLoading: fetchingRawFile } = useSWRImmutable<{ blob?: Blob contentLength?: number @@ -291,14 +292,6 @@ const SourceCodeBrowserRenderer: React.FC = ({ } ) - React.useEffect(() => { - if (isRawFileLoading) { - setProgress(true) - } else { - setProgress(false) - } - }, [isRawFileLoading]) - const fileBlob = rawFileResponse?.blob const contentLength = rawFileResponse?.contentLength @@ -353,19 +346,36 @@ const SourceCodeBrowserRenderer: React.FC = ({ } }, [activePath]) + React.useEffect(() => { + if (!initialized) return + if (fetchingSubTree || fetchingRawFile) { + setProgress(true) + } else if (!fetchingSubTree && !fetchingRawFile) { + setProgress(false) + } + }, [fetchingSubTree, fetchingRawFile]) + React.useEffect(() => { const onFetchSubTree = () => { - if (subTree?.entries?.length && activePath) { + if (Array.isArray(subTree?.entries) && activePath) { const { repositorySpecifier } = resolveRepositoryInfoFromPath(activePath) let patchMap: TFileMap = {} - for (const entry of subTree.entries) { - const path = `${repositorySpecifier}/${entry.basename}` - patchMap[path] = { - file: entry, - name: resolveFileNameFromPath(path), - fullPath: path, - treeExpanded: false + if (fileMap?.[activePath]) { + patchMap[activePath] = { + ...fileMap[activePath], + treeExpanded: true + } + } + if (subTree?.entries?.length) { + for (const entry of subTree.entries) { + const path = `${repositorySpecifier}/${entry.basename}` + patchMap[path] = { + file: entry, + name: resolveFileNameFromPath(path), + fullPath: path, + treeExpanded: false + } } } updateFileMap(patchMap) @@ -437,25 +447,29 @@ const SourceCodeBrowserRenderer: React.FC = ({
-
- {showDirectoryView && ( - - )} - {showTextFileView && ( - - )} - {showRawFileView && ( - - )} -
+ {!initialized ? ( + + ) : ( +
+ {showDirectoryView && ( + + )} + {showTextFileView && ( + + )} + {showRawFileView && ( + + )} +
+ )}
<>