Skip to content

Commit 9aced58

Browse files
feat: show a button when no storage found (#210)
* feat: show a button when no storage found * fix: remove unused imports and enhace check
1 parent ca22179 commit 9aced58

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/components/Base.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ import {
1717
Icon,
1818
} from "@hope-ui/solid"
1919
import { SwitchColorMode } from "./SwitchColorMode"
20-
import { ComponentProps, For, mergeProps, Show } from "solid-js"
20+
import { ComponentProps, For, mergeProps, Show, JSXElement } from "solid-js"
2121
import { AiOutlineFullscreen, AiOutlineFullscreenExit } from "solid-icons/ai"
2222
import { hoverColor } from "~/utils"
2323

2424
export const Error = (props: {
2525
msg: string
2626
disableColor?: boolean
2727
h?: string
28+
actions?: JSXElement
2829
}) => {
2930
const merged = mergeProps(
3031
{
@@ -47,6 +48,11 @@ export const Error = (props: {
4748
>
4849
{props.msg}
4950
</Heading>
51+
<Show when={props.actions}>
52+
<Flex mt="$4" justifyContent="center">
53+
{props.actions}
54+
</Flex>
55+
</Show>
5056
<Show when={!props.disableColor}>
5157
<Flex mt="$2" justifyContent="end">
5258
<SwitchColorMode />

src/lang/en/global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
"close": "Close",
2929
"no_support_now": "Not currently supported",
3030
"empty_input": "Please enter",
31-
"name": "Name"
31+
"name": "Name",
32+
"go_to_storages": "Go to Storages"
3233
}

src/pages/home/Obj.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Text, useColorModeValue, VStack } from "@hope-ui/solid"
1+
import { Text, useColorModeValue, VStack, Button } from "@hope-ui/solid"
22
import {
33
createEffect,
44
createMemo,
@@ -19,7 +19,9 @@ import {
1919
recordHistory,
2020
setPassword,
2121
/*layout,*/ State,
22+
me,
2223
} from "~/store"
24+
import { UserMethods } from "~/types"
2325

2426
const Folder = lazy(() => import("./folder/Folder"))
2527
const File = lazy(() => import("./file/File"))
@@ -33,7 +35,7 @@ export { objBoxRef }
3335
export const Obj = () => {
3436
const t = useT()
3537
const cardBg = useColorModeValue("white", "$neutral3")
36-
const { pathname, searchParams, isShare } = useRouter()
38+
const { pathname, searchParams, isShare, to } = useRouter()
3739
const { handlePathChange, refresh } = usePath()
3840
const pagination = getPagination()
3941
const page = createMemo(() => {
@@ -57,6 +59,23 @@ export const Obj = () => {
5759
await handlePathChange(pathname, page)
5860
}),
5961
)
62+
63+
const isStorageError = createMemo(() => {
64+
const err = objStore.err
65+
return (
66+
err.includes("storage not found") || err.includes("please add a storage")
67+
)
68+
})
69+
70+
const shouldShowStorageButton = createMemo(() => {
71+
return isStorageError() && UserMethods.is_admin(me())
72+
})
73+
74+
const storageErrorActions = () => (
75+
<Button colorScheme="accent" onClick={() => to("/@manage/storages")}>
76+
{t("global.go_to_storages")}
77+
</Button>
78+
)
6079
return (
6180
<VStack
6281
ref={(el: HTMLDivElement) => setObjBoxRef(el)}
@@ -71,7 +90,13 @@ export const Obj = () => {
7190
<Suspense fallback={<FullLoading />}>
7291
<Switch>
7392
<Match when={objStore.err}>
74-
<Error msg={objStore.err} disableColor />
93+
<Error
94+
msg={objStore.err}
95+
disableColor
96+
actions={
97+
shouldShowStorageButton() ? storageErrorActions() : undefined
98+
}
99+
/>
75100
</Match>
76101
<Match
77102
when={[State.FetchingObj, State.FetchingObjs].includes(

0 commit comments

Comments
 (0)