From cc09d32bcf44157c16f2cc219aaa472f30820bb8 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Wed, 26 Jul 2023 13:39:49 -0600 Subject: [PATCH] maybe got default time selector less insane --- .../Shared/Components/TimePicker.razor | 70 ++++--- .../Shared/Course/CourseSettings.razor | 12 ++ .../Module/Assignment/AssignmentDetails.razor | 174 ++++++++++-------- .../Shared/Semester/AssignmentInDay.razor | 108 ++++++----- .../Features/Configuration/CoursePlanner.cs | 25 ++- 5 files changed, 226 insertions(+), 163 deletions(-) diff --git a/Management.Web/Shared/Components/TimePicker.razor b/Management.Web/Shared/Components/TimePicker.razor index ebf2250..e74fa62 100644 --- a/Management.Web/Shared/Components/TimePicker.razor +++ b/Management.Web/Shared/Components/TimePicker.razor @@ -1,4 +1,6 @@ +@inject CoursePlanner planner + @code { [Parameter] [EditorRequired] @@ -7,47 +9,51 @@ [Parameter] [EditorRequired] public Action UpdateTime { get; set; }= default!; + protected override void OnInitialized() + { + planner.StateHasChanged += reload; + } + private void reload() + { + this.InvokeAsync(this.StateHasChanged); + } + public void Dispose() + { + planner.StateHasChanged -= reload; + } private string AmPm { get => Time.Hour < 12 ? "AM" : "PM"; } + private int AdjustedHour { - get => convert24to12Hour(Time.Hour); - } - private int convert24to12Hour(int hour) - { - if (hour == 0) + get { // 12 AM - return 12; - } - else if (hour <= 12) - { + @* if (Time.Hour == 0) + return 12; *@ // AM hours - return hour; - } - else - { + if (Time.Hour <= 11) + return Time.Hour; // PM hours - return hour - 12; + return Time.Hour + 1 - 12; } } - private int convert12To24Hour(int hour, string? amPm) + + private int convertTo24Hour(int hour, string? amPm) { - if (amPm == null) return -1; - if (amPm.ToUpper() == "PM" && hour < 12) + if(amPm == "AM") { - return hour + 12; + return hour % 12; } - else if (amPm.ToUpper() == "AM" && hour == 12) + else { - return 0; - } - else - { - return hour; + if (hour == 12) + return 12; + else + return hour + 12; } } } @@ -57,16 +63,22 @@ UpdateTime( new SimpleTimeOnly { - Hour=convert24to12Hour(Convert.ToInt32(e.Value)), + Hour=convertTo24Hour(Convert.ToInt32(e.Value), AmPm), Minute=Time.Minute } )" class="form-control w-auto d-inline" > - @foreach (var hour in Enumerable.Range(1, 12)) + + @foreach (var hour in Enumerable.Range(1, 11)) {