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;
} }
if (readValue.split(' ').filter((word) => word !== '').length > 1) {
void send(readValue); void send(readValue);
console.log('send read command', readValue); // TODO remove
setReadOpen(false); setReadOpen(false);
setReadValue(''); setReadValue('');
}
}; };
const content = () => { const content = () => {
@@ -271,31 +273,50 @@ const SystemLog = () => {
)} )}
</Grid> </Grid>
{data.developer_mode && ( {readOpen ? (
<Grid> <Box
{readOpen && ( 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>
<TextField <TextField
value={readValue} value={readValue}
onChange={(event) => { onChange={(e) => {
const value = event.target.value; const value = e.target.value;
if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) { if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) {
return; return;
} }
setReadValue(value); setReadValue(value);
}} }}
focused={true} focused={true}
label="Send Read command"
variant="outlined"
helperText="<deviceID> <type ID> [offset] [length]"
size="small" size="small"
label="Send Read command" // doesn't need translating - developer only
helperText="<deviceID> <typeID> [offset] [len]"
/> />
)} </Box>
) : (
<>
{data.developer_mode && (
<IconButton onClick={sendReadCommand}> <IconButton onClick={sendReadCommand}>
<PlayArrowIcon color="primary" /> <PlayArrowIcon color="primary" />
</IconButton> </IconButton>
</Grid> )}
</>
)} )}
</Grid> </Grid>
<Box <Box
sx={{ sx={{
backgroundColor: 'black', backgroundColor: 'black',