Skip to content

Commit

Permalink
Add a new feature to reload the task list automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoichiro committed Nov 17, 2023
1 parent 15bc284 commit 0468a0c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/actions/catalog.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ export const catalogActionsThunk = {
dispatch: ThunkDispatch<RootState, undefined, ActionTypes>,
getState: () => RootState
) => {
dispatch(CatalogAppActions.updatePhase('processing'));
dispatch(StorageActions.updateFirmwareBuildingTasks([]));
const { storage } = getState();
const result = await storage.instance!.fetchFirmwareBuildingTasks(
Expand All @@ -328,7 +327,6 @@ export const catalogActionsThunk = {
return;
}
dispatch(StorageActions.updateFirmwareBuildingTasks(result.value));
dispatch(CatalogAppActions.updatePhase('build'));
},

deleteFirmwareBuildingTask:
Expand Down
52 changes: 50 additions & 2 deletions src/components/catalog/keyboard/build/CatalogBuild.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import './CatalogBuild.scss';
import {
CatalogBuildActionsType,
Expand All @@ -10,10 +10,12 @@ import {
Card,
CardActions,
CardContent,
FormControlLabel,
Paper,
Step,
StepLabel,
Stepper,
Switch,
Tab,
Table,
TableBody,
Expand Down Expand Up @@ -51,6 +53,42 @@ export default function CatalogBuild(props: CatalogBuildProps) {
useState<boolean>(false);
const [targetDeleteTask, setTargetDeleteTask] =
useState<IFirmwareBuildingTask | null>(null);
const [autoReload, setAutoReload] = useState<boolean>(false);
const autoStopRef = useRef<number | null>(null);

const autoReloadRef = useRef<number | null>(null);
useEffect(() => {
if (autoReload) {
if (autoReloadRef.current !== null) return;
const reload = () => {
props.updateFirmwareBuildingTasks!(props.definitionDocument!.id);
autoReloadRef.current = window.setTimeout(reload, 30000);
};
reload();
autoStopRef.current = window.setTimeout(() => {
setAutoReload(false);
}, 180000);
} else {
if (autoReloadRef.current !== null) {
window.clearTimeout(autoReloadRef.current);
autoReloadRef.current = null;
}
if (autoStopRef.current !== null) {
window.clearTimeout(autoStopRef.current);
autoStopRef.current = null;
}
}
return () => {
if (autoReloadRef.current !== null) {
window.clearTimeout(autoReloadRef.current);
autoReloadRef.current = null;
}
if (autoStopRef.current !== null) {
window.clearTimeout(autoStopRef.current);
autoStopRef.current = null;
}
};
}, [autoReload]);

const createDefaultParameterValues = (
files: IBuildableFirmwareFile[]
Expand Down Expand Up @@ -200,13 +238,23 @@ export default function CatalogBuild(props: CatalogBuildProps) {
}
};

const onChangeAutoReload = (event: React.ChangeEvent<HTMLInputElement>) => {
setAutoReload(event.target.checked);
};

return (
<div className="catalog-build-container">
<React.Fragment>
<Paper sx={{ p: '16px', mb: '32px' }}>
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
<FormControlLabel
control={
<Switch checked={autoReload} onChange={onChangeAutoReload} />
}
label="Auto"
/>
<Button
variant="text"
variant="outlined"
sx={{ mr: '32px' }}
onClick={onClickReload}
disabled={!props.signedIn}
Expand Down

0 comments on commit 0468a0c

Please sign in to comment.