Skip to content

Commit

Permalink
add action buttons to loading error screen
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Feb 13, 2024
1 parent ad4bae4 commit cc2c25a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkspaceHandle>(null);
const resetWorkspace = () => workspace.current?.reset();
Expand All @@ -44,7 +46,7 @@ const App = (): JSX.Element => {
<DragContext>
<Wrapper>
<WebGLDetector />
{!loading && (
{!loading && !loadingError && (
<ContextMenuProvider>
<div tw="flex flex-col h-full w-full">
<div tw="flex-initial relative">
Expand Down Expand Up @@ -72,6 +74,7 @@ const App = (): JSX.Element => {
<LoadingIndicator />
</div>
)}
{loadingError && <LoadingError problem={loadingError} />}
<ToastContainer position="bottom-right" />
</Wrapper>
</DragContext>
Expand Down
39 changes: 39 additions & 0 deletions src/components/LoadingError.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Center tw="flex flex-col gap-y-4 text-midnight-600">
<div tw="flex flex-col items-center">
<h1 tw="text-lg">Failed to load your dataset</h1>
<p tw="text-sm text-gray-800">(with the following API error)</p>
</div>
<div tw="border border-red-600 rounded bg-red-100 divide-y divide-red-600">
<h2 tw="font-bold p-1">{problem.title}</h2>
{problem.detail && <p tw="p-1 text-sm">{problem.detail}</p>}
</div>
<div tw="flex flex-row gap-x-2">
<Button onClick={reload}>Reload</Button>
{application.filebrowsingAllowed && (
<Button onClick={browse}>Open another dataset</Button>
)}
<Button onClick={close}>Close</Button>
</div>
</Center>
);
};

export default LoadingError;
5 changes: 4 additions & 1 deletion src/stores/dataset/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -472,6 +472,9 @@ export const useDataset = create(
colorTransferFunctions: newTransferFunctions,
});
},
clearLoadingError: () => {
set({ loadingError: undefined });
},
};
})
);
Expand Down

0 comments on commit cc2c25a

Please sign in to comment.