Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(client): added unreachable server display (#100)

Corentin THOMASSETc2dc8bfdfb2c
diff --git a/apps/papra-client/src/modules/config/config.provider.tsx b/apps/papra-client/src/modules/config/config.provider.tsx
index 4c7068f8..060476a0 100644
--- a/apps/papra-client/src/modules/config/config.provider.tsx
+++ b/apps/papra-client/src/modules/config/config.provider.tsx
@@ -1,7 +1,10 @@
import type { ParentComponent } from 'solid-js';
import { createQuery } from '@tanstack/solid-query';
import { merge } from 'lodash-es';
-import { createContext, Show, useContext } from 'solid-js';
+import { createContext, Match, Switch, useContext } from 'solid-js';
+import { Button } from '../ui/components/button';
+import { EmptyState } from '../ui/components/empty';
+import { createToast } from '../ui/components/sonner';
import { buildTimeConfig, type Config, type RuntimePublicConfig } from './config';
import { fetchPublicConfig } from './config.services';
@@ -29,13 +32,45 @@ export const ConfigProvider: ParentComponent = (props) => {
return merge({}, buildTimeConfig, runtimeConfig);
};
+ const retry = async () => {
+ const result = await query.refetch();
+
+ if (result.error) {
+ createToast({
+ message: 'Server still unreachable',
+ description: 'The server remains unreachable, try again later.',
+ type: 'error',
+ });
+ }
+ };
+
return (
- <Show when={query.data?.config}>
- {getConfig => (
- <ConfigContext.Provider value={{ config: mergeConfigs(getConfig()) }}>
- {props.children}
- </ConfigContext.Provider>
- )}
- </Show>
+ <Switch>
+ <Match when={query.error}>
+ <EmptyState
+ title="Server unreachable"
+ description="The server seems to be unreachable, if you are self-hosting, make sure the server is running and properly configured. You may want to check the console for more information."
+ icon="i-tabler-server-spark"
+ class="p-6 pt-12 sm:pt-32"
+ cta={(
+ <Button
+ onClick={retry}
+ variant="outline"
+ >
+ <span class="i-tabler-refresh size-4 mr-2 text-primary" />
+ Retry
+ </Button>
+ )}
+ />
+ </Match>
+
+ <Match when={query.data?.config}>
+ {getConfig => (
+ <ConfigContext.Provider value={{ config: mergeConfigs(getConfig()) }}>
+ {props.children}
+ </ConfigContext.Provider>
+ )}
+ </Match>
+ </Switch>
);
};
diff --git a/apps/papra-client/src/modules/ui/components/empty.tsx b/apps/papra-client/src/modules/ui/components/empty.tsx
index f0ff36a9..ed289903 100644
--- a/apps/papra-client/src/modules/ui/components/empty.tsx
+++ b/apps/papra-client/src/modules/ui/components/empty.tsx
@@ -1,14 +1,16 @@
-import type { Component, JSX } from 'solid-js';
import { cn } from '@/modules/shared/style/cn';
+import { type Component, type ComponentProps, type JSX, splitProps } from 'solid-js';
export const EmptyState: Component<{
title: JSX.Element;
icon: string;
description: JSX.Element;
cta?: JSX.Element;
-}> = (props) => {
+} & ComponentProps<'div'>> = (props) => {
+ const [local, rest] = splitProps(props, ['title', 'icon', 'description', 'cta', 'class']);
+
return (
- <div class="flex flex-col items-center justify-center gap-2 pt-24 mx-auto max-w-md text-center">
+ <div class={cn('flex flex-col items-center justify-center gap-2 pt-24 mx-auto max-w-md text-center', local.class)} {...rest}>
<div class={cn(props.icon, 'text-primary size-12')} aria-hidden="true" />
<div class="text-xl font-medium">{props.title}</div>
<div class="text-sm text-muted-foreground mb-2">{props.description}</div>