@@ -5,18 +5,15 @@ import {
55 Card ,
66 CardBody ,
77 CardHeader ,
8- Drawer ,
9- DrawerBody ,
10- DrawerContent ,
11- DrawerFooter ,
12- DrawerHeader ,
138 Heading ,
149 HStack ,
1510 Stack ,
1611 StackDivider ,
12+ Text ,
1713 useDisclosure ,
1814 useToast ,
1915} from "@chakra-ui/react" ;
16+ import styles from "./home.module.css" ;
2017
2118import { Logs } from "../components/features/logs/logs.tsx" ;
2219import { Map } from "../components/features/map/map.tsx" ;
@@ -27,6 +24,16 @@ import {Locations} from "../types/location.ts";
2724import { LocationSelect } from "../components/common/locationSelect/locationSelect.tsx" ;
2825import { useLogs } from "../hooks/useLogs.tsx" ;
2926import { NotificationResponse } from "../types/notifications.ts" ;
27+ import { useGetRequestArrival } from "../hooks/useGetRequestArrival.tsx" ;
28+ import Countdown , { CountdownRenderProps } from "react-countdown" ;
29+
30+ const countdownRenderer = ( { minutes, seconds, completed, driverName} : CountdownRenderProps & { driverName : string } ) => {
31+ if ( completed ) {
32+ return < Text > { driverName } arrived</ Text > ;
33+ } else {
34+ return < Text as = "b" > The driver { driverName } will arrive in { minutes . toString ( ) . padStart ( 2 , "0" ) } :{ seconds . toString ( ) . padStart ( 2 , "0" ) } </ Text > ;
35+ }
36+ } ;
3037
3138export const HomePage = ( ) => {
3239 const session = useSession ( ) ;
@@ -35,6 +42,7 @@ export const HomePage = () => {
3542
3643 const [ selectedLocations , setSelectedLocations ] = useState ( { pickupId : - 1 , dropoffId : - 1 } ) ;
3744 const { logs, addNewLog, addErrorEntry, addInformationEntry} = useLogs ( ) ;
45+ const lastRequestedDrive = useGetRequestArrival ( logs ) ;
3846
3947 const logsModal = useDisclosure ( ) ;
4048 const toast = useToast ( ) ;
@@ -179,39 +187,41 @@ export const HomePage = () => {
179187 >
180188 Request Ride
181189 </ Button >
182- { /*<Text color='gray' mt={4}>The distance between the two points is 40 miles</Text>*/ }
183190 </ Box >
184191 </ Stack >
185192 </ CardBody >
186193 </ Card >
194+
195+ { lastRequestedDrive . driverArrival &&
196+ < HStack divider = { < StackDivider /> } spacing = '4' justifyContent = "center" alignItems = "center"
197+ bg = "teal.200" p = "1rem" maxW = { 600 } borderRadius = { 4 } >
198+ < Countdown
199+ date = { new Date ( Date . now ( ) ) . setSeconds ( lastRequestedDrive . driverArrival ) }
200+ renderer = { ( props ) => countdownRenderer ( {
201+ ...props ,
202+ driverName : lastRequestedDrive . driverName
203+ } ) }
204+ />
205+ </ HStack > }
187206 </ Stack >
188207 < Stack flexGrow = { 1 } justifyContent = 'space-between' w = '50%' h = '100%' maxH = { '900px' } >
189- < Drawer
190- isOpen = { logsModal . isOpen }
191- placement = 'right'
192- onClose = { ( ) => {
193- } }
194- size = "lg"
195- trapFocus = { false }
196- blockScrollOnMount = { false }
197- variant = "aside"
198- >
199- < DrawerContent >
200- < DrawerHeader > Notifications logs</ DrawerHeader >
201-
202- < DrawerBody >
203- < Logs logs = { logs } />
204- </ DrawerBody >
205-
206- < DrawerFooter >
207- < Button variant = 'outline' mr = { 3 } onClick = { logsModal . onClose } >
208- Close
209- </ Button >
210- </ DrawerFooter >
211- </ DrawerContent >
212- </ Drawer >
208+ < div className = { `${ styles . drawer } ${ logsModal . isOpen ? styles . open : '' } ` } >
209+ < div className = { styles . drawerHeader } >
210+ < Heading size = "md" > Notifications Logs</ Heading >
211+ </ div >
212+ < div className = { styles . drawerBody } >
213+ < Logs logs = { logs } />
214+ </ div >
215+ < div className = { styles . drawerFooter } >
216+ < Button variant = "outline" onClick = { logsModal . onClose } >
217+ Close
218+ </ Button >
219+ </ div >
220+ </ div >
221+
213222 < Stack flexGrow = { 1 } flexShrink = { 1 } >
214- < Map dropoffLocationID = { selectedLocations . dropoffId } pickupLocationID = { selectedLocations . pickupId } />
223+ < Map dropoffLocationID = { selectedLocations . dropoffId }
224+ pickupLocationID = { selectedLocations . pickupId } />
215225 </ Stack >
216226 < Button variant = 'outline' size = "sm" onClick = { logsModal . onToggle } > Show Logs</ Button >
217227 </ Stack >
0 commit comments