Skip to content

Commit 9b32f40

Browse files
committed
mobile changes, today changes
1 parent faec291 commit 9b32f40

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

src/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ function App() {
44
return (
55
<div className="p-4">
66
<main className="flex items-center justify-center">
7-
<div className="w-[74rem]">
8-
<h1 className="text-7xl font-bold mb-16 mt-5">Music Monday</h1>
7+
<div className="max-md:flex max-md:flex-col max-md:items-center w-[50rem] xl:w-[74rem]">
8+
<h1 className="text-6xl md:text-7xl font-bold mb-16 mt-5">
9+
Music Monday
10+
</h1>
911
<PaneGrid />
1012
</div>
1113
</main>

src/components/PaneGrid.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ const PaneGrid = () => {
1616
})();
1717
}, []);
1818
return (
19-
<div>
19+
<div className="">
2020
<MostRecent />
21-
<div className="flex gap-4 flex-wrap">
21+
<div className="flex gap-4 flex-wrap max-xl:hidden">
2222
<Leaderboard entries={entries} />
2323
<WinHistory entries={entries} />
2424
<LastSubmission entries={entries} />
2525
<WebPane entries={entries} />
2626
</div>
27+
<div className="flex gap-4 max-md:flex-col md:flex-wrap max-lg:justify-center max-md:items-center xl:hidden">
28+
<Leaderboard entries={entries} />
29+
<LastSubmission entries={entries} />
30+
<WebPane entries={entries} />
31+
<WinHistory entries={entries} />
32+
</div>
2733
</div>
2834
);
2935
};

src/components/Panes/MostRecent.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ const ORDER = ["Souren", "Kevin", "Ken", "Artom", "Andrew"];
33
const MostRecent = () => {
44
const nextMonday = new Date();
55
nextMonday.setHours(0, 0, 0, 0);
6-
nextMonday.setDate(
7-
nextMonday.getDate() + ((8 - nextMonday.getDay()) % 7 || 7)
8-
);
6+
7+
// lets check if today is monday?
8+
const isMonday = nextMonday.getDay() === 1;
9+
if (!isMonday) {
10+
nextMonday.setDate(
11+
nextMonday.getDate() + ((8 - nextMonday.getDay()) % 7 || 7)
12+
);
13+
}
914
const formattedMonday = new Intl.DateTimeFormat("en-US", {
1015
month: "short",
1116
day: "numeric",
@@ -20,15 +25,18 @@ const MostRecent = () => {
2025
const nextJudgeIdx = weeksDiff % ORDER.length;
2126

2227
return (
23-
<section className="flex gap-10 items-center mb-5">
28+
<section className="flex max-md:flex-col gap-10 items-center mb-5">
2429
<div className="">
2530
<h2 className="text-md">Upcoming Music Monday</h2>
26-
<p className="text-2xl font-bold">
27-
{formattedMonday} (#{weeksDiff + 21})
31+
<p className="text-2xl font-bold flex items-center">
32+
{formattedMonday} (#{weeksDiff + 21}){" "}
33+
{isMonday && (
34+
<span className="text-xs m-auto text-yellow-300">today!</span>
35+
)}
2836
</p>
2937
</div>
3038
<div className="">
31-
<h2 className="text-md">Upcoming Judge</h2>
39+
<h2 className="text-md">{isMonday ? "Today's" : "Upcoming"} Judge</h2>
3240
<div className="flex">
3341
{ORDER.map((x, i) => {
3442
return (

src/components/Panes/WebPane.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const WebPane = ({ entries }: GenericPaneProps) => {
88
title="Who votes who?"
99
description="Number of times a pair has voted for eachother"
1010
>
11-
<Web entries={entries} />
11+
<div className="max-md:w-96 flex items-center justify-center">
12+
<div className="max-md:scale-75">
13+
<Web entries={entries} />
14+
</div>
15+
</div>
1216
</Pane>
1317
);
1418
};

src/components/Panes/WinHistory.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import type { Entry, GenericPaneProps, Name } from "../../types";
22
import Pane from "../Pane";
33
import { Tooltip } from "react-tooltip";
44
import SpotifyEmbed from "../SpotifyEmbed";
5+
import { useWindowDimension } from "../../script";
56

67
const SONG_TOOLTIP = "song-tooltip";
78

89
const WinHistory = ({ entries }: GenericPaneProps) => {
10+
const [w, _] = useWindowDimension();
11+
const MAX = w < 768 ? 7 : 30;
912
let history: (Entry | "")[] = entries.filter((v) => v.winner);
1013
if (history.length < 30) {
1114
history = (Array.from({ length: 30 - history.length }).fill("") as ""[])
@@ -28,14 +31,14 @@ const WinHistory = ({ entries }: GenericPaneProps) => {
2831
Souren: "bg-yellow-600",
2932
};
3033
return (
31-
<Pane title="Winner History" description="Last 30 weeks">
34+
<Pane title="Winner History" description={`Last ${MAX} weeks`}>
3235
<div className="flex gap-x-2 mb-4 -mt-2">
3336
{(Object.keys(colorMap) as (Name | "")[]).map((v) => {
3437
return <p className={`${colorMap[v]} font-bold`}>{v}</p>;
3538
})}
3639
</div>
3740
<div className="flex">
38-
{history.map((v, i) => {
41+
{history.slice(-MAX).map((v, i) => {
3942
if (v === "") {
4043
return <div className="w-4 h-48 bg-zinc-700 mx-1 rounded-sm" />;
4144
}

src/script.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Papa from "papaparse";
22
import csvText from "./winners.csv?raw";
33
import type { Entry } from "./types";
4+
import { useEffect, useState } from "react";
45

56
export const processFile = async (): Promise<Entry[]> => {
67
const result = Papa.parse(csvText, { header: true, skipEmptyLines: true });
@@ -20,3 +21,30 @@ export const linkToEmbedLink = (link: string) => {
2021

2122
return `https://open.spotify.com/embed/track/${trackId}`;
2223
};
24+
25+
export const debounce = (fn: Function, ms: number) => {
26+
let timer: number | null;
27+
return () => {
28+
clearTimeout(timer as number);
29+
// @ts-ignore
30+
timer = setTimeout(function () {
31+
timer = null;
32+
fn.apply({}, arguments);
33+
}, ms);
34+
};
35+
};
36+
37+
export const useWindowDimension = () => {
38+
const [dimension, setDimension] = useState([
39+
window.innerWidth,
40+
window.innerHeight,
41+
]);
42+
useEffect(() => {
43+
const debouncedResizeHandler = debounce(() => {
44+
setDimension([window.innerWidth, window.innerHeight]);
45+
}, 300);
46+
window.addEventListener("resize", debouncedResizeHandler);
47+
return () => window.removeEventListener("resize", debouncedResizeHandler);
48+
}, []);
49+
return dimension;
50+
};

0 commit comments

Comments
 (0)