1
1
"use client" ;
2
2
3
- import SearchIcon from "@mui/icons-material/Search" ;
4
- import { Button } from "@mui/material" ;
5
- import Container from "@mui/material/Container" ;
3
+ import { Alert , Button , Typography } from "@mui/material" ;
6
4
import Stack from "@mui/material/Stack" ;
7
5
import { styled } from "@mui/system" ;
6
+ import AllRoomsSearchBar from "components/AllRoomsSearchBar" ;
8
7
import useAllRooms from "hooks/useAllRooms" ;
9
8
import { useMemo , useState } from "react" ;
10
9
import { useSelector } from "react-redux" ;
@@ -13,18 +12,28 @@ import { selectFilters } from "redux/filtersSlice";
13
12
import AllRoomsFilter from "../../components/AllRoomsFilter" ;
14
13
import Room from "../../components/AllRoomsRoom" ;
15
14
import RoomList from "../../components/AllRoomsRoomList" ;
16
- import AllRoomsSearchBar from "../../components/AllRoomsSearchBar" ;
17
15
18
16
export default function Page ( ) {
19
17
const filters = useSelector ( selectFilters ) ;
20
18
const { rooms, isValidating } = useAllRooms ( filters ) ;
21
- const centred = isValidating ? "center" : "default" ;
22
- // const displayMobile = useMediaQuery(useTheme().breakpoints.down("md"));
23
19
const [ visibleRooms , setVisibleRooms ] = useState ( 20 ) ;
24
20
25
21
const roomsDisplay = useMemo ( ( ) => {
26
22
if ( ! rooms ) return ;
27
- const roomEntries = Object . entries ( rooms ) . slice ( 0 , visibleRooms ) ;
23
+ const availableRooms = Object . entries ( rooms ) . filter (
24
+ ( room ) => room [ 1 ] . status !== "busy"
25
+ ) ;
26
+
27
+ if ( availableRooms . length === 0 ) {
28
+ return (
29
+ < Alert severity = "error" sx = { { marginTop : 2 } } >
30
+ No rooms satisfying current filters
31
+ </ Alert >
32
+ ) ;
33
+ }
34
+
35
+ const roomEntries = availableRooms . slice ( 0 , visibleRooms ) ;
36
+
28
37
return roomEntries . map ( ( [ roomId , { name, status, endtime } ] ) => {
29
38
return (
30
39
< Room
@@ -45,57 +54,42 @@ export default function Page() {
45
54
const totalRooms = rooms ? Object . keys ( rooms ) . length : 0 ;
46
55
47
56
return (
48
- < Container >
49
- < Stack >
50
- < StyledSearchBar >
51
- < AllRoomsSearchBar />
52
- < SearchIcon />
53
- </ StyledSearchBar >
57
+ < Stack alignItems = "center" >
58
+ < Stack marginTop = { 4 } paddingX = { 1 } >
59
+ < Typography fontWeight = "bold" variant = "h4" >
60
+ All Free Rooms
61
+ </ Typography >
62
+ < Typography marginTop = { 1 } variant = "body1" >
63
+ Not looking for a specific building? See all free rooms in this easy
64
+ to search list!
65
+ </ Typography >
54
66
< StyledBody >
55
67
< AllRoomsFilter filters = { filters } />
56
68
< RoomList isValidating = { isValidating } >
69
+ < AllRoomsSearchBar />
57
70
{ roomsDisplay }
58
71
{ visibleRooms < totalRooms && (
59
- < Button variant = "contained" onClick = { handleLoadMore } >
72
+ < Button
73
+ variant = "outlined"
74
+ onClick = { handleLoadMore }
75
+ sx = { { marginY : 1 } }
76
+ >
60
77
Load More Rooms
61
78
</ Button >
62
79
) }
63
80
</ RoomList >
64
81
</ StyledBody >
65
82
</ Stack >
66
- </ Container >
83
+ </ Stack >
67
84
) ;
68
85
}
69
86
70
- const StyledSearchBar = styled ( Stack ) ( ( { theme } ) => ( {
71
- flexDirection : "row" ,
72
- minWidth : "332px" ,
73
- borderRadius : 8 ,
74
- borderStyle : "solid" ,
75
- borderWidth : "thin" ,
76
- borderColor : theme . palette . text . secondary ,
77
- margin : theme . spacing ( 6 , 6.25 , 3.75 ) ,
78
- padding : theme . spacing ( 1.25 ) ,
79
- justifyContent : "space-between" ,
80
- alignItems : "center" ,
81
- [ theme . breakpoints . down ( "xs" ) ] : {
82
- spacing : 1 ,
83
- margin : theme . spacing ( 3 , 6.25 , 2 ) ,
84
- } ,
85
- [ theme . breakpoints . up ( "xs" ) ] : {
86
- spacing : 2 ,
87
- } ,
88
- } ) ) ;
89
-
90
87
const StyledBody = styled ( Stack ) ( ( { theme } ) => ( {
91
88
flexDirection : "row" ,
92
- // flexWrap: "wrap",
93
- margin : theme . spacing ( 0 , 4.25 ) ,
94
- padding : theme . spacing ( 2 ) ,
95
89
justifyContent : "space-between" ,
96
90
gap : theme . spacing ( 2 ) ,
97
- [ theme . breakpoints . down ( "md" ) ] : {
91
+ marginTop : "30px" ,
92
+ [ theme . breakpoints . down ( "sm" ) ] : {
98
93
flexDirection : "column" ,
99
- padding : theme . spacing ( 0 , 2 ) ,
100
94
} ,
101
95
} ) ) ;
0 commit comments