6
6
import type { Category } from '#/layouts/CategorySwitcher/Category'
7
7
import type Backend from '#/services/Backend'
8
8
import type AssetQuery from '#/utilities/AssetQuery'
9
- import { useEffect , useState } from 'react'
10
9
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'
15
10
import { DriveBarNavigation } from './DriveBarNavigation'
16
11
import { DriveBarToolbar } from './DriveBarToolbar'
17
12
@@ -21,77 +16,20 @@ export interface DriveBarProps {
21
16
readonly query : AssetQuery
22
17
readonly setQuery : React . Dispatch < React . SetStateAction < AssetQuery > >
23
18
readonly category : Category
24
- readonly rootDirectoryId : DirectoryId
25
19
}
26
20
27
- const CATEGORIES_TO_DISPLAY_START_MODAL = [ 'cloud' , 'local' , 'local-directory' ]
28
-
29
21
/**
30
22
* Displays the current directory path and permissions, upload and download buttons,
31
23
* and a column display mode switcher.
32
24
*/
33
25
export 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
82
27
83
28
return (
84
29
< div className = "flex flex-col gap-2" >
85
30
< DriveBarNavigation />
86
31
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 } />
95
33
</ div >
96
34
)
97
35
}
0 commit comments