Skip to content

Commit

Permalink
ASM23 Live
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanLyon committed Jul 9, 2023
1 parent 5ef0681 commit 4bd7607
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 235 deletions.
2 changes: 1 addition & 1 deletion apps/keystone/admin/util/schedule/export-horaro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export async function exportHoraro(eventShortname: string) {
"Category",
"Runner",
"Platform",
"Donation Challenge",
"Donation Incentives",
"Twitter"
],
items: runData.event.runs.map(run => {
Expand Down
2 changes: 1 addition & 1 deletion apps/keystone/src/schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const User: Lists.User = list({
isRequired: false,
match: {
regex: /^(.{3,32}#[0-9]{4}|[a-z0-9._]{2,32})?$/,
explanation: `Discord user ID is invalid. Make sure its like "Clubwho#1337".`
explanation: `Discord user ID is invalid. Make sure its like "clubwho".`
}
}
}),
Expand Down
40 changes: 40 additions & 0 deletions apps/nextjs/components/ASMM/asmm-live.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@import "./colors.scss";
@import "./responsive.scss";

.asmmLive {
background-color: $primary;
color: $light-text;

display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 2rem;
gap: 0.5rem;

.miniTagline {
font-size: 1rem;
font-style: italic;
}

.mainAmount {
font-size: 1.5rem;

.total {
font-weight: bold;
font-size: 2rem;
}
}

.pledge {
font-size: 1.5rem;

.pledgeTotal {
font-weight: bold;
}
}

.learnMore {
margin: 1rem;
}
}
98 changes: 98 additions & 0 deletions apps/nextjs/components/ASMM/asmm-live.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import anime from "animejs";
import { RefObject, useEffect, useRef, useState } from "react";
import { useAuth } from "../auth";
import Button from "../Button/Button";

import styles from "./asmm-live.module.scss";

function useOnScreen(ref: RefObject<HTMLElement>) {
const [isIntersecting, setIntersecting] = useState(false);

let observer: IntersectionObserver | null = null;

useEffect(() => {
if (ref.current) {
observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting));
observer.observe(ref.current);
}
return () => observer?.disconnect();
}, []);

return isIntersecting;
}

const ASMMLive = () => {
const [pledgeAmount, setPledgeAmount] = useState(-1);
const [walkAmount, setWalkAmount] = useState(0);
const amountRef = useRef<HTMLSpanElement>(null);
const amountVisible = useOnScreen(amountRef);
const [amountAnimated, setAmountAnimated] = useState(false);
const auth = useAuth();

const username = auth.ready ? auth.sessionData?.username : undefined;

useEffect(() => {
if (auth.ready) {
fetch(`/api/asmm/total`).then((res) => {
res.json().then((data) => {
setWalkAmount(data.KmCount ?? 0);
});
});

fetch(`/api/asmm/pledge?username=${username}`, { method: "GET" }).then((res) => {
res.json().then((data) => {
setPledgeAmount(data.pledge);
});
});
}
}, [auth]);

useEffect(() => {
if (!amountAnimated && amountVisible) {
setAmountAnimated(true);
anime({
targets: amountRef.current,
innerText: [0, walkAmount],
easing: "easeOutQuart",
round: true,
delay: 100,
duration: 3000,
update: function (a) {
if (a.animations.length > 0 && amountRef.current) {
const value = a.animations[0].currentValue;
amountRef.current.innerText = value;
}
},
});
}
}, [amountVisible, amountAnimated]);

const amountToPay = Math.round((pledgeAmount * (walkAmount / 10) + Number.EPSILON) * 100) / 100;

const hasPledged = pledgeAmount > 10;

return (
<div className={styles.asmmLive}>
<span className={styles.miniTagline}>Australian Speedrun Marathon Marathon</span>
<span className={styles.mainAmount}>
The AusSpeedruns community has walked{" "}
<span ref={amountRef} className={styles.total}>
{walkAmount}
</span>{" "}
KM.
</span>
{hasPledged ? (
<span className={styles.pledge}>
You are pledging ${pledgeAmount} per 10km which totals to{" "}
<span className={styles.pledgeTotal}>${amountToPay}</span>
</span>
) : (
<span className={styles.learnMore}>
<Button colorScheme="secondary inverted" link="/asmm" actionText="Pledge and learn more" />
</span>
)}
</div>
);
};

export default ASMMLive;
68 changes: 44 additions & 24 deletions apps/nextjs/components/EventLive/EventLive.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@use 'base';
@import './colors.scss';
@import './responsive.scss';
@use "base";
@import "./colors.scss";
@import "./responsive.scss";

.eventLive {
color: $light-text;
background: $tgx-main;
background-image: url("../../styles/img/events/asgx/live-background.png");
background-size: contain;
background: $asm23-main;
background-image: url("../../styles/img/events/asm23/asm23-background.png");
background-size: cover;
padding: 2rem;

@include breakpoint($sm-zero-only) {
Expand Down Expand Up @@ -92,23 +92,37 @@
}
}

.columnLeft h4 {
text-align: left;
.columnLeft {
h3 {
text-align: left;
}

@include breakpoint($sm-zero-only) {
text-align: center;
h4 {
text-align: left;

@include breakpoint($sm-zero-only) {
text-align: center;
}
}
}

.columnMiddle h4 {
text-align: center;
.columnMiddle {
h4 {
text-align: center;
}
}

.columnRight h4 {
text-align: right;
.columnRight {
h3 {
text-align: right;
}

h4 {
text-align: right;

@include breakpoint($sm-zero-only) {
text-align: center;
@include breakpoint($sm-zero-only) {
text-align: center;
}
}
}
}
Expand All @@ -129,12 +143,12 @@

.twitchVideo,
.twitchChat {
border: 8px solid $tgx-red;
border: 8px solid $secondary;
box-sizing: border-box;
}

.twitchChat {
border-color: $tgx-yellow;
border-color: $secondary;
}

.twitchVideo {
Expand Down Expand Up @@ -170,8 +184,8 @@

.incentive {
.liveContent {
background-color: $tgx-main;
border: 2px solid $tgx-blue;
background-color: $primary;
border: 2px solid $secondary;
// width: 50%;

@include breakpoint($sm-zero-only) {
Expand All @@ -184,7 +198,7 @@
margin-top: 10px;
width: 80%;
height: 10px;
background: $tgx-rainbow-rotated;
background: $primary;
}
}

Expand All @@ -194,8 +208,8 @@
}

.liveContent {
background-color: $tgx-main;
border: 2px solid $tgx-green;
background-color: $asm23-main;
border: 2px solid $secondary;
font-size: 1.2rem;
width: fit-content;
word-break: break-all;
Expand All @@ -215,7 +229,7 @@
}

.subtitle {
color: $goc-accent;
color: $primary;
font-weight: bold;
margin-bottom: 0;
}
Expand All @@ -233,4 +247,10 @@
}
}
}

.crowdcontrol {
display: flex;
justify-content: center;
margin: 4rem 0;
}
}
Loading

0 comments on commit 4bd7607

Please sign in to comment.