Skip to content

Commit

Permalink
Add error message if loading fails
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Nov 8, 2024
1 parent 84e061c commit 0b70d07
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/src/OrderHistoryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function OrderHistoryPanel({context}: {context: any}) {

const [ loading, setLoading ] = useState<boolean>(true);

const [ error, setError ] = useState<boolean>(false);

// Plugin settings object
const pluginSettings = useMemo(() => context?.context?.settings ?? {}, [context]);

Expand Down Expand Up @@ -197,7 +199,7 @@ function OrderHistoryPanel({context}: {context: any}) {

// Ensure that the selected order type is valid for the current context
useEffect(() => {
if (!validOrderTypes.find((type) => type.value == orderType)) {
if (!validOrderTypes.find((type: any) => type.value == orderType)) {
setOrderType(validOrderTypes[0]?.value ?? null);
}
}, [orderType, validOrderTypes]);
Expand Down Expand Up @@ -240,10 +242,12 @@ function OrderHistoryPanel({context}: {context: any}) {
}).then((response: any) => {
setHistoryData(response.data);
setLoading(false);
setError(false);
}).catch(() => {
console.error("ERR: Failed to fetch history data");
setHistoryData([]);
setLoading(false);
setError(true);
});
}

Expand Down Expand Up @@ -391,6 +395,11 @@ function OrderHistoryPanel({context}: {context: any}) {
<Paper withBorder p="sm" m="sm">
<Box pos="relative">
<LoadingOverlay visible={loading} />
{error && (
<Alert color="red" title="Error Loading Data">
<Text>Failed to load order history data from the server</Text>
</Alert>
)}
{(hasData || loading) ? (
<Card>
<BarChart
Expand Down

0 comments on commit 0b70d07

Please sign in to comment.