diff --git a/src/App.tsx b/src/App.tsx index 73c2a08b..a73333ae 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,18 +13,20 @@ import tw from 'twin.macro'; import 'styled-components'; import usePluginStore from './stores/pluginStore'; import DragContext from './systems/dnd/DragContext'; +import LoadingError from './components/LoadingError'; -const Wrapper = tw.div`bg-gray-200 text-midnight-600 w-screen h-screen relative overflow-hidden`; +const Wrapper = tw.main`bg-gray-200 text-midnight-600 w-screen h-screen relative overflow-hidden`; // fetch the dataset once on app init useDataset.getState().fetch(); const loadingSelector = (d: Dataset) => d.loading; +const loadingErrorSelector = (d: Dataset) => d.loadingError; const App = (): JSX.Element => { const plugins = usePluginStore((state) => state.plugins); - const loading = useDataset(loadingSelector) || plugins === undefined; + const loadingError = useDataset(loadingErrorSelector); const workspace = useRef(null); const resetWorkspace = () => workspace.current?.reset(); @@ -44,7 +46,7 @@ const App = (): JSX.Element => { - {!loading && ( + {!loading && !loadingError && (
@@ -72,6 +74,7 @@ const App = (): JSX.Element => {
)} + {loadingError && } diff --git a/src/components/LoadingError.tsx b/src/components/LoadingError.tsx new file mode 100644 index 00000000..849f8823 --- /dev/null +++ b/src/components/LoadingError.tsx @@ -0,0 +1,39 @@ +import application from '../application'; +import { useDataset } from '../lib'; +import { Problem } from '../types'; +import Center from './ui/Center'; +import tw from 'twin.macro'; + +interface Props { + problem: Problem; +} + +const Button = tw.button`border border-gray-600 rounded px-2 py-1 text-sm`; + +const LoadingError = ({ problem }: Props): JSX.Element => { + const reload = () => location.reload(); + const browse = () => useDataset.getState().clearLoadingError(); + const close = () => window.close(); + + return ( +
+
+

Failed to load your dataset

+

(with the following API error)

+
+
+

{problem.title}

+ {problem.detail &&

{problem.detail}

} +
+
+ + {application.filebrowsingAllowed && ( + + )} + +
+
+ ); +}; + +export default LoadingError; diff --git a/src/stores/dataset/dataset.ts b/src/stores/dataset/dataset.ts index da65c735..b6b78dab 100644 --- a/src/stores/dataset/dataset.ts +++ b/src/stores/dataset/dataset.ts @@ -6,7 +6,6 @@ import { useColors } from '../colors'; import { create } from 'zustand'; import { subscribeWithSelector } from 'zustand/middleware'; import { shallow } from 'zustand/shallow'; -import { Table } from '../../client'; import { ColumnsStats, DataColumn, @@ -87,6 +86,7 @@ export interface Dataset { isComputingRelevance: boolean; recomputeColumnRelevance: () => void; focusRow: (row?: number) => void; + clearLoadingError: () => void; } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -472,6 +472,9 @@ export const useDataset = create( colorTransferFunctions: newTransferFunctions, }); }, + clearLoadingError: () => { + set({ loadingError: undefined }); + }, }; }) );