diff --git a/web/src/handlers/day.rs b/web/src/handlers/day.rs index cfb5f1a..53666e8 100644 --- a/web/src/handlers/day.rs +++ b/web/src/handlers/day.rs @@ -8,6 +8,11 @@ use axum::{ http::StatusCode, response::{IntoResponse, Redirect, Response}, }; +use shared::advent::challenges::{ + day_five::DayFive, day_four::DayFour, day_one::DayOne, day_six::DaySix, day_three::DayThree, + day_two::DayTwo, +}; +use shared::advent::get_implemented_days; use shared::{ OAuthAgentType, OAuthClientType, advent::ChallengeCheckResponse, @@ -15,14 +20,6 @@ use shared::{ advent::{AdventChallenge, AdventError}, advent::{AdventPart, CompletionStatus}, }; -use shared::advent::challenges::{ - day_one::DayOne, - day_two::DayTwo, - day_three::DayThree, - day_four::DayFour, - day_five::DayFive, - day_six::DaySix, -}; fn pick_day( day: Day, @@ -195,6 +192,14 @@ pub async fn view_day_handler( let custom_submit_part_two = challenge.custom_submit_part_two(); let is_logged_in = session.logged_in(); + //HACK ehh that iter is awkward + let count = get_implemented_days().iter().count(); + let next_day = if id == count as u8 { + None + } else { + Some(id + 1) + }; + let template = match status { CompletionStatus::None => DayTemplate { title, @@ -209,10 +214,15 @@ pub async fn view_day_handler( requires_code_input_part_two, custom_submit_part_two, is_logged_in, + next_day: None, }, CompletionStatus::PartOne => { let part_two_text = get_part_two_text(did_clone, &challenge).await; let completed = part_two_text.is_none(); + let mut next_day = None; + if completed { + next_day = Some(id + 1); + } DayTemplate { title, day: id, @@ -226,6 +236,7 @@ pub async fn view_day_handler( requires_code_input_part_two, custom_submit_part_two, is_logged_in, + next_day, } } CompletionStatus::Both => { @@ -243,6 +254,7 @@ pub async fn view_day_handler( requires_code_input_part_two, custom_submit_part_two, is_logged_in, + next_day, } } }; diff --git a/web/src/templates/day.rs b/web/src/templates/day.rs index 36be20d..792f90c 100644 --- a/web/src/templates/day.rs +++ b/web/src/templates/day.rs @@ -23,4 +23,6 @@ pub struct DayTemplate { pub custom_submit_part_two: bool, pub is_logged_in: bool, + + pub next_day: Option, } diff --git a/web/templates/day.askama.html b/web/templates/day.askama.html index 27abf95..7872b0d 100644 --- a/web/templates/day.askama.html +++ b/web/templates/day.askama.html @@ -1,159 +1,280 @@ -{% extends "layout.askama.html" %} +{% extends "layout.askama.html" %} {% block content %} +
+ +

Day {{ day }}

+
-{% block content %} -
- -

Day {{ day }}

-
- - -
-
-

- Part 1 - {% if challenge_one_completed %} -
- - Completed -
- {% endif %} -

- -
{{ challenge_one_text | safe }}
+ +
+
+

+ Part 1 {% if challenge_one_completed %} +
+ + + + Completed +
+ {% endif %} +

- {% if let Some(msg) = part_one_submit_message %} -
- {% match msg %} - {% when FlashMessage::Success with (success) %} -
- - {{success}} -
- {% when FlashMessage::Error with (error) %} -
- - {{error}} -
- {% endmatch %} -
- {% endif %} +
+ {{ challenge_one_text | safe }} +
-
- {% if !is_logged_in %} - Login to complete challenges - {% else if !challenge_one_completed %} -
- {% if requires_code_input_part_one %} -
-
- -
Enter your solution
-
- -
- {% else %} - - {% endif %} + {% if let Some(msg) = part_one_submit_message %} +
+ {% match msg %} {% when FlashMessage::Success with (success) %} +
+ + + + {{success}} +
+ {% when FlashMessage::Error with (error) %} +
+ + + + {{error}} +
+ {% endmatch %} +
+ {% endif %} -
- {% else %} -
- - Great work, you've completed Part 1! -
- {% endif %} -
+
+ {% if !is_logged_in %} + Login to complete challenges + {% else if !challenge_one_completed %} +
+ {% if requires_code_input_part_one %} +
+
+ +
Enter your solution
+
+
+ {% else %} + + {% endif %} +
+ {% else %} +
+ + + + Great work, you've completed Part 1! +
+ {% endif %}
+
+
- - {% if let Some(challenge_two_text) = challenge_two_text %} -
-
-

- Part 2 - {% if challenge_two_completed %} -
- - Completed -
- {% endif %} -

- -
{{ challenge_two_text | safe }}
+ +{% if let Some(challenge_two_text) = challenge_two_text %} +
+
+

+ Part 2 {% if challenge_two_completed %} +
+ + + + Completed +
+ {% endif %} +

- {% if let Some(msg) = part_two_submit_message %} -
- {% match msg %} - {% when FlashMessage::Success with (success) %} -
- - {{success}} -
- {% when FlashMessage::Error with (error) %} -
- - {{error}} -
- {% endmatch %} -
- {% endif %} +
+ {{ challenge_two_text | safe }} +
-
- {% if !is_logged_in %} - Login to complete challenges - {% else if !challenge_two_completed && !custom_submit_part_two %} -
- {% if requires_code_input_part_two %} -
-
- -
Enter your solution
-
- -
- {% else %} - - {% endif %} -
- {% else if !challenge_two_completed %} - {% else %} -
- - Great work, you've completed Part 2! -
- {% endif %} -
-
-
+ {% if let Some(msg) = part_two_submit_message %} +
+ {% match msg %} {% when FlashMessage::Success with (success) %} +
+ + + + {{success}} +
+ {% when FlashMessage::Error with (error) %} +
+ + + + {{error}} +
+ {% endmatch %} +
{% endif %} - - {% if challenge_one_completed && challenge_two_completed %} -
- -
-

Amazing work! 🎉

-
You've completed all the challenges for today! Come back tomorrow at 00:00 UTC for more.
-
+
+ {% if !is_logged_in %} + Login to complete challenges + {% else if !challenge_two_completed && !custom_submit_part_two %} +
+ {% if requires_code_input_part_two %} +
+
+ +
Enter your solution
+
+
- {% endif %} - - {% if challenge_one_completed %} - - {% endif %} + {% else %} + + {% endif %} +
+ {% else if !challenge_two_completed %} {% else %} +
+ + + + Great work, you've completed Part 2! +
+ {% endif %} +
+
+
+{% endif %} -{% endblock %} + +{% if challenge_one_completed && challenge_two_completed %} +
+ + + +
+

Amazing work! 🎉

+
+ You've completed all the challenges for today! Come back tomorrow at 00:00 + UTC for more. +
+
+
+{% if let Some(next) = next_day %} + +{% endif %} {% endif %} {% if challenge_one_completed %} + +{% endif %} {% endblock %}