Merge branch 'only-show-avaliable'
This commit is contained in:
@@ -4,6 +4,9 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
Snackbar,
|
Snackbar,
|
||||||
Button,
|
Button,
|
||||||
|
FormGroup,
|
||||||
|
FormControlLabel,
|
||||||
|
Checkbox,
|
||||||
Stack,
|
Stack,
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
@@ -36,6 +39,8 @@ export default function Time(props) {
|
|||||||
const [token, setToken] = useState("");
|
const [token, setToken] = useState("");
|
||||||
const [stats, setStats] = useState({});
|
const [stats, setStats] = useState({});
|
||||||
|
|
||||||
|
const [onlyShowAvaliable, setOnlyShowAvaliable] = useState(true);
|
||||||
|
|
||||||
const [modifyTime, setModifyTime] = useState({});
|
const [modifyTime, setModifyTime] = useState({});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -136,8 +141,6 @@ export default function Time(props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const refreshRanges = () => {
|
const refreshRanges = () => {
|
||||||
getLimit();
|
|
||||||
getStats();
|
|
||||||
fetch(`${prefix}/api/time/ranges`)
|
fetch(`${prefix}/api/time/ranges`)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -219,11 +222,17 @@ export default function Time(props) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshRanges();
|
refreshRanges();
|
||||||
|
getLimit();
|
||||||
|
getStats();
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
|
getLimit();
|
||||||
|
getStats();
|
||||||
|
if (!onlyShowAvaliable) {
|
||||||
refreshRanges();
|
refreshRanges();
|
||||||
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, [onlyShowAvaliable]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -324,6 +333,17 @@ export default function Time(props) {
|
|||||||
>
|
>
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
<FormGroup>
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
checked={onlyShowAvaliable}
|
||||||
|
onChange={(e) => setOnlyShowAvaliable(e.target.checked)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label="仅显示空余"
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
<Typography>
|
<Typography>
|
||||||
当前每人数量上限: {limit}
|
当前每人数量上限: {limit}
|
||||||
<br />
|
<br />
|
||||||
@@ -340,7 +360,11 @@ export default function Time(props) {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{ranges.map((range) => (
|
{ranges.map((range) => {
|
||||||
|
if (onlyShowAvaliable && range.username !== "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return (
|
||||||
<TableRow key={range.id}>
|
<TableRow key={range.id}>
|
||||||
<TableCell>{range.name}</TableCell>
|
<TableCell>{range.name}</TableCell>
|
||||||
<TableCell>{range.range}</TableCell>
|
<TableCell>{range.range}</TableCell>
|
||||||
@@ -376,7 +400,8 @@ export default function Time(props) {
|
|||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user