1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useEffect , useRef , useState } from "react" ;
2
2
import Link from "next/link" ;
3
- import { Flex , Text } from "@chakra-ui/core" ;
3
+ import { Box , CloseButton , Flex , Text , useToast } from "@chakra-ui/core" ;
4
4
import styled from "@emotion/styled" ;
5
5
import Socials from "@/components/Socials" ;
6
6
import Logo from "../svgs/logo.svg" ;
@@ -11,9 +11,11 @@ import {
11
11
BodyPrimary ,
12
12
Headline ,
13
13
LinkPrimary ,
14
+ LinkSecondary ,
14
15
} from "@/components/core/Text" ;
15
16
import { ButtonPrimary } from "@/components/core/Button" ;
16
17
import { WidthWrapper } from "@/components/core/Layout" ;
18
+ import { useRouter } from "next/router" ;
17
19
18
20
const minHeights = [ 750 , 750 , 800 ] ;
19
21
@@ -25,13 +27,28 @@ const FlexFullView = styled(Flex)`
25
27
background-position: center bottom;
26
28
` ;
27
29
30
+ const HackaCommToast = styled ( Flex ) `
31
+ background: black;
32
+ color: white;
33
+ border-radius: 15px 15px 0 0;
34
+ ` ;
35
+
28
36
export default function Hero ( ) : React . ReactElement {
29
37
const [ heightProp , setHeightProp ] = useState (
30
38
minHeights . map ( ( minHeight ) => `max(100vh, ${ minHeight } px)` )
31
39
) ;
32
40
const actualWidth = useScreenWidth ( ) ;
33
41
const [ currentWidth , setCurrentWidth ] = useState ( 0 ) ;
34
42
const setNavOverlayOpen = useStore ( ( state ) => state . setNavOverlayOpen ) ;
43
+ const toast = useToast ( ) ;
44
+ const router = useRouter ( ) ;
45
+
46
+ const toastRefs = useRef < ( ( ) => void ) [ ] > ( [ ] ) ;
47
+
48
+ const closeToasts = ( ) => {
49
+ toastRefs . current . forEach ( ( cb ) => cb ( ) ) ;
50
+ toastRefs . current = [ ] ;
51
+ } ;
35
52
36
53
useEffect ( ( ) => {
37
54
const updateHeight = ( ) => {
@@ -49,6 +66,57 @@ export default function Hero(): React.ReactElement {
49
66
}
50
67
} , [ actualWidth , currentWidth , setNavOverlayOpen ] ) ;
51
68
69
+ useEffect ( ( ) => {
70
+ const handlePageSwitch = ( route : string ) => {
71
+ if ( router . pathname !== route ) {
72
+ router . push ( route ) ;
73
+ } else {
74
+ setNavOverlayOpen ( false ) ;
75
+ }
76
+ } ;
77
+
78
+ const hackaCommToast = setTimeout ( ( ) => {
79
+ toast ( {
80
+ position : "bottom" ,
81
+ duration : null ,
82
+ isClosable : true ,
83
+ render : ( { onClose } ) => {
84
+ toastRefs . current . push ( onClose ) ;
85
+
86
+ return (
87
+ < >
88
+ < HackaCommToast p = { 3 } >
89
+ < Box >
90
+ Check out HackaComm: a brand-new hackathon brought to you by
91
+ CUSEC and RBC!{ " " }
92
+ < LinkSecondary
93
+ onClick = { ( ) => {
94
+ handlePageSwitch ( "/hackacomm" ) ;
95
+ closeToasts ( ) ;
96
+ } }
97
+ >
98
+ Click to learn more.
99
+ </ LinkSecondary >
100
+ </ Box >
101
+ < Box alignSelf = "center" >
102
+ < CloseButton
103
+ size = "lg"
104
+ _focus = { { } }
105
+ onClick = { ( ) => {
106
+ closeToasts ( ) ;
107
+ } }
108
+ />
109
+ </ Box >
110
+ </ HackaCommToast >
111
+ </ >
112
+ ) ;
113
+ } ,
114
+ } ) ;
115
+ } , 1000 ) ;
116
+
117
+ return ( ) => clearTimeout ( hackaCommToast ) ;
118
+ } , [ router , setNavOverlayOpen , toast ] ) ;
119
+
52
120
return (
53
121
< FlexFullView
54
122
height = { heightProp }
0 commit comments