fix: changed position of error message, disabled buttons when error is showing
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@components/UI/Dialog.tsx";
|
} from "@components/UI/Dialog.tsx";
|
||||||
import { AlertCircle, } from "lucide-react";
|
import { AlertCircle, InfoIcon, } from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Tabs,
|
Tabs,
|
||||||
TabsContent,
|
TabsContent,
|
||||||
@@ -29,9 +29,7 @@ export interface TabElementProps {
|
|||||||
export interface TabManifest {
|
export interface TabManifest {
|
||||||
label: string;
|
label: string;
|
||||||
element: React.FC<TabElementProps>;
|
element: React.FC<TabElementProps>;
|
||||||
disabled: boolean;
|
isDisabled: boolean;
|
||||||
disabledMessage: string;
|
|
||||||
disabledLink?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NewDeviceProps {
|
export interface NewDeviceProps {
|
||||||
@@ -121,24 +119,21 @@ export const NewDeviceDialog = ({
|
|||||||
{
|
{
|
||||||
label: "HTTP",
|
label: "HTTP",
|
||||||
element: HTTP,
|
element: HTTP,
|
||||||
disabled: false,
|
isDisabled: false,
|
||||||
disabledMessage: "Unsuported connection method",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Bluetooth",
|
label: "Bluetooth",
|
||||||
element: BLE,
|
element: BLE,
|
||||||
disabled:
|
isDisabled:
|
||||||
unsupported.includes("Web Bluetooth") ||
|
unsupported.includes("Web Bluetooth") ||
|
||||||
unsupported.includes("Secure Context"),
|
unsupported.includes("Secure Context"),
|
||||||
disabledMessage: "",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Serial",
|
label: "Serial",
|
||||||
element: Serial,
|
element: Serial,
|
||||||
disabled:
|
isDisabled:
|
||||||
unsupported.includes("Web Serial") ||
|
unsupported.includes("Web Serial") ||
|
||||||
unsupported.includes("Secure Context"),
|
unsupported.includes("Secure Context"),
|
||||||
disabledMessage: "",
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -154,7 +149,6 @@ export const NewDeviceDialog = ({
|
|||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
key={tab.label}
|
key={tab.label}
|
||||||
value={tab.label}
|
value={tab.label}
|
||||||
disabled={tab.disabled}
|
|
||||||
>
|
>
|
||||||
{tab.label}
|
{tab.label}
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
@@ -162,16 +156,12 @@ export const NewDeviceDialog = ({
|
|||||||
</TabsList>
|
</TabsList>
|
||||||
{tabs.map((tab) => (
|
{tabs.map((tab) => (
|
||||||
<TabsContent key={tab.label} value={tab.label}>
|
<TabsContent key={tab.label} value={tab.label}>
|
||||||
{tab.disabled ? (
|
<fieldset disabled={tab.isDisabled}>
|
||||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
{tab.isDisabled ? <ErrorMessage missingFeatures={unsupported} /> : null}
|
||||||
{tab.disabledMessage}
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<tab.element closeDialog={() => onOpenChange(false)} />
|
<tab.element closeDialog={() => onOpenChange(false)} />
|
||||||
)}
|
</fieldset>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
))}
|
))}
|
||||||
<ErrorMessage missingFeatures={unsupported} />
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ export const Serial = ({ closeDialog }: TabElementProps): JSX.Element => {
|
|||||||
const { setSelectedDevice } = useAppStore();
|
const { setSelectedDevice } = useAppStore();
|
||||||
|
|
||||||
const updateSerialPortList = useCallback(async () => {
|
const updateSerialPortList = useCallback(async () => {
|
||||||
setSerialPorts(await navigator.serial.getPorts());
|
setSerialPorts(await navigator?.serial.getPorts());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
navigator.serial.addEventListener("connect", () => {
|
navigator?.serial?.addEventListener("connect", () => {
|
||||||
updateSerialPortList();
|
updateSerialPortList();
|
||||||
});
|
});
|
||||||
navigator.serial.addEventListener("disconnect", () => {
|
navigator?.serial?.addEventListener("disconnect", () => {
|
||||||
updateSerialPortList();
|
updateSerialPortList();
|
||||||
});
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -58,9 +58,8 @@ export const Serial = ({ closeDialog }: TabElementProps): JSX.Element => {
|
|||||||
await onConnect(port);
|
await onConnect(port);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{`# ${index} - ${usbVendorId ?? "UNK"} - ${
|
{`# ${index} - ${usbVendorId ?? "UNK"} - ${usbProductId ?? "UNK"
|
||||||
usbProductId ?? "UNK"
|
}`}
|
||||||
}`}
|
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ interface BrowserSupport {
|
|||||||
export function useBrowserFeatureDetection(): BrowserSupport {
|
export function useBrowserFeatureDetection(): BrowserSupport {
|
||||||
const support = useMemo(() => {
|
const support = useMemo(() => {
|
||||||
const features: [BrowserFeature, boolean][] = [
|
const features: [BrowserFeature, boolean][] = [
|
||||||
['Web Bluetooth', !!navigator.bluetooth],
|
['Web Bluetooth', !!navigator?.bluetooth],
|
||||||
['Web Serial', !!navigator.serial],
|
['Web Serial', !!navigator?.serial],
|
||||||
['Secure Context', window.location.protocol === 'https:' || window.location.hostname === 'localhost']
|
['Secure Context', window.location.protocol === 'https:' || window.location.hostname === 'localhost']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user