From 0505ceda665f0e6daf917ea04b516f68c50e727a Mon Sep 17 00:00:00 2001 From: Alexander Senier Date: Sat, 1 Jun 2024 14:40:33 +0200 Subject: [PATCH] Reject training dates that lie in the future --- CHANGELOG.md | 7 +++++++ frontend/src/page/training.rs | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9958a12..2a6b2ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Reject future training dates + ## [0.4.1] - 2024-05-20 ### Fixed @@ -110,6 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial version of web app +[Unreleased]: https://github.com/treiher/valens/compare/v0.4.1...HEAD [0.4.1]: https://github.com/treiher/valens/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/treiher/valens/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/treiher/valens/compare/v0.2.0...v0.3.0 diff --git a/frontend/src/page/training.rs b/frontend/src/page/training.rs index 68ff758..1d535bd 100644 --- a/frontend/src/page/training.rs +++ b/frontend/src/page/training.rs @@ -403,7 +403,9 @@ fn view_training_sessions_dialog( return empty![]; } } - let save_disabled = loading || form.date.1.is_none(); + let today = Local::now().date_naive(); + let date_valid = form.date.1.map_or(false, |d| d <= today); + let save_disabled = loading || !date_valid; common::view_dialog( "primary", title, @@ -416,11 +418,12 @@ fn view_training_sessions_dialog( input_ev(Ev::Input, Msg::DateChanged), input![ C!["input"], - C![IF![form.date.1.is_none() => "is-danger"]], + C![IF![!date_valid => "is-danger"]], attrs! { At::Type => "date", At::Value => form.date.0, At::Disabled => date_disabled.as_at_value(), + At::Max => today, } ], ]