Added room list filterig, fixed main blocks height issues
This commit is contained in:
parent
5f15d033b3
commit
df2873dc48
12
src/App.tsx
12
src/App.tsx
@ -19,6 +19,9 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
root: {
|
root: {
|
||||||
padding: theme.spacing(10, 2, 2, 2),
|
padding: theme.spacing(10, 2, 2, 2),
|
||||||
height: "100vh",
|
height: "100vh",
|
||||||
|
"& > div > *": {
|
||||||
|
height: "100%",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -44,8 +47,8 @@ export const App = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (planContainer.current)
|
if (planContainer.current)
|
||||||
setCanvasSize({
|
setCanvasSize({
|
||||||
w: planContainer.current.clientWidth,
|
w: planContainer.current.clientWidth - theme.spacing(2),
|
||||||
h: planContainer.current.clientHeight,
|
h: planContainer.current.clientHeight - theme.spacing(1),
|
||||||
});
|
});
|
||||||
}, [planContainer.current]);
|
}, [planContainer.current]);
|
||||||
|
|
||||||
@ -60,10 +63,7 @@ export const App = () => {
|
|||||||
</AppBar>
|
</AppBar>
|
||||||
<Grid className={classes.root} container>
|
<Grid className={classes.root} container>
|
||||||
<Grid ref={planContainer} item xs={9}>
|
<Grid ref={planContainer} item xs={9}>
|
||||||
<BuildingPlan
|
<BuildingPlan width={canvasSize.w} height={canvasSize.h} />
|
||||||
width={planContainer.current?.clientWidth}
|
|
||||||
height={planContainer.current?.clientHeight}
|
|
||||||
/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={3}>
|
<Grid item xs={3}>
|
||||||
<RoomList />
|
<RoomList />
|
||||||
|
@ -6,16 +6,26 @@ import {
|
|||||||
ListItemText,
|
ListItemText,
|
||||||
Typography,
|
Typography,
|
||||||
makeStyles,
|
makeStyles,
|
||||||
|
InputLabel,
|
||||||
|
Select,
|
||||||
|
Box,
|
||||||
} from "@material-ui/core";
|
} from "@material-ui/core";
|
||||||
|
import { ChangeEvent, useState } from "react";
|
||||||
|
|
||||||
import { useRoomContext } from "../context";
|
import { useRoomContext } from "../context";
|
||||||
|
import { FilterState } from "../types/ui";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
drawer: {
|
drawer: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
minHeight: "100%",
|
height: `calc(100% - ${theme.spacing(1)}px)`,
|
||||||
padding: theme.spacing(2),
|
padding: theme.spacing(2),
|
||||||
},
|
},
|
||||||
|
filterBox: {
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: theme.spacing(1),
|
||||||
|
},
|
||||||
indicatorContainer: {
|
indicatorContainer: {
|
||||||
minWidth: theme.spacing(3),
|
minWidth: theme.spacing(3),
|
||||||
},
|
},
|
||||||
@ -37,22 +47,54 @@ export const RoomList = () => {
|
|||||||
|
|
||||||
const { state } = useRoomContext();
|
const { state } = useRoomContext();
|
||||||
|
|
||||||
|
const [filter, setFilter] = useState(FilterState.ALL);
|
||||||
|
|
||||||
|
const handleFilterChange = (
|
||||||
|
event: ChangeEvent<{ name?: string; value: unknown }>
|
||||||
|
) => {
|
||||||
|
if (event.target && typeof event.target.value === "string")
|
||||||
|
setFilter(Number.parseInt(event.target.value));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper className={classes.drawer}>
|
<Paper className={classes.drawer}>
|
||||||
<Typography variant="h6">Class room avaliability status</Typography>
|
<Typography variant="h6">Class room avaliability status</Typography>
|
||||||
|
<Box className={classes.filterBox}>
|
||||||
|
<InputLabel htmlFor="filter">Filter</InputLabel>
|
||||||
|
|
||||||
|
<Select
|
||||||
|
native
|
||||||
|
value={filter}
|
||||||
|
onChange={handleFilterChange}
|
||||||
|
inputProps={{
|
||||||
|
name: "filter",
|
||||||
|
id: "filter",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value={FilterState.ALL}>All</option>
|
||||||
|
<option value={FilterState.FREE}>Free</option>
|
||||||
|
<option value={FilterState.BUSY}>Busy</option>
|
||||||
|
</Select>
|
||||||
|
</Box>
|
||||||
<List>
|
<List>
|
||||||
{state.map.map(({ title }, index) => (
|
{state.map.map(({ title }, index) => {
|
||||||
<ListItem disableGutters>
|
if (filter === FilterState.FREE && !state.char[index].free) return "";
|
||||||
<ListItemIcon className={classes.indicatorContainer}>
|
else if (filter === FilterState.BUSY && state.char[index].free)
|
||||||
<div
|
return "";
|
||||||
className={`${classes.indicator} ${
|
else
|
||||||
state.char[index].free ? classes.free : classes.busy
|
return (
|
||||||
}`}
|
<ListItem key={title} disableGutters>
|
||||||
/>
|
<ListItemIcon className={classes.indicatorContainer}>
|
||||||
</ListItemIcon>
|
<div
|
||||||
<ListItemText primary={title} />
|
className={`${classes.indicator} ${
|
||||||
</ListItem>
|
state.char[index].free ? classes.free : classes.busy
|
||||||
))}
|
}`}
|
||||||
|
/>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary={title} />
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</List>
|
</List>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
|
5
src/types/ui.ts
Normal file
5
src/types/ui.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export enum FilterState {
|
||||||
|
ALL,
|
||||||
|
FREE,
|
||||||
|
BUSY,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user