this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

next day button

+289 -154
+20 -8
web/src/handlers/day.rs
··· 8 8 http::StatusCode, 9 9 response::{IntoResponse, Redirect, Response}, 10 10 }; 11 + use shared::advent::challenges::{ 12 + day_five::DayFive, day_four::DayFour, day_one::DayOne, day_six::DaySix, day_three::DayThree, 13 + day_two::DayTwo, 14 + }; 15 + use shared::advent::get_implemented_days; 11 16 use shared::{ 12 17 OAuthAgentType, OAuthClientType, 13 18 advent::ChallengeCheckResponse, 14 19 advent::day::Day, 15 20 advent::{AdventChallenge, AdventError}, 16 21 advent::{AdventPart, CompletionStatus}, 17 - }; 18 - use shared::advent::challenges::{ 19 - day_one::DayOne, 20 - day_two::DayTwo, 21 - day_three::DayThree, 22 - day_four::DayFour, 23 - day_five::DayFive, 24 - day_six::DaySix, 25 22 }; 26 23 27 24 fn pick_day( ··· 195 192 let custom_submit_part_two = challenge.custom_submit_part_two(); 196 193 let is_logged_in = session.logged_in(); 197 194 195 + //HACK ehh that iter is awkward 196 + let count = get_implemented_days().iter().count(); 197 + let next_day = if id == count as u8 { 198 + None 199 + } else { 200 + Some(id + 1) 201 + }; 202 + 198 203 let template = match status { 199 204 CompletionStatus::None => DayTemplate { 200 205 title, ··· 209 214 requires_code_input_part_two, 210 215 custom_submit_part_two, 211 216 is_logged_in, 217 + next_day: None, 212 218 }, 213 219 CompletionStatus::PartOne => { 214 220 let part_two_text = get_part_two_text(did_clone, &challenge).await; 215 221 let completed = part_two_text.is_none(); 222 + let mut next_day = None; 223 + if completed { 224 + next_day = Some(id + 1); 225 + } 216 226 DayTemplate { 217 227 title, 218 228 day: id, ··· 226 236 requires_code_input_part_two, 227 237 custom_submit_part_two, 228 238 is_logged_in, 239 + next_day, 229 240 } 230 241 } 231 242 CompletionStatus::Both => { ··· 243 254 requires_code_input_part_two, 244 255 custom_submit_part_two, 245 256 is_logged_in, 257 + next_day, 246 258 } 247 259 } 248 260 };
+2
web/src/templates/day.rs
··· 23 23 pub custom_submit_part_two: bool, 24 24 25 25 pub is_logged_in: bool, 26 + 27 + pub next_day: Option<u8>, 26 28 }
+267 -146
web/templates/day.askama.html
··· 1 - {% extends "layout.askama.html" %} 1 + {% extends "layout.askama.html" %} {% block content %} 2 + <div class="mb-6"> 3 + <div class="breadcrumbs text-sm"> 4 + <ul> 5 + <li><a href="/">Home</a></li> 6 + <li>Day {{ day }}</li> 7 + </ul> 8 + </div> 9 + <h2 class="text-4xl font-bold">Day {{ day }}</h2> 10 + </div> 2 11 3 - {% block content %} 4 - <div class="mb-6"> 5 - <div class="breadcrumbs text-sm"> 6 - <ul> 7 - <li><a href="/">Home</a></li> 8 - <li>Day {{ day }}</li> 9 - </ul> 10 - </div> 11 - <h2 class="text-4xl font-bold">Day {{ day }}</h2> 12 - </div> 12 + <!-- Part 1 --> 13 + <div class="card bg-base-100 shadow-xl mb-6"> 14 + <div class="card-body"> 15 + <h3 class="card-title text-2xl"> 16 + Part 1 {% if challenge_one_completed %} 17 + <div class="badge badge-success gap-2"> 18 + <svg 19 + xmlns="http://www.w3.org/2000/svg" 20 + fill="none" 21 + viewBox="0 0 24 24" 22 + class="inline-block w-4 h-4 stroke-current" 23 + > 24 + <path 25 + stroke-linecap="round" 26 + stroke-linejoin="round" 27 + stroke-width="2" 28 + d="M5 13l4 4L19 7" 29 + ></path> 30 + </svg> 31 + Completed 32 + </div> 33 + {% endif %} 34 + </h3> 13 35 14 - <!-- Part 1 --> 15 - <div class="card bg-base-100 shadow-xl mb-6"> 16 - <div class="card-body"> 17 - <h3 class="card-title text-2xl"> 18 - Part 1 19 - {% if challenge_one_completed %} 20 - <div class="badge badge-success gap-2"> 21 - <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> 22 - Completed 23 - </div> 24 - {% endif %} 25 - </h3> 36 + <article class="prose prose-lg max-w-none"> 37 + {{ challenge_one_text | safe }} 38 + </article> 26 39 27 - <article class="prose prose-lg max-w-none">{{ challenge_one_text | safe }}</article> 40 + {% if let Some(msg) = part_one_submit_message %} 41 + <div class="mt-4"> 42 + {% match msg %} {% when FlashMessage::Success with (success) %} 43 + <div class="alert alert-success shadow-lg"> 44 + <svg 45 + xmlns="http://www.w3.org/2000/svg" 46 + class="stroke-current shrink-0 h-6 w-6" 47 + fill="none" 48 + viewBox="0 0 24 24" 49 + > 50 + <path 51 + stroke-linecap="round" 52 + stroke-linejoin="round" 53 + stroke-width="2" 54 + d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" 55 + /> 56 + </svg> 57 + <span>{{success}}</span> 58 + </div> 59 + {% when FlashMessage::Error with (error) %} 60 + <div class="alert alert-error shadow-lg"> 61 + <svg 62 + xmlns="http://www.w3.org/2000/svg" 63 + class="stroke-current shrink-0 h-6 w-6" 64 + fill="none" 65 + viewBox="0 0 24 24" 66 + > 67 + <path 68 + stroke-linecap="round" 69 + stroke-linejoin="round" 70 + stroke-width="2" 71 + d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" 72 + /> 73 + </svg> 74 + <span>{{error}}</span> 75 + </div> 76 + {% endmatch %} 77 + </div> 78 + {% endif %} 28 79 29 - {% if let Some(msg) = part_one_submit_message %} 30 - <div class="mt-4"> 31 - {% match msg %} 32 - {% when FlashMessage::Success with (success) %} 33 - <div class="alert alert-success shadow-lg"> 34 - <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> 35 - <span>{{success}}</span> 36 - </div> 37 - {% when FlashMessage::Error with (error) %} 38 - <div class="alert alert-error shadow-lg"> 39 - <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> 40 - <span>{{error}}</span> 41 - </div> 42 - {% endmatch %} 43 - </div> 44 - {% endif %} 45 - 46 - <div class="card-actions justify-start mt-4"> 47 - {% if !is_logged_in %} 48 - <a href="/login" class="btn btn-primary">Login to complete challenges</a> 49 - {% else if !challenge_one_completed %} 50 - <form method="post" action="/day/{{ day }}"> 51 - {% if requires_code_input_part_one %} 52 - <div class="join"> 53 - <div> 54 - <label class="input validator join-item"> 55 - <input type="text" name="verification_code_one" placeholder="Enter Part one's solution" required /> 56 - </label> 57 - <div class="validator-hint">Enter your solution</div> 58 - </div> 59 - <button type="submit" class="btn btn-primary join-item">Check answer</button> 60 - </div> 61 - {% else %} 62 - <button class="btn btn-primary" type="submit">Check answer</button> 63 - {% endif %} 64 - 65 - </form> 66 - {% else %} 67 - <div class="badge badge-success badge-lg gap-2"> 68 - <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> 69 - Great work, you've completed Part 1! 70 - </div> 71 - {% endif %} 72 - </div> 80 + <div class="card-actions justify-start mt-4"> 81 + {% if !is_logged_in %} 82 + <a href="/login" class="btn btn-primary">Login to complete challenges</a> 83 + {% else if !challenge_one_completed %} 84 + <form method="post" action="/day/{{ day }}"> 85 + {% if requires_code_input_part_one %} 86 + <div class="join"> 87 + <div> 88 + <label class="input validator join-item"> 89 + <input 90 + type="text" 91 + name="verification_code_one" 92 + placeholder="Enter Part one's solution" 93 + required 94 + /> 95 + </label> 96 + <div class="validator-hint">Enter your solution</div> 97 + </div> 98 + <button type="submit" class="btn btn-primary join-item"> 99 + Check answer 100 + </button> 73 101 </div> 102 + {% else %} 103 + <button class="btn btn-primary" type="submit">Check answer</button> 104 + {% endif %} 105 + </form> 106 + {% else %} 107 + <div class="badge badge-success badge-lg gap-2"> 108 + <svg 109 + xmlns="http://www.w3.org/2000/svg" 110 + fill="none" 111 + viewBox="0 0 24 24" 112 + class="inline-block w-4 h-4 stroke-current" 113 + > 114 + <path 115 + stroke-linecap="round" 116 + stroke-linejoin="round" 117 + stroke-width="2" 118 + d="M5 13l4 4L19 7" 119 + ></path> 120 + </svg> 121 + Great work, you've completed Part 1! 122 + </div> 123 + {% endif %} 74 124 </div> 125 + </div> 126 + </div> 75 127 76 - <!-- Part 2 --> 77 - {% if let Some(challenge_two_text) = challenge_two_text %} 78 - <div id="part_two" class="card bg-base-100 shadow-xl mb-6"> 79 - <div class="card-body"> 80 - <h3 class="card-title text-2xl"> 81 - Part 2 82 - {% if challenge_two_completed %} 83 - <div class="badge badge-success gap-2"> 84 - <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> 85 - Completed 86 - </div> 87 - {% endif %} 88 - </h3> 128 + <!-- Part 2 --> 129 + {% if let Some(challenge_two_text) = challenge_two_text %} 130 + <div id="part_two" class="card bg-base-100 shadow-xl mb-6"> 131 + <div class="card-body"> 132 + <h3 class="card-title text-2xl"> 133 + Part 2 {% if challenge_two_completed %} 134 + <div class="badge badge-success gap-2"> 135 + <svg 136 + xmlns="http://www.w3.org/2000/svg" 137 + fill="none" 138 + viewBox="0 0 24 24" 139 + class="inline-block w-4 h-4 stroke-current" 140 + > 141 + <path 142 + stroke-linecap="round" 143 + stroke-linejoin="round" 144 + stroke-width="2" 145 + d="M5 13l4 4L19 7" 146 + ></path> 147 + </svg> 148 + Completed 149 + </div> 150 + {% endif %} 151 + </h3> 89 152 90 - <article class="prose prose-lg max-w-none">{{ challenge_two_text | safe }}</article> 153 + <article class="prose prose-lg max-w-none"> 154 + {{ challenge_two_text | safe }} 155 + </article> 91 156 92 - {% if let Some(msg) = part_two_submit_message %} 93 - <div class="mt-4"> 94 - {% match msg %} 95 - {% when FlashMessage::Success with (success) %} 96 - <div class="alert alert-success shadow-lg"> 97 - <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> 98 - <span>{{success}}</span> 99 - </div> 100 - {% when FlashMessage::Error with (error) %} 101 - <div class="alert alert-error shadow-lg"> 102 - <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> 103 - <span>{{error}}</span> 104 - </div> 105 - {% endmatch %} 106 - </div> 107 - {% endif %} 108 - 109 - <div class="card-actions justify-start mt-4"> 110 - {% if !is_logged_in %} 111 - <a href="/login" class="btn btn-primary">Login to complete challenges</a> 112 - {% else if !challenge_two_completed && !custom_submit_part_two %} 113 - <form method="post" action="/day/{{ day }}"> 114 - {% if requires_code_input_part_two %} 115 - <div class="join"> 116 - <div> 117 - <label class="input validator join-item"> 118 - <input type="text" name="verification_code_two" placeholder="Enter Part two's solution" required /> 119 - </label> 120 - <div class="validator-hint">Enter your solution</div> 121 - </div> 122 - <button type="submit" class="btn btn-primary join-item">Check answer</button> 123 - </div> 124 - {% else %} 125 - <button class="btn btn-primary" type="submit">Check answer</button> 126 - {% endif %} 127 - </form> 128 - {% else if !challenge_two_completed %} 129 - {% else %} 130 - <div class="badge badge-success badge-lg gap-2"> 131 - <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> 132 - Great work, you've completed Part 2! 133 - </div> 134 - {% endif %} 135 - </div> 136 - </div> 137 - </div> 157 + {% if let Some(msg) = part_two_submit_message %} 158 + <div class="mt-4"> 159 + {% match msg %} {% when FlashMessage::Success with (success) %} 160 + <div class="alert alert-success shadow-lg"> 161 + <svg 162 + xmlns="http://www.w3.org/2000/svg" 163 + class="stroke-current shrink-0 h-6 w-6" 164 + fill="none" 165 + viewBox="0 0 24 24" 166 + > 167 + <path 168 + stroke-linecap="round" 169 + stroke-linejoin="round" 170 + stroke-width="2" 171 + d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" 172 + /> 173 + </svg> 174 + <span>{{success}}</span> 175 + </div> 176 + {% when FlashMessage::Error with (error) %} 177 + <div class="alert alert-error shadow-lg"> 178 + <svg 179 + xmlns="http://www.w3.org/2000/svg" 180 + class="stroke-current shrink-0 h-6 w-6" 181 + fill="none" 182 + viewBox="0 0 24 24" 183 + > 184 + <path 185 + stroke-linecap="round" 186 + stroke-linejoin="round" 187 + stroke-width="2" 188 + d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" 189 + /> 190 + </svg> 191 + <span>{{error}}</span> 192 + </div> 193 + {% endmatch %} 194 + </div> 138 195 {% endif %} 139 196 140 - <!-- All Complete Message --> 141 - {% if challenge_one_completed && challenge_two_completed %} 142 - <div class="alert alert-success shadow-lg"> 143 - <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> 144 - <div> 145 - <h3 class="font-bold">Amazing work! 🎉</h3> 146 - <div class="text-sm">You've completed all the challenges for today! Come back tomorrow at 00:00 UTC for more.</div> 147 - </div> 197 + <div class="card-actions justify-start mt-4"> 198 + {% if !is_logged_in %} 199 + <a href="/login" class="btn btn-primary">Login to complete challenges</a> 200 + {% else if !challenge_two_completed && !custom_submit_part_two %} 201 + <form method="post" action="/day/{{ day }}"> 202 + {% if requires_code_input_part_two %} 203 + <div class="join"> 204 + <div> 205 + <label class="input validator join-item"> 206 + <input 207 + type="text" 208 + name="verification_code_two" 209 + placeholder="Enter Part two's solution" 210 + required 211 + /> 212 + </label> 213 + <div class="validator-hint">Enter your solution</div> 214 + </div> 215 + <button type="submit" class="btn btn-primary join-item"> 216 + Check answer 217 + </button> 148 218 </div> 149 - {% endif %} 219 + {% else %} 220 + <button class="btn btn-primary" type="submit">Check answer</button> 221 + {% endif %} 222 + </form> 223 + {% else if !challenge_two_completed %} {% else %} 224 + <div class="badge badge-success badge-lg gap-2"> 225 + <svg 226 + xmlns="http://www.w3.org/2000/svg" 227 + fill="none" 228 + viewBox="0 0 24 24" 229 + class="inline-block w-4 h-4 stroke-current" 230 + > 231 + <path 232 + stroke-linecap="round" 233 + stroke-linejoin="round" 234 + stroke-width="2" 235 + d="M5 13l4 4L19 7" 236 + ></path> 237 + </svg> 238 + Great work, you've completed Part 2! 239 + </div> 240 + {% endif %} 241 + </div> 242 + </div> 243 + </div> 244 + {% endif %} 150 245 151 - {% if challenge_one_completed %} 152 - <script> 153 - if (window.location.hash === '#part_two') { 154 - document.getElementById('part_two')?.scrollIntoView({ behavior: 'smooth' }); 155 - } 156 - </script> 157 - {% endif %} 158 - 159 - {% endblock %} 246 + <!-- All Complete Message --> 247 + {% if challenge_one_completed && challenge_two_completed %} 248 + <div class="alert alert-success shadow-lg"> 249 + <svg 250 + xmlns="http://www.w3.org/2000/svg" 251 + class="stroke-current shrink-0 h-6 w-6" 252 + fill="none" 253 + viewBox="0 0 24 24" 254 + > 255 + <path 256 + stroke-linecap="round" 257 + stroke-linejoin="round" 258 + stroke-width="2" 259 + d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" 260 + /> 261 + </svg> 262 + <div> 263 + <h3 class="font-bold">Amazing work! 🎉</h3> 264 + <div class="text-sm"> 265 + You've completed all the challenges for today! Come back tomorrow at 00:00 266 + UTC for more. 267 + </div> 268 + </div> 269 + </div> 270 + {% if let Some(next) = next_day %} 271 + <div class="flex justify-end mt-4"> 272 + <a href="/day/{{ next }}" class="btn btn-primary">Next Day →</a> 273 + </div> 274 + {% endif %} {% endif %} {% if challenge_one_completed %} 275 + <script> 276 + if (window.location.hash === "#part_two") { 277 + document.getElementById("part_two")?.scrollIntoView({ behavior: "smooth" }); 278 + } 279 + </script> 280 + {% endif %} {% endblock %}