Skip to content

Commit b7300c9

Browse files
Remove start modal
1 parent ff56f6a commit b7300c9

File tree

4 files changed

+116
-173
lines changed

4 files changed

+116
-173
lines changed

app/gui/src/dashboard/components/ErrorBoundary.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import * as textProvider from '#/providers/TextProvider'
1313
import * as ariaComponents from '#/components/AriaComponents'
1414
import * as result from '#/components/Result'
1515

16+
import { Button, Text, type SvgUseIcon } from '#/components/AriaComponents'
1617
import { useEventCallback } from '#/hooks/eventCallbackHooks'
1718
import * as errorUtils from '#/utilities/error'
1819
import { OfflineError } from '#/utilities/HttpClient'
1920
import type { FallbackProps } from 'react-error-boundary'
21+
import { Icon } from './Icon'
2022
import SvgMask from './SvgMask'
2123

2224
// =====================
@@ -201,4 +203,35 @@ export function ErrorDisplay(props: ErrorDisplayProps): React.JSX.Element {
201203
return <>{render ?? defaultRender}</>
202204
}
203205

206+
/** Props for an {@link InlineErrorDisplay}. */
207+
export interface InlineErrorDisplayProps extends Omit<ErrorDisplayProps, 'status' | 'subtitle'> {}
208+
209+
/** Displays an error inline. */
210+
export function InlineErrorDisplay(props: InlineErrorDisplayProps) {
211+
const { error, resetErrorBoundary, onBeforeFallbackShown, title, resetQueries = () => {} } = props
212+
213+
const { getText } = textProvider.useText()
214+
215+
const render = onBeforeFallbackShown?.({ error, resetErrorBoundary, resetQueries })
216+
217+
const onReset = useEventCallback(() => {
218+
resetErrorBoundary()
219+
})
220+
221+
const finalTitle = title ?? getText('somethingWentWrong')
222+
const finalIcon: SvgUseIcon = 'error'
223+
224+
const defaultRender = (
225+
<div className="flex items-center gap-1">
226+
<Icon icon={finalIcon} />
227+
<Text>{finalTitle}</Text>
228+
<Button variant="outline" size="xsmall" onPress={onReset} className="ml-3">
229+
{getText('tryAgain')}
230+
</Button>
231+
</div>
232+
)
233+
234+
return <>{render ?? defaultRender}</>
235+
}
236+
204237
export { useErrorBoundary, withErrorBoundary } from 'react-error-boundary'

app/gui/src/dashboard/layouts/StartModal.tsx

Lines changed: 0 additions & 58 deletions
This file was deleted.

app/gui/src/dashboard/pages/dashboard/Drive/DriveBar/DriveBar.tsx

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
import type { Category } from '#/layouts/CategorySwitcher/Category'
77
import type Backend from '#/services/Backend'
88
import 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'
1510
import { DriveBarNavigation } from './DriveBarNavigation'
1611
import { 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
*/
3325
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
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

Comments
 (0)