diff --git a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Components/EventData.razor b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Components/EventData.razor index a93c61c..7aeb146 100644 --- a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Components/EventData.razor +++ b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Components/EventData.razor @@ -8,7 +8,7 @@ @foreach (var timeSlot in State.Value.Timeslots) { - + @timeSlot.From.LocalDateTime.ToString("h:mm") @@ -140,6 +140,35 @@ @code { + private bool _hasScrolledToCurrentTime; + + protected override void OnAfterRender(bool firstRender) + { + base.OnAfterRender(firstRender); + + if (_hasScrolledToCurrentTime || State.Value.Timeslots.Count == 0) + return; + + var currentTimeSlot = GetCurrentTimeSlot(); + if (currentTimeSlot is null) + return; + + _hasScrolledToCurrentTime = true; + NavigationManager.NavigateTo($"#{GetTimeSlotId(currentTimeSlot)}", false); + } + + private TimeSlot? GetCurrentTimeSlot() + { + var now = DateTime.Now.TimeOfDay; + + return State.Value.Timeslots + .OrderBy(timeSlot => Math.Abs((timeSlot.From.LocalDateTime.TimeOfDay - now).TotalMinutes)) + .FirstOrDefault(); + } + + private static string GetTimeSlotId(TimeSlot timeSlot) => + $"timeslot-{timeSlot.From.LocalDateTime:HHmm}"; + void HandleViewSession(int sessionId) { NavigationManager.NavigateTo($"session/{sessionId}"); diff --git a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Program.cs b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Program.cs index c7280da..2916a1c 100644 --- a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Program.cs +++ b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Program.cs @@ -17,8 +17,9 @@ builder.Services.AddFluxor(o => { o.ScanAssemblies(typeof(Program).Assembly); - if (builder.HostEnvironment.IsDevelopment()) - o.UseReduxDevTools(); + // Removing because there are problems insttiating this since .NET 7 -> if you want to fix then ensure that all unintitialised-type build warnings are fixed + // if (builder.HostEnvironment.IsDevelopment()) + // o.UseReduxDevTools(); }); builder.Services.AddBlazoredLocalStorage(); @@ -30,4 +31,4 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); -await builder.Build().RunAsync(); \ No newline at end of file +await builder.Build().RunAsync();