From 3474891c2ce00dab16fccebc12c465cda4e62d72 Mon Sep 17 00:00:00 2001 From: Andrew Simonson Date: Wed, 1 Feb 2023 21:15:33 -0600 Subject: [PATCH] quality of life improvements (both user and dev) --- src/app.py | 14 ++++++------- src/static/css/App.css | 1 + src/static/js/chessbed.js | 42 ++++++++++++++++++++++--------------- src/static/js/responsive.js | 12 +++++++++-- src/templates/header.html | 2 +- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/src/app.py b/src/app.py index 6b0e9d8..42b2580 100644 --- a/src/app.py +++ b/src/app.py @@ -1,6 +1,5 @@ import flask from flask_minify import Minify -from flask_socketio import SocketIO import json proj = json.load(open("./static/json/projects.json", "r")) @@ -29,12 +28,11 @@ pages = { } app = flask.Flask(__name__) -Minify(app=app, html=True, js=True, cssless=True) -socketio = SocketIO(app) +@app.route('/api/goto/') @app.route('/api/goto/') -def goto(location): +def goto(location='home'): pagevars = pages[location] return [pagevars, flask.render_template(pagevars["template"], var=pagevars)] @@ -94,7 +92,9 @@ def static_from_root(): if __name__ == "__main__": - import sass + # import sass - sass.compile(dirname=("static/scss", "static/css"), output_style="compressed") - socketio.run(app) + # sass.compile(dirname=("static/scss", "static/css"), output_style="compressed") + app.run() +else: + Minify(app=app, html=True, js=True, cssless=True) \ No newline at end of file diff --git a/src/static/css/App.css b/src/static/css/App.css index a300a6a..06d42b8 100644 --- a/src/static/css/App.css +++ b/src/static/css/App.css @@ -34,6 +34,7 @@ body { background-attachment: fixed; background-size: 100% auto; background-clip: border-box; + background-color: #1a1a1a; } * { diff --git a/src/static/js/chessbed.js b/src/static/js/chessbed.js index 23ee553..c97da4b 100644 --- a/src/static/js/chessbed.js +++ b/src/static/js/chessbed.js @@ -4,7 +4,7 @@ async function addChessEmbed(username) { user = await fetch(`https://api.chess.com/pub/player/${username}`); stats = await fetch(`https://api.chess.com/pub/player/${username}/stats`); } catch (e) { - setChess({cName:"Chess.com request failed"}); + setChess({ cName: "Chess.com request failed" }); return; } if (user.status === 200) { @@ -15,26 +15,34 @@ async function addChessEmbed(username) { blitz: stats.chess_blitz.last.rating, bullet: stats.chess_bullet.last.rating, tactics: stats.tactics.highest.rating, - } - setChess({cName:user["username"],pic:user.avatar,ratings:ratings}); + }; + setChess({ cName: user["username"], pic: user.avatar, ratings: ratings }); } else if (user === null || user.status === 403 || user.status === null) { - chessSet({cName:"Chess.com request failed"}); + setChess({ cName: "Chess.com request failed" }); } else { - chessSet({cName:"User Not Found"}); + setChess({ cName: "User Not Found" }); } } -function setChess({cName = null, pic = null, ratings = null}) { - if (cName) { - document.querySelector(".chessName").textContent = cName; - } - if (pic) { - document.querySelector(".chessImage").src = pic; - } - if (ratings) { - document.querySelector(".chessRapid .chessStat").textContent = ratings.rapid; - document.querySelector(".chessBlitz .chessStat").textContent = ratings.blitz; - document.querySelector(".chessBullet .chessStat").textContent = ratings.bullet; - document.querySelector(".chessPuzzles .chessStat").textContent = ratings.tactics; +function setChess({ cName = null, pic = null, ratings = null }) { + try { + if (cName) { + document.querySelector(".chessName").textContent = cName; + } + if (pic) { + document.querySelector(".chessImage").src = pic; + } + if (ratings) { + document.querySelector(".chessRapid .chessStat").textContent = + ratings.rapid; + document.querySelector(".chessBlitz .chessStat").textContent = + ratings.blitz; + document.querySelector(".chessBullet .chessStat").textContent = + ratings.bullet; + document.querySelector(".chessPuzzles .chessStat").textContent = + ratings.tactics; + } + } catch { + console.log("fucker clicking so fast the internet can't even keep up"); } } diff --git a/src/static/js/responsive.js b/src/static/js/responsive.js index 23459f1..7a58e38 100644 --- a/src/static/js/responsive.js +++ b/src/static/js/responsive.js @@ -89,8 +89,9 @@ function toggleMenu() { } const loc = "https://asimonson.com" +// const loc = 'http://127.0.0.1:5000' -async function goto(location) { +async function goto(location, push=true) { let a = await fetch(loc + "/api/goto/" + location, { credentials: "include", method: "GET", @@ -105,5 +106,12 @@ async function goto(location) { eval(x.innerHTML); }); document.querySelector("title").textContent = metadata['title']; - history.pushState(null, null, metadata['canonical']); + if(push){ + history.pushState(null, null, metadata['canonical']); + } } + +function backButton() { + const location = window.location.pathname; + goto(location.substring(1), push=false); // remove slash, goto already does that +} \ No newline at end of file diff --git a/src/templates/header.html b/src/templates/header.html index aad2e84..cdfc6df 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -61,7 +61,7 @@ {{ var['title'] }} - +