mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
firmware/installPybricksDialog/hooks: dispatch error if no url
Dispatch an error in case there is no firmware URL. Normally this should never happen, but currently it does because we don't have EV3 firmware yet. The error is more useful than just spinning forever.
This commit is contained in:
committed by
David Lechner
parent
c6302232e3
commit
fadc3bc8c7
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
// Copyright (c) 2022-2025 The Pybricks Authors
|
||||
// based on https://usehooks-ts.com/react-hook/use-fetch
|
||||
|
||||
import { FirmwareMetadata, FirmwareReader } from '@pybricks/firmware';
|
||||
@@ -78,8 +78,10 @@ export function useFirmware(hubType: Hub): State {
|
||||
const [state, dispatch] = useReducer(fetchReducer, initialState);
|
||||
|
||||
useEffect(() => {
|
||||
// Do nothing if the url is not given
|
||||
// Raise error if the url is not given, to show that something is wrong
|
||||
// instead of a misleading intermediate state.
|
||||
if (!url) {
|
||||
dispatch({ type: 'error', payload: new Error('No URL for this hub type') });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user