Skip to content

Commit

Permalink
profile: Adding inputs for dob year
Browse files Browse the repository at this point in the history
  • Loading branch information
trygvis committed Jan 15, 2025
1 parent 90e1fee commit 120b366
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static MONTH_NAMES: Lazy<Vec<String>> = Lazy::new(|| {
struct MeTemplate<'a> {
pub month_names: &'a [String],
pub days: Vec<i32>,
pub dob_year: usize,
pub dob_month: usize,
pub dob_day: usize,
pub some_accounts: Vec<SomeAccount>,
Expand Down Expand Up @@ -61,6 +62,7 @@ pub async fn get_me(
let template = MeTemplate {
month_names: MONTH_NAMES.as_slice(),
days: (1..31).collect::<Vec<i32>>(),
dob_year: me.dob.map(|d| d.year() as usize).unwrap_or_default(),
dob_month: me.dob.map(|d| d.month() as usize).unwrap_or_default(),
dob_day: me.dob.map(|d| d.day() as usize).unwrap_or_default(),
some_accounts,
Expand All @@ -72,6 +74,7 @@ pub async fn get_me(

#[derive(Deserialize, Debug)]
pub(crate) struct MeForm {
dob_year: i32,
dob_month: u8,
dob_day: u8,
}
Expand All @@ -91,7 +94,7 @@ pub async fn post_me(
.await?
.context("error loading me")?;

let year = me.dob.map(|dob| dob.year()).unwrap_or_else(|| 1900);
let year = input.dob_year;
let month: Option<Month> = input.dob_month.try_into().ok();

let dob: Option<Date> = match (month, input.dob_day) {
Expand Down
9 changes: 9 additions & 0 deletions backend/templates/me.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<h1>Edit profile</h1>
<form action="/me" method="POST">
<table>
<tr>
<td>
<label for="dob_year">Year of birth</label>
</td>
<td>
<input type="number" name="dob_year" id="dob_year"
min="1900" max="2100" value="{{ dob_year }}" required>
</td>
</tr>
<tr>
<td>
<label for="dob_month">Month of birth</label>
Expand Down

0 comments on commit 120b366

Please sign in to comment.