Skip to content

Commit

Permalink
[ENG-1020] Explorer loading indicator (spacedriveapp#1318)
Browse files Browse the repository at this point in the history
* loading indicator

* cleanup tw
  • Loading branch information
ameer2468 authored Sep 8, 2023
1 parent d435141 commit 2111d35
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions interface/app/$libraryId/Explorer/View/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
useLibraryMutation
} from '@sd/client';
import { ContextMenu, ModifierKeys, dialogManager, toast } from '@sd/ui';
import { Loader } from '~/components';
import { useOperatingSystem } from '~/hooks';
import { isNonEmpty } from '~/util';
import { usePlatform } from '~/util/Platform';
Expand Down Expand Up @@ -206,11 +207,19 @@ export default memo(({ className, style, emptyNotice, ...contextProps }: Explore

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
const [isRenaming, setIsRenaming] = useState(false);
const [showLoading, setShowLoading] = useState(false);

useKeyDownHandlers({
disabled: isRenaming || quickPreviewStore.open
});

useEffect(() => {
if (explorer.isFetchingNextPage) {
const timer = setTimeout(() => setShowLoading(true), 100);
return () => clearTimeout(timer);
} else setShowLoading(false);
}, [explorer.isFetchingNextPage]);

return (
<>
<div
Expand Down Expand Up @@ -241,6 +250,9 @@ export default memo(({ className, style, emptyNotice, ...contextProps }: Explore
{layoutMode === 'grid' && <GridView />}
{layoutMode === 'list' && <ListView />}
{layoutMode === 'media' && <MediaView />}
{showLoading && (
<Loader className="fixed bottom-10 left-0 w-[calc(100%+180px)]" />
)}
</ViewContext.Provider>
) : (
emptyNotice
Expand Down
1 change: 1 addition & 0 deletions interface/app/$libraryId/Explorer/useExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface UseExplorerProps<TOrder extends Ordering> {
count?: number;
parent?: ExplorerParent;
loadMore?: () => void;
isFetchingNextPage?: boolean;
scrollRef?: RefObject<HTMLDivElement>;
/**
* @defaultValue `true`
Expand Down
3 changes: 2 additions & 1 deletion interface/app/$libraryId/location/$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export const Component = () => {
orderingKeys: filePathOrderingKeysSchema
});

const { items, count, loadMore } = useItems({ locationId, settings: explorerSettings });
const { items, count, loadMore, query } = useItems({ locationId, settings: explorerSettings });

const explorer = useExplorer({
items,
count,
loadMore,
isFetchingNextPage: query.isFetchingNextPage,
settings: explorerSettings,
...(location.data && {
parent: { type: 'Location', location: location.data }
Expand Down
21 changes: 21 additions & 0 deletions interface/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import clsx from 'clsx';
import { Puff } from 'react-loading-icons';
import { useIsDark } from '~/hooks';

interface Props {
className?: string;
color?: string;
}

export function Loader({ className }: Props) {
const isDark = useIsDark();
return (
<Puff
stroke={isDark ? '#2599FF' : '#303136'}
strokeOpacity={4}
strokeWidth={5}
speed={1}
className={clsx('h-7 w-7', className)}
/>
);
}
1 change: 1 addition & 0 deletions interface/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './TextViewer';
export * from './PasswordMeter';
export * from './SubtleButton';
export * from './TrafficLights';
export * from './Loader';

0 comments on commit 2111d35

Please sign in to comment.