improved read cmd dialog

This commit is contained in:
proddy
2024-10-21 23:28:10 +02:00
parent 26aa55346a
commit 0dfcd10505

View File

@@ -91,7 +91,7 @@ const SystemLog = () => {
}); });
const { send } = useRequest( 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 immediate: false
} }
@@ -176,10 +176,12 @@ const SystemLog = () => {
setReadOpen(!readOpen); setReadOpen(!readOpen);
return; return;
} }
void send(readValue);
console.log('send read command', readValue); // TODO remove if (readValue.split(' ').filter((word) => word !== '').length > 1) {
setReadOpen(false); void send(readValue);
setReadValue(''); setReadOpen(false);
setReadValue('');
}
}; };
const content = () => { const content = () => {
@@ -271,31 +273,50 @@ const SystemLog = () => {
)} )}
</Grid> </Grid>
{data.developer_mode && ( {readOpen ? (
<Grid> <Box
{readOpen && ( component="form"
<TextField sx={{ display: 'flex', alignItems: 'flex-end' }}
value={readValue} onSubmit={(e) => {
onChange={(event) => { e.preventDefault();
const value = event.target.value; sendReadCommand();
if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) { }}
return; >
} <IconButton
setReadValue(value); disableRipple
}} onClick={() => {
focused={true} setReadOpen(false);
label="Send Read command" setReadValue('');
variant="outlined" }}
helperText="<deviceID> <type ID> [offset] [length]" >
size="small" <PlayArrowIcon color="primary" sx={{ my: 2.5 }} />
/>
)}
<IconButton onClick={sendReadCommand}>
<PlayArrowIcon color="primary" />
</IconButton> </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> </Grid>
<Box <Box
sx={{ sx={{
backgroundColor: 'black', backgroundColor: 'black',