Skip to content

Commit

Permalink
improved read cmd dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 21, 2024
1 parent 26aa553 commit 0dfcd10
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions interface/src/app/status/SystemLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const SystemLog = () => {
});

const { send } = useRequest(
(data: string) => API({ device: 'system', cmd: 'read', id: 0, value: data }),
(data: string) => API({ device: 'system', cmd: 'read', id: 0, data: data }),
{
immediate: false
}
Expand Down Expand Up @@ -176,10 +176,12 @@ const SystemLog = () => {
setReadOpen(!readOpen);
return;
}
void send(readValue);
console.log('send read command', readValue); // TODO remove
setReadOpen(false);
setReadValue('');

if (readValue.split(' ').filter((word) => word !== '').length > 1) {
void send(readValue);
setReadOpen(false);
setReadValue('');
}
};

const content = () => {
Expand Down Expand Up @@ -271,31 +273,50 @@ const SystemLog = () => {
)}
</Grid>

{data.developer_mode && (
<Grid>
{readOpen && (
<TextField
value={readValue}
onChange={(event) => {
const value = event.target.value;
if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) {
return;
}
setReadValue(value);
}}
focused={true}
label="Send Read command"
variant="outlined"
helperText="<deviceID> <type ID> [offset] [length]"
size="small"
/>
)}
<IconButton onClick={sendReadCommand}>
<PlayArrowIcon color="primary" />
{readOpen ? (
<Box
component="form"
sx={{ display: 'flex', alignItems: 'flex-end' }}
onSubmit={(e) => {
e.preventDefault();
sendReadCommand();
}}
>
<IconButton
disableRipple
onClick={() => {
setReadOpen(false);
setReadValue('');
}}
>
<PlayArrowIcon color="primary" sx={{ my: 2.5 }} />
</IconButton>
</Grid>
<TextField
value={readValue}
onChange={(e) => {
const value = e.target.value;
if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) {
return;
}
setReadValue(value);
}}
focused={true}
size="small"
label="Send Read command" // doesn't need translating - developer only
helperText="<deviceID> <typeID> [offset] [len]"
/>
</Box>
) : (
<>
{data.developer_mode && (
<IconButton onClick={sendReadCommand}>
<PlayArrowIcon color="primary" />
</IconButton>
)}
</>
)}
</Grid>

<Box
sx={{
backgroundColor: 'black',
Expand Down

0 comments on commit 0dfcd10

Please sign in to comment.