danheron / Heron.MudCalendar

Calendar component for MudBlazor
MIT License
174 stars 33 forks source link

Elements bug in calendar #122

Closed scorteanucosmin closed 6 months ago

scorteanucosmin commented 6 months ago

After booking an appointment (Adding a calendar item) at 23:00 (last cell of the day, using only DayView) and going to the next day there seems to throw an error I suspect the fact that adding 1 hour to the CalendarItem from 23:00 to 00:00 the next day at 00:00 is not properly displayed and it throws the error due to having no value

Using .AddHours(1.1) instead of .AddHours(1) fixes the issue, Start & End date times when booking at 23:00 with AddHours(1.1) output:

5/15/2024 11:00:00 PM - 5/16/2024 12:06:00 AM

blazor.web.js:1 [2024-05-15T16:33:52.772Z] Error: System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.MaxInteger[TSource,TResult](IEnumerable`1 source, Func`2 selector)
   at Heron.MudCalendar.DayWeekViewBase.CalcPositions(IEnumerable`1 items, DateOnly date)
   at Heron.MudCalendar.DayWeekViewBase.<>c__DisplayClass44_0.<RenderCellContents>b__0(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Heron.MudCalendar.DayWeekViewBase.<>c__DisplayClass43_0.<RenderCell>b__0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Heron.MudCalendar.DayWeekViewBase.<get_RenderCells>b__42_0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Heron.MudCalendar.DayWeekViewBase.<get_Render>b__35_4(RenderTreeBuilder __builder3)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudDropContainer`1.<BuildRenderTree>b__94_0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

My calendar code for reproducibility purposes:

<MudDialogProvider/>
<MudCalendar Items="_calendarAppointments" CellClicked="OnCellClicked" ItemClicked="OnItemClicked"
             DayTimeInterval="CalendarTimeInterval.Minutes60" ShowMonth="false" ShowWeek="false"
             View="CalendarView.Day" ShowDatePicker="false" Square="true">
</MudCalendar>

OnCellClicked code:

_calendarAppointments.Add(new CalendarItem
        {
            Start = dateTime,
            End = dateTime.AddHours(1),
            Text = "Booked"
        });

Start & End date times output when booking at 23:00: 5/15/2024 11:00:00 PM - 5/16/2024 12:00:00 AM

Another bug that I've encountered only happening at 12:00 to 13:00 date times, unfortunately I haven't had the time to look into it to provide at least some context of where the issue is coming from bug

Later edit: the visual bug was fixed by increasing DayCellHeight from 36 (default) to 40 fixedvisualbug