blob: 54c4b5cfd414db475c381339672d37b59fb2c4c8 [file] [log] [blame]
pineafanb7c79742022-11-06 18:08:36 +00001import React, { useEffect, useState } from "react";
pineafane0283a82022-02-13 10:05:56 +00002import Styles from '../styles/Components/header.module.css';
pineafanb18f0192022-10-27 22:08:36 +01003import NavStyles from '../styles/Components/navbar.module.css';
pineafan876af7d2021-10-14 20:31:21 +01004import Head from 'next/head';
pineafanff3d4522022-05-06 19:51:02 +01005import { useReward } from "react-rewards";
6import ScrollContainer from 'react-indiana-drag-scroll'
pineafana5ce9102021-09-02 17:21:31 +01007
pineafanb7c79742022-11-06 18:08:36 +00008const positive = [
9 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f389.svg",
10 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f388.svg",
11 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f973.svg",
12];
13
14const negative = [
15 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f614.svg",
16 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f61e.svg",
17 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f613.svg",
18 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f625.svg",
19 "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f623.svg",
20];
21
22function preloadImage (src) {
23 return new Promise((resolve, reject) => {
24 const img = new Image()
25 img.onload = function() {
26 resolve(img)
27 }
28 img.onerror = img.onabort = function() {
29 reject(src)
30 }
31 img.src = src
32 })
33}
34
35
pineafanff3d4522022-05-06 19:51:02 +010036function Header(props) {
37 const [ clickTotal, setClickTotal ] = React.useState(0);
38
39 const { reward: reward, isAnimating: isAnimating } = useReward('headerConfetti', 'confetti', {
40 elementSize: 10,
41 elementCount: 150,
42 startVelocity: 35,
43 lifetime: 300,
44 decay: 0.95,
45 spread: 170,
46 position: "absolute",
47 colors: ["#F27878", "#E5AB71", "#E5DC71", "#A1CC65", "#68D49E", "#71AFE5", "#6576CC", "#8D58B2", "#BF5E9F"]
48 });
49 const { reward: disappointment, isAnimating: isDisappointmentAnimating } = useReward('disappointmentConfetti', 'confetti', {
50 elementSize: 25,
51 elementCount: 1,
52 startVelocity: 25,
53 lifetime: 350,
54 decay: 0.95,
55 spread: 0,
56 position: "absolute",
57 colors: ["#E5AB71"]
58 });
59
pineafanb7c79742022-11-06 18:08:36 +000060 const all = positive.concat(negative)
61 const [imagesPreloaded, setImagesPreloaded] = useState(false)
62 useEffect(() => {
63 let isCancelled = false
64 async function effect() {
65 if (isCancelled) { return }
66 const imagesPromiseList = []
67 for (const i of all) { imagesPromiseList.push(preloadImage(i)) }
68 await Promise.all(imagesPromiseList)
69 if (isCancelled) { return }
70 setImagesPreloaded(true)
71 };
72 effect()
73 return () => { isCancelled = true }
74 }, [all])
75
pineafanb18f0192022-10-27 22:08:36 +010076 function showSubBarWithUrl(url) {
77 const screenWidth = window.innerWidth;
78 let amount = screenWidth - 50;
79 amount = Math.floor(amount / 42) - 1;
80 props.showSubBar(
81 <div className={NavStyles.container}>
82 {
83 Array.from(Array(amount)).map((i, index) => {
84 return (
pineafanb7c79742022-11-06 18:08:36 +000085 <a className={NavStyles.icon} key={index}><img alt="" className={NavStyles.icon} src={
pineafanb18f0192022-10-27 22:08:36 +010086 url[Math.floor(Math.random() * url.length)]
87 } /></a>
88 )
89 })
90 }
91 </div>,
pineafanb7c79742022-11-06 18:08:36 +000092 5, "center"
pineafanb18f0192022-10-27 22:08:36 +010093 );
94 }
95
pineafanff3d4522022-05-06 19:51:02 +010096 function confetti() {
97 if (!isAnimating && !isDisappointmentAnimating && props.index) {
98 setClickTotal(clickTotal + 1);
pineafan9babd752022-10-21 21:47:52 +010099 if (clickTotal > 0 && Math.floor(Math.random() * 3) === 0) {
pineafanb7c79742022-11-06 18:08:36 +0000100 showSubBarWithUrl(negative);
pineafanff3d4522022-05-06 19:51:02 +0100101 disappointment();
102 } else {
pineafanb7c79742022-11-06 18:08:36 +0000103 showSubBarWithUrl(positive);
pineafanff3d4522022-05-06 19:51:02 +0100104 reward();
105 }
106 }
pineafan9b1b68c2021-11-05 17:47:27 +0000107 }
pineafana5ce9102021-09-02 17:21:31 +0100108
pineafanff3d4522022-05-06 19:51:02 +0100109 return (
110 <div className={Styles.header} style={{
111 margin: "0",
112 minHeight: props.fullscreen ? "calc(100vh - 42px)" : "calc(100vh - (4 * max(2em, 4vw)) - 1em)",
113 }} id={props.id ? props.id : null}>
pineafanb7c79742022-11-06 18:08:36 +0000114 {imagesPreloaded}
pineafanff3d4522022-05-06 19:51:02 +0100115 <div className={Styles.backgroundGradient} style={{
116 backgroundImage: `linear-gradient(69.44deg, #${props.gradient[0]} 0%, #${props.gradient[1]} 100%)`,
117 }} />
118 <Head>
119 <title>{props.name}</title>
120
121 <meta name="apple-mobile-web-app-capable" content="yes" />
122 <meta name="mobile-web-app-capable" content="yes" />
123 <meta name="viewport" content="width=device-width, minimal-ui" />
124
125 <meta name="title" content={props.name} />
126 <meta name="og:title" content={props.name} />
127 <meta name="description" content={props.embedDescription ? props.embedDescription : props.subtext} />
128 <meta name="og:description" content={props.embedDescription ? props.embedDescription : props.subtext} />
129 <meta name="author" content="Clicks" />
130 <meta name="og:author" content="Clicks" />
131 <meta name="image" content={props.embedImage} />
132 <meta name="og:image" content={props.embedImage} />
133
134 <meta name="theme-color" content={"#000000"} />
135 <meta name="og-color" content={"#" + props.gradient[1]} />
136 <meta name="msapplication-TileColor" content={"#000000"} />
137 </Head>
138 <img draggable={false} alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/${props.wave}.svg`} />
pineafand94d40e2022-10-23 19:55:29 +0100139 <div id="headerConfetti" />
140 <div id="disappointmentConfetti" />
pineafanff3d4522022-05-06 19:51:02 +0100141 <div className={Styles.panel}>
142 <div className={Styles.titleContainer}>
143 <div onClick={confetti}>
pineafana5ce9102021-09-02 17:21:31 +0100144 {
pineafanb18f0192022-10-27 22:08:36 +0100145 props.customImage ?
pineafanff3d4522022-05-06 19:51:02 +0100146 <img height="64px" width="64px" alt={props.name} className={Styles.headerImage} style={{borderRadius: props.roundImage ? "100vw" : "0"}} src={props.customImage} />
147 : <></>
pineafana5ce9102021-09-02 17:21:31 +0100148 }
149 </div>
pineafanff3d4522022-05-06 19:51:02 +0100150 <h1 className={Styles.title}>{props.name}</h1>
pineafana5ce9102021-09-02 17:21:31 +0100151 </div>
pineafanff3d4522022-05-06 19:51:02 +0100152 <p className={Styles.subtext + " " + (props.buttons.length ? Styles.subtextExtra : null)}>{props.subtext}</p>
153 <a href="#skipNav" id="skipNav" style={{display: "none"}} />
154 { props.buttons.length ?
155 <div className={Styles.buttonOverflow}>
156 <img className={Styles.indicator + " " + Styles.leftArrow} draggable={false} alt="" src={`https://assets.clicks.codes/web/icons/arrow.svg`}/>
157 <ScrollContainer
158 vertical={false}
159 horizontal={true}
160 hideScrollbars={true}
161 nativeMobileScroll={true}
162 style={{borderRadius: "10px", height: "fit-content"}}
163 >
164 <div className={Styles.buttonLayout}>
165 {
166 props.buttons ? props.buttons.map((button, index) => {
167 return <a
168 key={index}
169 className={Styles.button}
170 style={{ backgroundColor: `#${button.color}`, color: `#${button.buttonText}` }}
171 href={button.link}
pineafan25b33332022-10-29 22:16:35 +0100172 onClick={
173 button.onClick ? button.onClick : () => { if (button.id) { props.callback(button.id) } }}
pineafanff3d4522022-05-06 19:51:02 +0100174 target={button.target ? "_blank" : null}
175 draggable={false}
176 rel="noreferrer">
177 {button.text}
178 </a>
179 }) : null
180 }
181 </div>
182 </ScrollContainer>
183 <img className={Styles.indicator + " " + Styles.rightArrow} draggable={false} alt="" src={`https://assets.clicks.codes/web/icons/arrow.svg`}/>
184 </div> : <></>
185 }
pineafana5ce9102021-09-02 17:21:31 +0100186 </div>
pineafanff3d4522022-05-06 19:51:02 +0100187 </div>
188 )
pineafana5ce9102021-09-02 17:21:31 +0100189}
190
191export default Header;