Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
353 changes: 185 additions & 168 deletions interface/package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
"version": "0.1.0",
"private": true,
"type": "module",
"proxy": "http://192.168.0.23",
"proxy": "http://192.168.0.229",
"scripts": {
"dev": "vite --no-open",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview --no-open"
},
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.8.0",
"@mui/material": "^5.8.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@mui/icons-material": "^7.3.7",
"@mui/material": "^7.3.7",
"async-validator": "^4.1.1",
"axios": "^0.27.2",
"axios": "^1.13.5",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.23",
"notistack": "^2.0.5",
"parse-ms": "^3.0.0",
"notistack": "^3.0.2",
"parse-ms": "^4.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-dropzone": "^11.4.2",
"react-dropzone": "^14.4.0",
"react-router-dom": "^6.30.1",
"sockette": "^2.0.6"
},
Expand Down
6 changes: 3 additions & 3 deletions interface/src/api/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosPromise, CancelToken } from 'axios';
import axios, { AxiosProgressEvent, AxiosPromise } from 'axios';

export const WS_BASE_URL = '/ws/';
export const API_BASE_URL = '/rest/';
Expand Down Expand Up @@ -30,8 +30,8 @@ function calculateWebSocketRoot(webSocketPath: string) {
}

export interface FileUploadConfig {
cancelToken?: CancelToken;
onUploadProgress?: (progressEvent: ProgressEvent) => void;
signal?: AbortSignal;
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
}

export const uploadFile = (url: string, file: File, config?: FileUploadConfig): AxiosPromise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions interface/src/components/layout/LayoutMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const LayoutMenuItem: FC<LayoutMenuItemProps> = ({ icon: Icon, label, to, disabl
const { pathname } = useLocation();

return (
<ListItem disablePadding selected={routeMatches(to, pathname)}>
<ListItemButton component={Link} to={to} disabled={disabled}>
<ListItem disablePadding>
<ListItemButton component={Link} to={to} disabled={disabled} selected={routeMatches(to, pathname)}>
<ListItemIcon>
<Icon />
</ListItemIcon>
Expand Down
25 changes: 19 additions & 6 deletions interface/src/components/upload/SingleUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { FC, Fragment } from 'react';
import { useDropzone, DropzoneState } from 'react-dropzone';
import { useDropzone, DropzoneState, Accept } from 'react-dropzone';

import { Box, Button, LinearProgress, Theme, Typography, useTheme } from '@mui/material';

import CloudUploadIcon from '@mui/icons-material/CloudUpload';
import CancelIcon from '@mui/icons-material/Cancel';

const progressPercentage = (progress: ProgressEvent) => Math.round((progress.loaded * 100) / progress.total);
import { AxiosProgressEvent } from 'axios';

const progressPercentage = (progress: AxiosProgressEvent) => {
if (!progress.loaded || !progress.total) {
return 0;
}
return Math.round((progress.loaded * 100) / progress.total);
};

const getBorderColor = (theme: Theme, props: DropzoneState) => {
if (props.isDragAccept) {
Expand All @@ -24,12 +31,18 @@ const getBorderColor = (theme: Theme, props: DropzoneState) => {
export interface SingleUploadProps {
onDrop: (acceptedFiles: File[]) => void;
onCancel: () => void;
accept?: string | string[];
accept?: Accept;
uploading: boolean;
progress?: ProgressEvent;
progress?: AxiosProgressEvent;
}

const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, accept, uploading, progress }) => {
const SingleUpload: FC<SingleUploadProps> = ({
onDrop,
onCancel,
accept,
uploading,
progress
}) => {
const dropzoneState = useDropzone({ onDrop, accept, disabled: uploading, multiple: false });
const { getRootProps, getInputProps } = dropzoneState;
const theme = useTheme();
Expand Down Expand Up @@ -81,7 +94,7 @@ const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, accept, uploadi
</Fragment>
)}
</Box>
</Box >
</Box>
);
};

Expand Down
35 changes: 20 additions & 15 deletions interface/src/components/upload/useFileUpload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react';
import axios, { AxiosPromise, CancelTokenSource } from 'axios';
import { useSnackbar } from "notistack";
import { useCallback, useEffect, useRef, useState } from 'react';
import axios, { AxiosPromise, AxiosProgressEvent } from 'axios';
import { useSnackbar } from 'notistack';

import { extractErrorMessage } from '../../utils';
import { FileUploadConfig } from '../../api/endpoints';
Expand All @@ -11,36 +11,41 @@ interface MediaUploadOptions {

const useFileUpload = ({ upload }: MediaUploadOptions) => {
const { enqueueSnackbar } = useSnackbar();
const [uploading, setUploading] = useState<boolean>(false);
const [uploadProgress, setUploadProgress] = useState<ProgressEvent>();
const [uploadCancelToken, setUploadCancelToken] = useState<CancelTokenSource>();

const [uploading, setUploading] = useState(false);
const [uploadProgress, setUploadProgress] = useState<AxiosProgressEvent>();

const abortControllerRef = useRef<AbortController | null>(null);

const resetUploadingStates = () => {
setUploading(false);
setUploadProgress(undefined);
setUploadCancelToken(undefined);
abortControllerRef.current = null;
};

const cancelUpload = useCallback(() => {
uploadCancelToken?.cancel();
abortControllerRef.current?.abort();
resetUploadingStates();
}, [uploadCancelToken]);
}, []);

useEffect(() => {
return () => {
uploadCancelToken?.cancel();
abortControllerRef.current?.abort();
};
}, [uploadCancelToken]);
}, []);

const uploadFile = async (images: File[]) => {
try {
const cancelToken = axios.CancelToken.source();
setUploadCancelToken(cancelToken);
const controller = new AbortController();
abortControllerRef.current = controller;

setUploading(true);

await upload(images[0], {
onUploadProgress: setUploadProgress,
cancelToken: cancelToken.token
signal: controller.signal,
onUploadProgress: setUploadProgress
});

resetUploadingStates();
enqueueSnackbar('Upload successful', { variant: 'success' });
} catch (error: any) {
Expand Down
4 changes: 3 additions & 1 deletion interface/src/framework/system/FirmwareFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const FirmwareFileUpload: FC<UploadFirmwareProps> = ({ uploadFirmware }) => {
my={2}
/>
<SingleUpload
accept="application/octet-stream"
accept={{
'application/octet-stream': ['.bin']
}}
onDrop={uploadFile}
onCancel={cancelUpload}
uploading={uploading}
Expand Down
34 changes: 18 additions & 16 deletions interface/src/framework/wifi/WiFiNetworkSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, useContext } from 'react';

import { Avatar, Badge, List, ListItem, ListItemAvatar, ListItemIcon, ListItemText } from '@mui/material';
import { Avatar, Badge, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
import LockOpenIcon from '@mui/icons-material/LockOpen';
import LockIcon from '@mui/icons-material/Lock';
import WifiIcon from '@mui/icons-material/Wifi';
Expand All @@ -20,21 +20,23 @@ const WiFiNetworkSelector: FC<WiFiNetworkSelectorProps> = ({ networkList }) => {

const renderNetwork = (network: WiFiNetwork) => {
return (
<ListItem key={network.bssid} button onClick={() => wifiConnectionContext.selectNetwork(network)}>
<ListItemAvatar>
<Avatar>
{isNetworkOpen(network) ? <LockOpenIcon /> : <LockIcon />}
</Avatar>
</ListItemAvatar>
<ListItemText
primary={network.ssid}
secondary={"Security: " + networkSecurityMode(network) + ", Ch: " + network.channel}
/>
<ListItemIcon>
<Badge badgeContent={network.rssi + "db"}>
<WifiIcon />
</Badge>
</ListItemIcon>
<ListItem key={network.bssid}>
<ListItemButton onClick={() => wifiConnectionContext.selectNetwork(network)}>
<ListItemAvatar>
<Avatar>
{isNetworkOpen(network) ? <LockOpenIcon /> : <LockIcon />}
</Avatar>
</ListItemAvatar>
<ListItemText
primary={network.ssid}
secondary={"Security: " + networkSecurityMode(network) + ", Ch: " + network.channel}
/>
<ListItemIcon>
<Badge badgeContent={network.rssi + "db"}>
<WifiIcon />
</Badge>
</ListItemIcon>
</ListItemButton>
</ListItem>
);
};
Expand Down