add proper templating
This commit is contained in:
parent
a1ca56dc82
commit
4f9d7ce833
3 changed files with 60 additions and 33 deletions
|
@ -5,9 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::{
|
||||
clock,
|
||||
forecast::{
|
||||
self, modify_weather_time, round_to_last_weather_time, Forecast, ForecastSet, Rate,
|
||||
},
|
||||
forecast::{round_to_last_weather_time, Forecast, ForecastSet, Rate},
|
||||
};
|
||||
|
||||
const DATA: &'static str = include_str!("../data.json");
|
||||
|
@ -194,7 +192,7 @@ impl<'a> CombinedFish<'a> {
|
|||
// Start with the next weather cycle.
|
||||
date = date + Duration::hours(8);
|
||||
let mut results = Vec::new();
|
||||
for i in 1..cycles {
|
||||
for _i in 1..cycles {
|
||||
while !self.is_in_correct_weather_at(forecast, date) {
|
||||
date = date + Duration::hours(8);
|
||||
}
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -1,12 +1,13 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Router};
|
||||
use data::{CombinedFish, Data};
|
||||
use maud::{html, Markup};
|
||||
use data::Data;
|
||||
use maud::Markup;
|
||||
|
||||
pub mod clock;
|
||||
pub mod data;
|
||||
pub mod forecast;
|
||||
pub mod templates;
|
||||
|
||||
pub struct AppState {
|
||||
pub data: Data,
|
||||
|
@ -35,33 +36,7 @@ where
|
|||
|
||||
#[axum::debug_handler]
|
||||
async fn main_handler(state: State<Arc<AppState>>) -> Result<Markup, AppError> {
|
||||
let meta = state.data.fish_with_meta();
|
||||
let mut values: Vec<&CombinedFish> = meta.values().filter(|f| f.entry.big_fish).collect();
|
||||
values.sort_by(|afish, bfish| bfish.is_up.cmp(&afish.is_up));
|
||||
Ok(html! {
|
||||
h1 { "Hello! Current ET " (clock::get_current_eorzea_date().format("%H:%M")) }
|
||||
@for fish in values {
|
||||
li {
|
||||
@if fish.is_up {
|
||||
"Up! "
|
||||
} @else {
|
||||
"Next uptime " (fish.next_uptime)
|
||||
}
|
||||
(fish.meta.name_en)
|
||||
details {
|
||||
@if fish.entry.start_hour.is_some() && fish.entry.end_hour.is_some() {
|
||||
"From " (fish.entry.start_hour.unwrap()) "h to " (fish.entry.end_hour.unwrap()) "h"
|
||||
}
|
||||
@if fish.entry.weather_set.len() > 0 {
|
||||
" Weather(s) " (fish.entry.weather_set.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", "))
|
||||
}
|
||||
@if let Some(forecast) = fish.get_forecast(&state.data) {
|
||||
"Current weather in " (data::get_zone_name(&state.data, forecast.zone_id)) ": " (data::get_weather_name(&state.data, forecast.weather_now().weather_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Ok(templates::main_page(state))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
54
src/templates.rs
Normal file
54
src/templates.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::extract::State;
|
||||
use maud::{html, Markup, DOCTYPE};
|
||||
|
||||
use crate::{
|
||||
clock,
|
||||
data::{self, CombinedFish},
|
||||
AppState,
|
||||
};
|
||||
|
||||
pub fn layout(content: Markup) -> Markup {
|
||||
html! {
|
||||
(DOCTYPE)
|
||||
html {
|
||||
head {
|
||||
title { "beacon" }
|
||||
meta name="viewport" content="width=device-width";
|
||||
}
|
||||
|
||||
body { (content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_page(state: State<Arc<AppState>>) -> Markup {
|
||||
let meta = state.data.fish_with_meta();
|
||||
let mut values: Vec<&CombinedFish> = meta.values().filter(|f| f.entry.big_fish).collect();
|
||||
values.sort_by(|afish, bfish| bfish.is_up.cmp(&afish.is_up));
|
||||
layout(html! {
|
||||
h1 { "Hello! Current ET " (clock::get_current_eorzea_date().format("%H:%M")) }
|
||||
@for fish in values {
|
||||
li {
|
||||
@if fish.is_up {
|
||||
"Up! "
|
||||
} @else {
|
||||
"Next uptime " (fish.next_uptime)
|
||||
}
|
||||
(fish.meta.name_en)
|
||||
details {
|
||||
@if fish.entry.start_hour.is_some() && fish.entry.end_hour.is_some() {
|
||||
"From " (fish.entry.start_hour.unwrap()) "h to " (fish.entry.end_hour.unwrap()) "h"
|
||||
}
|
||||
@if fish.entry.weather_set.len() > 0 {
|
||||
" Weather(s) " (fish.entry.weather_set.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", "))
|
||||
}
|
||||
@if let Some(forecast) = fish.get_forecast(&state.data) {
|
||||
"Current weather in " (data::get_zone_name(&state.data, forecast.zone_id)) ": " (data::get_weather_name(&state.data, forecast.weather_now().weather_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Reference in a new issue