new card types, style changes, image preloading etc etc
diff --git a/Components/Card.js b/Components/Card.js
index e90a73f..c4a31c6 100644
--- a/Components/Card.js
+++ b/Components/Card.js
@@ -17,39 +17,99 @@
}
}
+ getButtonRow() {
+ return this.props.buttons ? this.props.buttons.map((button, i) => {
+ return <a
+ key={i}
+ className={Styles.button}
+ style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}}
+ href={button.link ? button.link : null}
+ onClick={button.onClick ? button.onClick : null}
+ target={button.newTab ? "_blank" : undefined}
+ rel="noreferrer">{button.text}
+ </a>
+ }) : null
+ }
+
+ getTitleBlock() {
+ let icons = null;
+ if (this.props.icon && this.props.icon[0].length > 1) {
+ icons = <div className={Styles.iconRow}>{this.props.icon.map((icon, i) => {
+ return <img key={i} alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes/${icon}.svg`} />
+ })}</div>
+ } else if (this.props.icon) {
+ icons = <img alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes/${this.props.icon}.svg`} />
+ } else if (this.props.wave) {
+ icons = <img alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes//${this.props.wave}.svg`} />
+ }
+ return <>{icons}</>;
+ }
+ getBand() {
+ if (this.props.band) {
+ return <div className={Styles.band} style={{
+ backgroundColor: `#${this.props.band.color ?? "F27878"}`,
+ bottom: this.props.buttons ? `calc(25% + 5px)` : "40px"
+ }}>
+ <p style={{color: "#" + (this.props.band.textColor ?? "FFFFFF")}}>{this.props.band.text ?? ""}</p>
+ </div>
+ }
+ }
+
render() {
- return (
- <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{
- margin: "0"
- }} onClick={this.handleClick}>
- <div className={Styles.backgroundGradient} style={{
- backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)`
- }} />
- <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} />
- <div className={Styles.panel} onClick={this.handleClick}>
- <div className={Styles.titleContainer}>
- <img alt="Project icon" className={Styles.image} src={"https://assets.clicks.codes/" + (this.props.icon ? this.props.icon : this.props.wave) + ".svg"} />
- <h1 className={Styles.title}>{this.props.title}</h1>
- </div>
- <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p>
- <div className={Styles.buttonLayout} onClick={this.showMessage}>
- {
- this.props.buttons ? this.props.buttons.map((button, i) => {
- return <a
- key={i}
- className={Styles.button}
- style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}}
- href={button.link ? button.link : null}
- onClick={button.onClick ? button.onClick : null}
- target={button.newTab ? "_blank" : undefined}
- rel="noreferrer">{button.text}
- </a>
- }) : null
- }
+ let overwriteAlign = {
+ "left": "flex-start",
+ "center": "center",
+ "right": "flex-end"
+ }[this.props.overwritePosition ?? "right"];
+ if (this.props.border) {
+ return (
+ <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null) + " " + Styles.dashed} style={{
+ margin: "0", opacity: `0`, boxShadow: "none", borderColor: `#${this.props.border}`
+ }}>
+ <div className={Styles.noPanel}>
+ <div className={Styles.titleContainer}>
+ {
+ (this.props.icon || this.props.wave)
+ ? <img alt="Project icon" className={Styles.image} src={"https://assets.clicks.codes/" + (this.props.icon ? this.props.icon : this.props.wave) + ".svg"} />
+ : null
+ }
+ <h1 className={Styles.title}>{this.props.title}</h1>
+ </div>
+ <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p>
+ {this.getBand()}
+ <div className={Styles.buttonLayout} onClick={this.showMessage} style={{
+ justifyContent: overwriteAlign
+ }}>
+ {this.getButtonRow()}
+ </div>
</div>
</div>
- </div>
- );
+ );
+ } else {
+ return (
+ <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{
+ margin: "0"
+ }} onClick={this.handleClick}>
+ <div className={Styles.backgroundGradient} style={{
+ backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)`
+ }} />
+ <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} />
+ <div className={Styles.panel} onClick={this.handleClick}>
+ <div className={Styles.titleContainer}>
+ { this.getTitleBlock() }
+ <h1 className={Styles.title}>{this.props.title}</h1>
+ </div>
+ <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p>
+ {this.getBand()}
+ <div className={Styles.buttonLayout} onClick={this.showMessage} style={{
+ justifyContent: overwriteAlign
+ }}>
+ {this.getButtonRow()}
+ </div>
+ </div>
+ </div>
+ );
+ }
}
}
diff --git a/Components/Header.js b/Components/Header.js
index 37418c5..54c4b5c 100644
--- a/Components/Header.js
+++ b/Components/Header.js
@@ -1,11 +1,38 @@
-import React, { useRef } from "react";
+import React, { useEffect, useState } from "react";
import Styles from '../styles/Components/header.module.css';
import NavStyles from '../styles/Components/navbar.module.css';
import Head from 'next/head';
-import { useColorMode } from "theme-ui";
import { useReward } from "react-rewards";
import ScrollContainer from 'react-indiana-drag-scroll'
+const positive = [
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f389.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f388.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f973.svg",
+];
+
+const negative = [
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f614.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f61e.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f613.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f625.svg",
+ "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f623.svg",
+];
+
+function preloadImage (src) {
+ return new Promise((resolve, reject) => {
+ const img = new Image()
+ img.onload = function() {
+ resolve(img)
+ }
+ img.onerror = img.onabort = function() {
+ reject(src)
+ }
+ img.src = src
+ })
+}
+
+
function Header(props) {
const [ clickTotal, setClickTotal ] = React.useState(0);
@@ -30,6 +57,22 @@
colors: ["#E5AB71"]
});
+ const all = positive.concat(negative)
+ const [imagesPreloaded, setImagesPreloaded] = useState(false)
+ useEffect(() => {
+ let isCancelled = false
+ async function effect() {
+ if (isCancelled) { return }
+ const imagesPromiseList = []
+ for (const i of all) { imagesPromiseList.push(preloadImage(i)) }
+ await Promise.all(imagesPromiseList)
+ if (isCancelled) { return }
+ setImagesPreloaded(true)
+ };
+ effect()
+ return () => { isCancelled = true }
+ }, [all])
+
function showSubBarWithUrl(url) {
const screenWidth = window.innerWidth;
let amount = screenWidth - 50;
@@ -39,14 +82,14 @@
{
Array.from(Array(amount)).map((i, index) => {
return (
- <a className={NavStyles.icon} key={index}><img alt="Clicks" className={NavStyles.icon} src={
+ <a className={NavStyles.icon} key={index}><img alt="" className={NavStyles.icon} src={
url[Math.floor(Math.random() * url.length)]
} /></a>
)
})
}
</div>,
- 5
+ 5, "center"
);
}
@@ -54,20 +97,10 @@
if (!isAnimating && !isDisappointmentAnimating && props.index) {
setClickTotal(clickTotal + 1);
if (clickTotal > 0 && Math.floor(Math.random() * 3) === 0) {
- showSubBarWithUrl([
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f614.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f61e.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f613.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f625.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f623.svg",
- ]);
+ showSubBarWithUrl(negative);
disappointment();
} else {
- showSubBarWithUrl([
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f389.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f388.svg",
- "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f973.svg",
- ]);
+ showSubBarWithUrl(positive);
reward();
}
}
@@ -78,6 +111,7 @@
margin: "0",
minHeight: props.fullscreen ? "calc(100vh - 42px)" : "calc(100vh - (4 * max(2em, 4vw)) - 1em)",
}} id={props.id ? props.id : null}>
+ {imagesPreloaded}
<div className={Styles.backgroundGradient} style={{
backgroundImage: `linear-gradient(69.44deg, #${props.gradient[0]} 0%, #${props.gradient[1]} 100%)`,
}} />