Add a calendar to schedule a recipe to a chosen date (WIP)

This commit is contained in:
Greg Burri 2025-01-23 03:01:15 +01:00
parent d9449de02b
commit 9d3f9e9c60
15 changed files with 441 additions and 62 deletions

View file

@ -8,7 +8,7 @@ edition = "2021"
common = { path = "../common" }
axum = { version = "0.8", features = ["macros"] }
axum-extra = { version = "0.11", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie"] }
tokio = { version = "1", features = ["full"] }
tower = { version = "0.5", features = ["util"] }
tower-http = { version = "0.6", features = ["fs", "trace"] }

View file

@ -0,0 +1,46 @@
.calendar {
.month-selector {
width: 100%;
text-align: center;
.prev {
float: left;
}
.next {
float: right;
}
.month {
display: none;
}
.month.current {
display: inline;
}
}
ul.weekdays {
margin: 0;
padding: 20px 0;
li {
display: inline-block;
width: 14%;
text-align: center;
margin: 0;
}
}
ul.days {
margin: 0;
padding: 20px 0;
li {
display: inline-block;
width: 14%;
text-align: center;
margin: 0;
}
}
}

View file

@ -1,8 +1,8 @@
#modal-dialog {
// visibility: hidden;
color: white;
max-width: 300px;
margin-left: -125px;
width: 500px;
margin-left: -250px;
background-color: black;
text-align: center;
border-radius: 2px;

View file

@ -1,5 +1,6 @@
@use 'toast.scss';
@use 'modal-dialog.scss';
@use 'calendar.scss';
$color-1: #B29B89;
$color-2: #89B29B;
@ -123,6 +124,10 @@ body {
h1 {
text-align: center;
}
#hidden-templates {
display: none;
}
}
#recipe-edit {
@ -163,10 +168,6 @@ body {
background-color: red;
}
}
#hidden-templates {
display: none;
}
}
form {

View file

@ -1,4 +1,4 @@
use std::{fs::File, sync::LazyLock};
use std::{borrow::Borrow, fs::File, sync::LazyLock};
use ron::de::from_reader;
use serde::Deserialize;
@ -114,6 +114,27 @@ pub enum Sentence {
RecipeOneServing,
RecipeSomeServings,
RecipeEstimatedTimeMinAbbreviation,
// Calendar.
CalendarMondayAbbreviation,
CalendarTuesdayAbbreviation,
CalendarWednesdayAbbreviation,
CalendarThursdayAbbreviation,
CalendarFridayAbbreviation,
CalendarSaturdayAbbreviation,
CalendarSundayAbbreviation,
CalendarJanuary,
CalendarFebruary,
CalendarMarch,
CalendarApril,
CalendarMay,
CalendarJune,
CalendarJuly,
CalendarAugust,
CalendarSeptember,
CalendarOctober,
CalendarNovember,
CalendarDecember,
}
pub const DEFAULT_LANGUAGE_CODE: &str = "en";
@ -131,7 +152,10 @@ impl Tr {
}
}
pub fn t(&self, sentence: Sentence) -> &'static str {
pub fn t<T>(&self, sentence: T) -> &'static str
where
T: Borrow<Sentence>,
{
self.lang.get(sentence)
}
@ -196,10 +220,15 @@ impl Language {
}
}
pub fn get(&'static self, sentence: Sentence) -> &'static str {
pub fn get<T>(&'static self, sentence: T) -> &'static str
where
T: Borrow<Sentence>,
{
let sentence_cloned: Sentence = sentence.borrow().clone();
let text: &str = self
.translation
.get(sentence.clone() as usize)
.get(sentence_cloned as usize)
.unwrap()
.as_ref();
if text.is_empty() && self.code != DEFAULT_LANGUAGE_CODE {

View file

@ -0,0 +1,45 @@
<div class="calendar">
<div class="month-selector">
<span class="prev">PREV</span>
<span class="year" ></span>
{% for month in [
Sentence::CalendarJanuary,
Sentence::CalendarFebruary,
Sentence::CalendarMarch,
Sentence::CalendarApril,
Sentence::CalendarMay,
Sentence::CalendarJune,
Sentence::CalendarJuly,
Sentence::CalendarAugust,
Sentence::CalendarSeptember,
Sentence::CalendarOctober,
Sentence::CalendarNovember,
Sentence::CalendarDecember,
] %}
<span class="month">{{ tr.t(*month) }}</span>
{% endfor %}
<span class="next">NEXT</span>
</div>
<ul class="weekdays">
{% for day in [
Sentence::CalendarMondayAbbreviation,
Sentence::CalendarTuesdayAbbreviation,
Sentence::CalendarWednesdayAbbreviation,
Sentence::CalendarThursdayAbbreviation,
Sentence::CalendarFridayAbbreviation,
Sentence::CalendarSaturdayAbbreviation,
Sentence::CalendarSundayAbbreviation,
] %}
<li class="weekday">{{ tr.t(*day) }}</li>
{% endfor %}
<ul class="days">
{% for i in 0..7 %}
{% for j in 0..5 %}
<li id="day-{{i}}{{j}}"></li>
{% endfor %}
{% endfor %}
</ul>
</div>

View file

@ -5,8 +5,11 @@
<div class="content" id="recipe-view">
<h2 class="recipe-title" >{{ recipe.title }}</h2>
{% if user.is_some() && crate::data::model::can_user_edit_recipe(&user.as_ref().unwrap(), &recipe) %}
<a class="edit-recipe" href="/recipe/edit/{{ recipe.id }}" >Edit</a>
{% if let Some(user) = user %}
{% if crate::data::model::can_user_edit_recipe(user, recipe) %}
<a class="edit-recipe" href="/recipe/edit/{{ recipe.id }}" >Edit</a>
{% endif %}
<span class="add-to-planner">Add to planner</span>
{% endif %}
<div class="tags">
@ -27,7 +30,6 @@
{% else %}
{% endmatch %}
{% match recipe.estimated_time %}
{% when Some(time) %}
{{ time +}} {{+ tr.t(Sentence::RecipeEstimatedTimeMinAbbreviation) }}
@ -76,6 +78,10 @@
</div>
</div>
{% endfor %}
<div id="hidden-templates">
{% include "calendar.html" %}
</div>
</div>
{% endblock %}

View file

@ -99,6 +99,26 @@
(RecipeOneServing, "1 serving"),
(RecipeSomeServings, "{} servings"),
(RecipeEstimatedTimeMinAbbreviation, "min"),
(CalendarMondayAbbreviation, "Mon"),
(CalendarTuesdayAbbreviation, "Tue"),
(CalendarWednesdayAbbreviation, "Wed"),
(CalendarThursdayAbbreviation, "Thu"),
(CalendarFridayAbbreviation, "Fri"),
(CalendarSaturdayAbbreviation, "Sat"),
(CalendarSundayAbbreviation, "Sun"),
(CalendarJanuary, "January"),
(CalendarFebruary, "February"),
(CalendarMarch, "March"),
(CalendarApril, "April"),
(CalendarMay, "May"),
(CalendarJune, "June"),
(CalendarJuly, "July"),
(CalendarAugust, "August"),
(CalendarSeptember, "September"),
(CalendarOctober, "October"),
(CalendarNovember, "November"),
(CalendarDecember, "December"),
]
),
(
@ -201,6 +221,26 @@
(RecipeOneServing, "pour 1 personne"),
(RecipeSomeServings, "pour {} personnes"),
(RecipeEstimatedTimeMinAbbreviation, "min"),
(CalendarMondayAbbreviation, "Lun"),
(CalendarTuesdayAbbreviation, "Mar"),
(CalendarWednesdayAbbreviation, "Mer"),
(CalendarThursdayAbbreviation, "Jeu"),
(CalendarFridayAbbreviation, "Ven"),
(CalendarSaturdayAbbreviation, "Sam"),
(CalendarSundayAbbreviation, "Dim"),
(CalendarJanuary, "Janvier"),
(CalendarFebruary, "Février"),
(CalendarMarch, "Mars"),
(CalendarApril, "Avril"),
(CalendarMay, "Mai"),
(CalendarJune, "Juin"),
(CalendarJuly, "Juillet"),
(CalendarAugust, "Août"),
(CalendarSeptember, "Septembre"),
(CalendarOctober, "Octobre"),
(CalendarNovember, "Novembre"),
(CalendarDecember, "Décembre"),
]
)
]