Compare commits

..

1 Commits

Author SHA1 Message Date
7677b5cb64 do frontend (preact) 2026-11-24 23:45:37 +01:00
19 changed files with 79 additions and 355 deletions

7
Cargo.lock generated
View File

@@ -82,11 +82,18 @@ dependencies = [
"windows-sys 0.61.2", "windows-sys 0.61.2",
] ]
[[package]]
name = "anyhow"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]] [[package]]
name = "aoc-srv" name = "aoc-srv"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"anyhow",
"axum", "axum",
"chrono", "chrono",
"clap", "clap",

View File

@@ -39,6 +39,7 @@ rustls = ["reqwest/rustls"]
[dependencies] [dependencies]
anstyle = "1" anstyle = "1"
anyhow = "1"
axum = { version = "0.8", default-features = false, features = ["ws", "http1", "tokio", "macros"] } axum = { version = "0.8", default-features = false, features = ["ws", "http1", "tokio", "macros"] }
chrono = { version = "0.4", default-features = false, features = ["std", "now"] } chrono = { version = "0.4", default-features = false, features = ["std", "now"] }
clap = { version = "4.6", features = ["derive"] } clap = { version = "4.6", features = ["derive"] }

View File

@@ -32,7 +32,6 @@ preview data="data/test/aoc-response.json" \
release: release:
just make-web just make-web
RUSTFLAGS="\ RUSTFLAGS="\
-Z on-broken-pipe=inherit \
-Z fmt-debug=none \ -Z fmt-debug=none \
-C link-arg=-fuse-ld=lld \ -C link-arg=-fuse-ld=lld \
-C force-unwind-tables=no \ -C force-unwind-tables=no \

View File

@@ -1,5 +1,3 @@
use std::{io, path::PathBuf, process::ExitCode};
use clap::Parser as _; use clap::Parser as _;
mod args; mod args;
@@ -11,26 +9,7 @@ mod consts {
pub static TEMPLATE_CFG: &str = include_str!("../data/example-config.toml"); pub static TEMPLATE_CFG: &str = include_str!("../data/example-config.toml");
} }
#[derive(Debug, thiserror::Error)] fn main() -> anyhow::Result<()> {
enum AppError {
#[error("'{}': {}", .1.display(), .0)]
OpenConfig(config::OpenConfigError, PathBuf),
#[error("creating async runtime: {0}")]
AsyncRuntimeCreation(io::Error),
#[error("server: {0}")]
Server(server::ServerError),
}
fn main() -> ExitCode {
if let Err(err) = app() {
log::macros::error!("{err}");
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}
fn app() -> Result<(), AppError> {
let args = args::Args::parse(); let args = args::Args::parse();
log::state::set_log_level(args.loglevel); log::state::set_log_level(args.loglevel);
@@ -41,19 +20,16 @@ fn app() -> Result<(), AppError> {
} => { } => {
use server::{ServeArgs, run_server}; use server::{ServeArgs, run_server};
let config = config::Config::open(&config_path) let config = config::Config::open(config_path)?;
.map_err(|e| AppError::OpenConfig(e, config_path))?;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
crate::log::macros::trace!("{config:#?}"); crate::log::macros::trace!("{config:#?}");
let rt = tokio::runtime::Builder::new_multi_thread() let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
.build() .build()?;
.map_err(AppError::AsyncRuntimeCreation)?;
rt.block_on(async { run_server(ServeArgs { listen }, config).await }) rt.block_on(async { run_server(ServeArgs { listen }, config).await })?;
.map_err(AppError::Server)?;
} }
args::Command::Features => { args::Command::Features => {
let http2 = cfg!(feature = "http2"); let http2 = cfg!(feature = "http2");

View File

@@ -131,7 +131,6 @@ pub async fn websocket(
ws.on_upgrade(async move |mut socket| { ws.on_upgrade(async move |mut socket| {
let mut subscription = state.leaderboard.subscribe(); let mut subscription = state.leaderboard.subscribe();
// let mut first = true;
loop { loop {
let payload = { let payload = {
let LeaderboardWatchedInfo { let LeaderboardWatchedInfo {
@@ -139,13 +138,6 @@ pub async fn websocket(
ref message, ref message,
} = *subscription.borrow_and_update(); } = *subscription.borrow_and_update();
// for testing the error message:
// if first {
// first = false;
// format!("{}\tok\t{data}", expiry.to_rfc3339())
// } else {
// format!("{}\terr\terrormessage", expiry.to_rfc3339())
// }
match message { match message {
Ok(data) => format!("{}\tok\t{data}", expiry.to_rfc3339()), Ok(data) => format!("{}\tok\t{data}", expiry.to_rfc3339()),
Err(err) => format!("{}\terr\t{err}", expiry.to_rfc3339()), Err(err) => format!("{}\terr\t{err}", expiry.to_rfc3339()),

View File

@@ -1,4 +1,4 @@
use std::{io, sync::Arc}; use std::sync::Arc;
use axum::{Router, routing}; use axum::{Router, routing};
use itertools::Itertools; use itertools::Itertools;
@@ -17,21 +17,7 @@ pub struct ServeArgs {
pub listen: Vec<args::typ::TcpOrUnixListener>, pub listen: Vec<args::typ::TcpOrUnixListener>,
} }
#[derive(Debug, thiserror::Error)] pub async fn run_server(mut args: ServeArgs, config: config::Config) -> anyhow::Result<()> {
pub enum ServerError {
#[error("binding to address: {0}")]
Bind(io::Error),
#[error("not listening on any address")]
NotListening,
#[error("joining async listeners: {0}")]
JoinError(tokio::task::JoinError),
#[error("serving requests")]
ServeError(io::Error),
}
pub async fn run_server(mut args: ServeArgs, config: config::Config) -> Result<(), ServerError> {
use ServerError as E;
let app = Router::new() let app = Router::new()
.route("/api-ws", routing::get(api::websocket)) .route("/api-ws", routing::get(api::websocket))
.fallback_service({ .fallback_service({
@@ -59,16 +45,14 @@ pub async fn run_server(mut args: ServeArgs, config: config::Config) -> Result<(
match addr { match addr {
Tcp(socket_addr) => { Tcp(socket_addr) => {
let tcp_listener = net::TcpListener::bind(&*socket_addr) let tcp_listener = net::TcpListener::bind(&*socket_addr).await?;
.await *socket_addr = tcp_listener.local_addr()?; // if dyn port requested
.map_err(E::Bind)?;
*socket_addr = tcp_listener.local_addr().map_err(E::Bind)?; // if dyn port requested
let serve = axum::serve(tcp_listener, app.clone()); let serve = axum::serve(tcp_listener, app.clone());
serves.spawn(async move { serve.await }); serves.spawn(async move { serve.await });
} }
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
UnixDomainSocket(path_buf) => { UnixDomainSocket(path_buf) => {
let uds_listener = net::UnixListener::bind(path_buf).map_err(E::Bind)?; let uds_listener = net::UnixListener::bind(path_buf)?;
let serve = axum::serve(uds_listener, app.clone()); let serve = axum::serve(uds_listener, app.clone());
serves.spawn(async move { serve.await }); serves.spawn(async move { serve.await });
} }
@@ -78,7 +62,9 @@ pub async fn run_server(mut args: ServeArgs, config: config::Config) -> Result<(
info!("listening on: {}", args.listen.iter().format(", ")); info!("listening on: {}", args.listen.iter().format(", "));
match serves.join_next().await { match serves.join_next().await {
Some(res) => res.map_err(E::JoinError)?.map_err(E::ServeError), Some(res) => res??,
None => Err(E::NotListening), None => anyhow::bail!("not listening in any addresses"),
} }
Ok(())
} }

View File

View File

@@ -2,10 +2,10 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="./public/etsiit-tech-club.svg" /> <link rel="icon" type="image/svg+xml" href="./public/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" /> <meta name="color-scheme" content="light dark" />
<title>Advent of Code - ETSIIT</title> <title>Vite + Preact</title>
<link rel="stylesheet" href="/src/styles/main.scss" /> <link rel="stylesheet" href="/src/styles/main.scss" />
</head> </head>

View File

@@ -1,179 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="400pt"
height="400pt"
viewBox="0 0 400.00001 400.00001"
version="1.1"
id="svg22"
sodipodi:docname="logo-head.svg"
inkscape:export-filename="../Logo_Final_Verde.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
inkscape:version="1.4.4 (dcaf3e7d9e, 2026-05-05)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs22" />
<sodipodi:namedview
id="namedview22"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="pt"
inkscape:export-bgcolor="#7fb9b700"
inkscape:zoom="0.6831979"
inkscape:cx="102.45933"
inkscape:cy="335.92024"
inkscape:window-width="1600"
inkscape:window-height="865"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g22"
showguides="true" />
<g
data-name="Capa 1"
id="g22">
<symbol
id="a">
<path
d="M 0.244,0.659 H 0 V 0.714 H 0.55 V 0.659 H 0.305 V 0 H 0.244 Z"
id="path1" />
</symbol>
<symbol
id="b">
<path
d="m 0,0.269 c 0,0.089 0.022,0.157 0.065,0.205 a 0.22,0.22 0 0 0 0.172,0.072 c 0.074,0 0.129,-0.023 0.164,-0.069 A 0.294,0.294 0 0 0 0.455,0.291 V 0.259 H 0.059 A 0.253,0.253 0 0 1 0.107,0.103 0.16,0.16 0 0 1 0.237,0.048 c 0.044,0 0.078,0.009 0.103,0.027 A 0.128,0.128 0 0 1 0.389,0.151 H 0.445 A 0.176,0.176 0 0 0 0.379,0.04 0.227,0.227 0 0 0 0.237,0 0.221,0.221 0 0 0 0.061,0.071 0.294,0.294 0 0 0 0,0.269 M 0.107,0.445 A 0.261,0.261 0 0 1 0.06,0.304 H 0.397 A 0.255,0.255 0 0 1 0.357,0.449 C 0.332,0.483 0.292,0.5 0.236,0.5 0.178,0.5 0.135,0.482 0.107,0.445 Z"
id="path2" />
</symbol>
<symbol
id="c">
<path
d="M 0,0.27 C 0,0.327 0.01,0.375 0.029,0.416 A 0.22,0.22 0 0 0 0.112,0.512 0.24,0.24 0 0 0 0.241,0.546 0.199,0.199 0 0 0 0.377,0.502 0.215,0.215 0 0 0 0.443,0.378 L 0.385,0.367 A 0.196,0.196 0 0 1 0.339,0.462 C 0.317,0.485 0.283,0.497 0.238,0.497 A 0.16,0.16 0 0 1 0.138,0.467 0.171,0.171 0 0 1 0.08,0.387 0.344,0.344 0 0 1 0.062,0.272 0.34,0.34 0 0 1 0.08,0.158 0.175,0.175 0 0 1 0.136,0.078 0.163,0.163 0 0 1 0.236,0.049 c 0.047,0 0.084,0.013 0.109,0.038 0.025,0.026 0.041,0.06 0.048,0.101 H 0.451 A 0.229,0.229 0 0 0 0.384,0.051 0.208,0.208 0 0 0 0.235,0 0.218,0.218 0 0 0 0.062,0.071 0.295,0.295 0 0 0 0,0.27 Z"
id="path3" />
</symbol>
<symbol
id="d">
<path
d="M 0,0.714 H 0.058 V 0.432 A 0.233,0.233 0 0 0 0.249,0.53 c 0.057,0 0.1,-0.016 0.129,-0.048 C 0.407,0.451 0.421,0.404 0.421,0.343 V 0 H 0.363 v 0.332 c 0,0.051 -0.01,0.089 -0.032,0.112 C 0.311,0.467 0.279,0.479 0.237,0.479 A 0.197,0.197 0 0 1 0.166,0.466 0.17,0.17 0 0 1 0.106,0.428 0.172,0.172 0 0 1 0.069,0.38 0.163,0.163 0 0 1 0.058,0.312 V 0 H 0 Z"
id="path4" />
</symbol>
<symbol
id="e">
<path
d="M 0,0 Z"
id="path5" />
</symbol>
<symbol
id="f">
<path
d="m 0,0.373 c 0,0.08 0.013,0.147 0.039,0.203 a 0.291,0.291 0 0 0 0.109,0.128 c 0.047,0.03 0.102,0.045 0.163,0.045 0.08,0 0.14,-0.02 0.184,-0.062 A 0.32,0.32 0 0 0 0.583,0.518 L 0.523,0.507 A 0.273,0.273 0 0 1 0.452,0.647 C 0.419,0.679 0.372,0.695 0.311,0.695 A 0.229,0.229 0 0 1 0.177,0.656 0.243,0.243 0 0 1 0.093,0.545 0.457,0.457 0 0 1 0.064,0.374 c 0,-0.065 0.01,-0.122 0.029,-0.17 A 0.25,0.25 0 0 1 0.178,0.093 0.23,0.23 0 0 1 0.313,0.054 c 0.066,0 0.116,0.018 0.151,0.053 A 0.254,0.254 0 0 1 0.53,0.25 H 0.592 A 0.29,0.29 0 0 0 0.508,0.069 0.27,0.27 0 0 0 0.311,0 0.305,0.305 0 0 0 0.145,0.044 0.295,0.295 0 0 0 0.038,0.172 0.485,0.485 0 0 0 0,0.373 Z"
id="path6" />
</symbol>
<symbol
id="g">
<path
d="M 0,0.714 H 0.058 V 0 H 0 Z"
id="path7" />
</symbol>
<symbol
id="h">
<path
d="M 0,0.188 V 0.53 H 0.058 V 0.199 c 0,-0.051 0.01,-0.089 0.03,-0.113 0.02,-0.023 0.05,-0.035 0.092,-0.035 0.047,0 0.09,0.017 0.126,0.052 0.017,0.015 0.03,0.03 0.036,0.046 0.007,0.016 0.011,0.04 0.011,0.07 V 0.53 H 0.411 V 0.016 H 0.354 V 0.102 A 0.22,0.22 0 0 0 0.167,0 C 0.056,0 0,0.063 0,0.188 Z"
id="path8" />
</symbol>
<symbol
id="i">
<path
d="M 0.058,0.016 H 0 V 0.73 H 0.058 V 0.439 C 0.078,0.474 0.103,0.5 0.134,0.518 A 0.21,0.21 0 0 0 0.244,0.546 0.192,0.192 0 0 0 0.407,0.472 0.314,0.314 0 0 0 0.464,0.275 0.307,0.307 0 0 0 0.403,0.074 0.206,0.206 0 0 0 0.235,0 0.223,0.223 0 0 0 0.132,0.024 0.185,0.185 0 0 0 0.058,0.1 V 0.016 M 0.057,0.298 V 0.253 C 0.057,0.185 0.072,0.134 0.102,0.1 A 0.16,0.16 0 0 1 0.228,0.049 c 0.053,0 0.095,0.018 0.126,0.055 0.032,0.037 0.048,0.094 0.048,0.171 0,0.077 -0.016,0.134 -0.048,0.169 A 0.154,0.154 0 0 1 0.235,0.497 0.167,0.167 0 0 1 0.106,0.444 0.205,0.205 0 0 1 0.057,0.298 Z"
id="path9" />
</symbol>
<g
id="g19"
transform="translate(-0.86835778)">
<use
xlink:href="#a"
transform="matrix(76.174936,0,0,-76.174936,130.27866,188.63968)"
fill="#00b8d6"
id="use9"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#b"
transform="matrix(76.174936,0,0,-76.174936,170.11815,189.85847)"
fill="#00b8d6"
id="use10"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#c"
transform="matrix(76.174936,0,0,-76.174936,211.25262,189.85847)"
fill="#00b8d6"
id="use11"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#d"
transform="matrix(76.174936,0,0,-76.174936,253.45353,188.63968)"
fill="#00b8d6"
id="use12"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#e"
transform="matrix(76.174936,0,0,-76.174936,289.56045,188.63968)"
fill="#00b8d6"
id="use13"
style="fill:#007337;fill-opacity:1;stroke-width:1;stroke-dasharray:none" />
<use
xlink:href="#f"
transform="matrix(76.174936,0,0,-76.174936,136.14413,265.11931)"
fill="#00b8d6"
id="use14"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#g"
transform="matrix(76.174936,0,0,-76.174936,190.83774,263.82434)"
fill="#00b8d6"
id="use15"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#h"
transform="matrix(76.174936,0,0,-76.174936,206.22507,265.04213)"
fill="#00b8d6"
id="use16"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
<use
xlink:href="#i"
transform="matrix(76.174936,0,0,-76.174936,248.57833,265.04213)"
fill="#00b8d6"
id="use17"
style="fill:#007337;fill-opacity:1;stroke:#007336;stroke-width:0.0263158;stroke-dasharray:none;stroke-opacity:1" />
</g>
<clipPath
id="j">
<path
transform="matrix(1,0,0,-1,0,1000)"
d="M 0,1000 H 1000 V 0 H 0 Z"
id="path18" />
</clipPath>
<g
clip-path="url(#j)"
id="g21"
style="stroke:#737000;stroke-opacity:1"
transform="matrix(1.0023018,0,0,1.0023018,-22.484161,-290.97477)">
<path
stroke-width="17.548"
stroke-linecap="round"
stroke-miterlimit="10"
fill="none"
stroke="#00b8d6"
d="m 351.51,587.763 c -3.603,13.8 -16.153,23.985 -31.082,23.985 h -179.56 c -17.74,0 -32.122,-14.38 -32.122,-32.122 V 400.067 c 0,-17.74 14.382,-32.122 32.122,-32.122 h 179.56 c 15.501,0 28.438,10.98 31.457,25.587 m -48,-25.587 V 321.03 M 252.15,367.945 V 321.03 m -56.244,46.915 V 321.03 m -51.735,46.915 V 321.03 m 159.714,337.635 v -46.916 m -51.735,46.916 v -46.916 m -56.244,46.916 v -46.916 m -51.735,46.916 V 611.749 M 100.072,412.234 H 53.156 m 46.916,51.735 H 53.156 m 46.916,56.244 H 53.156 m 46.916,51.735 H 53.156"
id="path21"
style="fill:none;fill-opacity:1;stroke:#737000;stroke-opacity:1" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 8.8 KiB

15
web/public/vite.svg Normal file
View File

@@ -0,0 +1,15 @@
<svg xmlns="http://www.w3.org/2000/svg" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257">
<defs>
<linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%">
<stop offset="0%" stop-color="#41D1FF"></stop>
<stop offset="100%" stop-color="#BD34FE"></stop>
</linearGradient>
<linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%">
<stop offset="0%" stop-color="#FFEA83"></stop>
<stop offset="8.333%" stop-color="#FFDD35"></stop>
<stop offset="100%" stop-color="#FFA800"></stop>
</linearGradient>
</defs>
<path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path>
<path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="27.68" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 296">
<path fill="#673AB8" d="m128 0l128 73.9v147.8l-128 73.9L0 221.7V73.9z"></path>
<path fill="#FFF" d="M34.865 220.478c17.016 21.78 71.095 5.185 122.15-34.704c51.055-39.888 80.24-88.345 63.224-110.126c-17.017-21.78-71.095-5.184-122.15 34.704c-51.055 39.89-80.24 88.346-63.224 110.126Zm7.27-5.68c-5.644-7.222-3.178-21.402 7.573-39.253c11.322-18.797 30.541-39.548 54.06-57.923c23.52-18.375 48.303-32.004 69.281-38.442c19.922-6.113 34.277-5.075 39.92 2.148c5.644 7.223 3.178 21.403-7.573 39.254c-11.322 18.797-30.541 39.547-54.06 57.923c-23.52 18.375-48.304 32.004-69.281 38.441c-19.922 6.114-34.277 5.076-39.92-2.147Z"></path>
<path fill="#FFF" d="M220.239 220.478c17.017-21.78-12.169-70.237-63.224-110.126C105.96 70.464 51.88 53.868 34.865 75.648c-17.017 21.78 12.169 70.238 63.224 110.126c51.055 39.889 105.133 56.485 122.15 34.704Zm-7.27-5.68c-5.643 7.224-19.998 8.262-39.92 2.148c-20.978-6.437-45.761-20.066-69.28-38.441c-23.52-18.376-42.74-39.126-54.06-57.923c-10.752-17.851-13.218-32.03-7.575-39.254c5.644-7.223 19.999-8.261 39.92-2.148c20.978 6.438 45.762 20.067 69.281 38.442c23.52 18.375 42.739 39.126 54.06 57.923c10.752 17.85 13.218 32.03 7.574 39.254Z"></path>
<path fill="#FFF" d="M127.552 167.667c10.827 0 19.603-8.777 19.603-19.604c0-10.826-8.776-19.603-19.603-19.603c-10.827 0-19.604 8.777-19.604 19.603c0 10.827 8.777 19.604 19.604 19.604Z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -8,8 +8,7 @@ import { type Leaderboard as LeaderboardData } from '@/lib/api/aoc'
import { makeRangeIterator } from '@/lib' import { makeRangeIterator } from '@/lib'
import { HumanAdventDate } from '@/lib/time' import { HumanAdventDate } from '@/lib/time'
import '@/styles/leaderboard.scss' import './styles/leaderboard.scss'
import '@/styles/error.scss'
interface LeaderboardState { interface LeaderboardState {
headerInfo: HeaderInfo headerInfo: HeaderInfo
@@ -24,14 +23,12 @@ function isLeaderboardState(
class Leaderboard extends Component { class Leaderboard extends Component {
state: LeaderboardState | {} = {} state: LeaderboardState | {} = {}
ws?: WebSocket ws?: WebSocket
private closeTimer?: number
constructor() { constructor() {
super() super()
} }
private connect = () => { componentDidMount() {
if (this.ws && this.ws.readyState <= WebSocket.OPEN) return // CONNECTING or OPEN
this.ws = new WebSocket('api-ws') this.ws = new WebSocket('api-ws')
this.ws.addEventListener('message', event => { this.ws.addEventListener('message', event => {
@@ -44,37 +41,13 @@ class Leaderboard extends Component {
timestamp: data.timestamp, timestamp: data.timestamp,
errmsg: data.isError ? data.message : undefined, errmsg: data.isError ? data.message : undefined,
}, },
lastApiData: data.isError lastApiData: data.isError ? undefined : data.parseData(),
? isLeaderboardState(this.state)
? this.state.lastApiData
: undefined
: data.parseData(),
}) })
}) })
} }
private disconnect = () => { componentWillUnmount() {
this.ws?.close() this.ws?.close()
this.ws = undefined
}
private onVisibilityChange = () => {
clearTimeout(this.closeTimer)
if (document.hidden)
// grace period so quick tab switches don't cause reconnect churn
this.closeTimer = window.setTimeout(this.disconnect, 30_000)
else this.connect()
}
componentDidMount = () => {
document.addEventListener('visibilitychange', this.onVisibilityChange)
if (!document.hidden) this.connect()
}
componentWillUnmount = () => {
document.removeEventListener('visibilitychange', this.onVisibilityChange)
clearTimeout(this.closeTimer)
this.disconnect()
} }
render() { render() {
@@ -83,12 +56,7 @@ class Leaderboard extends Component {
const headerInfo = this.state.headerInfo const headerInfo = this.state.headerInfo
const data = this.state.lastApiData const data = this.state.lastApiData
if (!data) if (!data) return <span>failed to get API data</span>
return (
<span class="error">
failed to get initial API data, <Header info={headerInfo} />
</span>
)
const daySeconds = 24 * 60 * 60 const daySeconds = 24 * 60 * 60
const totalDays = data.num_days const totalDays = data.num_days
@@ -144,19 +112,17 @@ class Leaderboard extends Component {
.sort((a, b) => b.last_star_ts - a.last_star_ts) .sort((a, b) => b.last_star_ts - a.last_star_ts)
.map(e => { .map(e => {
const lastStar = const lastStar =
e.last_star_ts !== 0 ? new Date(e.last_star_ts * 1000) : null e.last_star_ts !== 0 ? new Date(e.last_star_ts) : null
const days: [undefined | Date, undefined | Date][] = new Array( const days: [undefined | Date, undefined | Date][] = new Array(
totalDays totalDays
) )
.fill(undefined) .fill(undefined)
.map(_ => [undefined, undefined]) .map(_ => [undefined, undefined])
for (const [idx, day] of Object.entries(e.completion_day_level)) for (const [idx, day] of Object.entries(e.completion_day_level))
for (const [lvl, star] of Object.entries(day)) for (const [lvl, star] of Object.entries(day)) {
days[+idx - 1]![+lvl - 1] = new Date( days[+idx - 1]![+lvl - 1] = new Date(star.get_star_ts)
star.get_star_ts * 1000 }
)
return ( return (
<tr> <tr>
@@ -176,7 +142,7 @@ class Leaderboard extends Component {
return ( return (
<td class="star"> <td class="star">
<TimestampStar <TimestampStar
dayStart={new Date(date * 1000)} dayStart={new Date(date)}
timestamps={days[idx]!} timestamps={days[idx]!}
></TimestampStar> ></TimestampStar>
</td> </td>

View File

@@ -1,8 +1,6 @@
import { useEffect, useState } from 'preact/hooks' import { useEffect, useState } from 'preact/hooks'
import { HumanDuration } from '@/lib/time' import { HumanDuration } from '@/lib/time'
import "@/styles/error.scss"
function Countdown({ until }: { until: Date }) { function Countdown({ until }: { until: Date }) {
function getRemaining() { function getRemaining() {
const now = new Date() const now = new Date()
@@ -35,7 +33,7 @@ export function Header({ info }: { info: HeaderInfo }) {
if (info.errmsg) if (info.errmsg)
return ( return (
<span class="error"> <span>
error happened: {info.errmsg} ({countdown}) error happened: {info.errmsg} ({countdown})
</span> </span>
) )

View File

@@ -35,9 +35,10 @@ export function TimestampStar({
timestamps: [Date | undefined, Date | undefined] timestamps: [Date | undefined, Date | undefined]
}) { }) {
function tooltip(day: Date): string { function tooltip(day: Date): string {
return `${HumanDuration((day.getTime() - dayStart.getTime()) / 1000)} (${HumanTime(day)})` return `${HumanDuration(day.getTime() - dayStart.getTime())} (${HumanTime(day)})`
} }
// TODO: times popup
if (!day1) return <Star type="unachieved"></Star> if (!day1) return <Star type="unachieved"></Star>
if (!day2) return <Star type="silver" tooltip={`${tooltip(day1)}`}></Star> if (!day2) return <Star type="silver" tooltip={`${tooltip(day1)}`}></Star>
return ( return (

View File

@@ -5,7 +5,7 @@ export function HumanDuration(tseconds: number): string {
const seconds = tseconds % 60 const seconds = tseconds % 60
const tminutes = f(tseconds / 60) const tminutes = f(tseconds / 60)
const minutes = tminutes % 60 const minutes = tminutes % 24
const hours = f(tminutes / 60) const hours = f(tminutes / 60)
return ( return (

View File

@@ -23,76 +23,46 @@ $transition: 0.36s cubic-bezier(0.16, 1, 0.3, 1);
@mixin light-theme() { @mixin light-theme() {
color-scheme: light; color-scheme: light;
--background: #f4eff0; --background: #f8f6f2;
--surface: #fcfafa; --surface: #ffffff;
--surface-muted: #e9e1e3; --surface-muted: #f0ede6;
$primary: #007336; $primary: #dd5555;
$secondary: #6b6700; $secondary: #606b33;
$accent: #4f6f8f; $accent: #d1985c;
$link: #2b64a6; $text: #34332f;
$link-visited: #6a4c9c; $text-muted: #77736b;
$error: #b3261e; --border: #e4dfd6;
$golden-star: #a97c00;
$silver-star: #7283c6;
$text: #333138;
$text-muted: #6b6469;
--border: #d4c5c7;
@include generate-shades((primary: $primary, @include generate-shades((primary: $primary,
secondary: $secondary, secondary: $secondary,
accent: $accent, accent: $accent,
text: $text, text: $text,
text-muted: $text-muted, text-muted: $text-muted,
link: $link,
link-visited: $link-visited,
error: $error,
golden-star: $golden-star,
silver-star: $silver-star,
)); ));
} }
@mixin dark-theme() { @mixin dark-theme() {
color-scheme: dark; color-scheme: dark;
--background: #28262c; --background: #22231f;
--surface: #333138; --surface: #2d2f29;
--surface-muted: #3f3c44; --surface-muted: #383a32;
$primary: #3fb872; $primary: #e36b68;
$secondary: #b5ae3a; $secondary: #a0aa68;
$accent: #8fb0cf; $accent: #dda76e;
$link: #7fb0e6; $text: #f0ede5;
$link-visited: #b79fe0; $text-muted: #aaa99e;
$error: #f28b82; --border: #45463d;
$golden-star: #e6c04a;
$silver-star: #a8b8f0;
$text: #f1eaeb;
$text-muted: #b3a8ac;
--border: #4d4a54;
@include generate-shades((primary: $primary, @include generate-shades((primary: $primary,
secondary: $secondary, secondary: $secondary,
accent: $accent, accent: $accent,
text: $text, text: $text,
text-muted: $text-muted, text-muted: $text-muted,
link: $link,
link-visited: $link-visited,
error: $error,
golden-star: $golden-star,
silver-star: $silver-star,
)); ));
} }

View File

@@ -1,6 +0,0 @@
@use 'variables';
.error {
color: var(--error);
font-weight: bolder;
}

View File

@@ -1,8 +1,8 @@
@use 'variables'; @use 'variables';
$star-color-variants: ( $star-color-variants: (
'golden': golden-star, 'golden': accent,
'silver': silver-star, 'silver': text,
'unachieved': text-muted, 'unachieved': text-muted,
'unavailable': text-muted, 'unavailable': text-muted,
); );
@@ -88,7 +88,7 @@ table.leaderboard {
text-decoration: none; text-decoration: none;
} }
&:is(td) .tooltip { &.tooltip {
cursor: help; cursor: help;
} }

View File

@@ -13,14 +13,6 @@ main {
justify-content: center; justify-content: center;
} }
a {
color: var(--link);
&:visited {
color: var(--link-visited);
}
}
footer { footer {
position: fixed; position: fixed;
bottom: 0; bottom: 0;