66import type { Category } from '#/layouts/CategorySwitcher/Category'
77import type Backend from '#/services/Backend'
88import type AssetQuery from '#/utilities/AssetQuery'
9- import { useEffect , useState } from 'react'
109
11- import { useErrorBoundary } from '#/components/ErrorBoundary'
12- import { listDirectoryQueryOptions } from '#/hooks/backendHooks'
13- import type { DirectoryId } from '#/services/Backend'
14- import { useQueryClient , useSuspenseQuery } from '@tanstack/react-query'
1510import { DriveBarNavigation } from './DriveBarNavigation'
1611import { DriveBarToolbar } from './DriveBarToolbar'
1712
@@ -21,77 +16,20 @@ export interface DriveBarProps {
2116 readonly query : AssetQuery
2217 readonly setQuery : React . Dispatch < React . SetStateAction < AssetQuery > >
2318 readonly category : Category
24- readonly rootDirectoryId : DirectoryId
2519}
2620
27- const CATEGORIES_TO_DISPLAY_START_MODAL = [ 'cloud' , 'local' , 'local-directory' ]
28-
2921/**
3022 * Displays the current directory path and permissions, upload and download buttons,
3123 * and a column display mode switcher.
3224 */
3325export function DriveBar ( props : DriveBarProps ) {
34- const { backend, query, setQuery, category, rootDirectoryId } = props
35-
36- const [ shouldForceHideStartModal , setShouldForceHideStartModal ] = useState ( false )
37- const { showBoundary } = useErrorBoundary ( )
38-
39- const queryClient = useQueryClient ( )
40- const rootDirectoryQuery = listDirectoryQueryOptions ( {
41- backend,
42- category,
43- parentId : rootDirectoryId ,
44- } )
45-
46- const {
47- data : isEmpty ,
48- error,
49- isFetching,
50- } = useSuspenseQuery ( {
51- ...rootDirectoryQuery ,
52- select : ( data ) => data . length === 0 ,
53- } )
54-
55- // Show the error boundary if the query failed, but has data.
56- if ( error != null && ! isFetching ) {
57- showBoundary ( error )
58- // Remove the query from the cache.
59- // This will force the query to be refetched when the user navigates again.
60- queryClient . removeQueries ( { queryKey : rootDirectoryQuery . queryKey } )
61- }
62-
63- // When the directory is no longer empty, we need to hide the start modal.
64- // This includes the cases when the directory wasn't empty before, but it's now empty
65- // (e.g. when the user deletes the last asset).
66- useEffect ( ( ) => {
67- if ( ! isEmpty ) {
68- setShouldForceHideStartModal ( true )
69- }
70- } , [ isEmpty ] )
71-
72- // When the root directory changes, we need to show the start modal
73- // if the directory is empty.
74- useEffect ( ( ) => {
75- setShouldForceHideStartModal ( false )
76- } , [ category . type ] )
77-
78- const shouldDisplayStartModal =
79- isEmpty &&
80- CATEGORIES_TO_DISPLAY_START_MODAL . includes ( category . type ) &&
81- ! shouldForceHideStartModal
26+ const { backend, query, setQuery, category } = props
8227
8328 return (
8429 < div className = "flex flex-col gap-2" >
8530 < DriveBarNavigation />
8631
87- < DriveBarToolbar
88- backend = { backend }
89- query = { query }
90- setQuery = { setQuery }
91- category = { category }
92- isEmpty = { isEmpty }
93- shouldDisplayStartModal = { shouldDisplayStartModal }
94- />
32+ < DriveBarToolbar backend = { backend } query = { query } setQuery = { setQuery } category = { category } />
9533 </ div >
9634 )
9735}
0 commit comments