diff --git a/Wino.Calendar.ViewModels/EventDetailsPageViewModel.cs b/Wino.Calendar.ViewModels/EventDetailsPageViewModel.cs index 5baf0ae7..c86ada88 100644 --- a/Wino.Calendar.ViewModels/EventDetailsPageViewModel.cs +++ b/Wino.Calendar.ViewModels/EventDetailsPageViewModel.cs @@ -164,18 +164,17 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel CurrentSettings = _preferencesService.GetCurrentCalendarSettings(); IsDarkWebviewRenderer = _underlyingThemeService.IsUnderlyingThemeDark(); - // Initialize Show As options - ShowAsOptions.Add(new ShowAsOption(CalendarItemShowAs.Free)); - ShowAsOptions.Add(new ShowAsOption(CalendarItemShowAs.Tentative)); - ShowAsOptions.Add(new ShowAsOption(CalendarItemShowAs.Busy)); - ShowAsOptions.Add(new ShowAsOption(CalendarItemShowAs.OutOfOffice)); - ShowAsOptions.Add(new ShowAsOption(CalendarItemShowAs.WorkingElsewhere)); - SelectedShowAsOption = ShowAsOptions[2]; // Default to Busy + foreach (var showAs in CalendarItemActionOptions.ShowAsOptions) + { + ShowAsOptions.Add(new ShowAsOption(showAs)); + } - // Initialize RSVP status options - RsvpStatusOptions.Add(new RsvpStatusOption(CalendarItemStatus.Accepted)); - RsvpStatusOptions.Add(new RsvpStatusOption(CalendarItemStatus.Tentative)); - RsvpStatusOptions.Add(new RsvpStatusOption(CalendarItemStatus.Cancelled)); + SelectedShowAsOption = ShowAsOptions.FirstOrDefault(option => option.ShowAs == CalendarItemShowAs.Busy) ?? ShowAsOptions.FirstOrDefault(); + + foreach (var responseStatus in CalendarItemActionOptions.ResponseOptions) + { + RsvpStatusOptions.Add(new RsvpStatusOption(responseStatus)); + } } public override async void OnNavigatedTo(NavigationMode mode, object parameters) diff --git a/Wino.Core.Domain/CalendarItemActionOptions.cs b/Wino.Core.Domain/CalendarItemActionOptions.cs new file mode 100644 index 00000000..c9df13ea --- /dev/null +++ b/Wino.Core.Domain/CalendarItemActionOptions.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Wino.Core.Domain.Enums; + +namespace Wino.Core.Domain; + +public static class CalendarItemActionOptions +{ + public static IReadOnlyList ShowAsOptions { get; } = + [ + CalendarItemShowAs.Free, + CalendarItemShowAs.Tentative, + CalendarItemShowAs.Busy, + CalendarItemShowAs.OutOfOffice, + CalendarItemShowAs.WorkingElsewhere + ]; + + public static IReadOnlyList ResponseOptions { get; } = + [ + CalendarItemStatus.Accepted, + CalendarItemStatus.Tentative, + CalendarItemStatus.Cancelled + ]; +} diff --git a/Wino.Core.Tests/Services/CalendarContextMenuItemServiceTests.cs b/Wino.Core.Tests/Services/CalendarContextMenuItemServiceTests.cs index e1a7b4f4..1fce6485 100644 --- a/Wino.Core.Tests/Services/CalendarContextMenuItemServiceTests.cs +++ b/Wino.Core.Tests/Services/CalendarContextMenuItemServiceTests.cs @@ -1,5 +1,6 @@ using System.Linq; using FluentAssertions; +using Wino.Core.Domain; using Wino.Core.Domain.Entities.Calendar; using Wino.Core.Domain.Enums; using Wino.Services; @@ -30,15 +31,12 @@ public class CalendarContextMenuItemServiceTests items.Should().NotContain(item => item.Action.ActionType == CalendarContextMenuActionType.Respond); var showAsItem = items.Single(item => item.Action.ActionType == CalendarContextMenuActionType.ShowAs); - showAsItem.Children.Should().HaveCount(5); + showAsItem.Children.Should().HaveCount(CalendarItemActionOptions.ShowAsOptions.Count); showAsItem.Children.Select(child => child.Action.ShowAs).Should().BeEquivalentTo( - [ - CalendarItemShowAs.Free, - CalendarItemShowAs.Tentative, - CalendarItemShowAs.Busy, - CalendarItemShowAs.OutOfOffice, - CalendarItemShowAs.WorkingElsewhere - ]); + CalendarItemActionOptions.ShowAsOptions); + + var deleteItem = items.Single(item => item.Action.ActionType == CalendarContextMenuActionType.Delete); + deleteItem.Action.TargetType.Should().BeNull(); } [Fact] diff --git a/Wino.Mail.WinUI/Controls/Calendar/CalendarItemControl.xaml b/Wino.Mail.WinUI/Controls/Calendar/CalendarItemControl.xaml index db937ab6..2ac8e545 100644 --- a/Wino.Mail.WinUI/Controls/Calendar/CalendarItemControl.xaml +++ b/Wino.Mail.WinUI/Controls/Calendar/CalendarItemControl.xaml @@ -30,8 +30,10 @@ + Placement="BottomEdgeAlignedLeft" + ShowMode="Transient" /> diff --git a/Wino.Mail.WinUI/Controls/Calendar/CalendarPeriodControl.xaml.cs b/Wino.Mail.WinUI/Controls/Calendar/CalendarPeriodControl.xaml.cs index 91cbffcc..17391f9e 100644 --- a/Wino.Mail.WinUI/Controls/Calendar/CalendarPeriodControl.xaml.cs +++ b/Wino.Mail.WinUI/Controls/Calendar/CalendarPeriodControl.xaml.cs @@ -845,13 +845,13 @@ public sealed partial class CalendarPeriodControl : UserControl, INotifyProperty } private void TimedViewportPointerMoved(object sender, PointerRoutedEventArgs e) - => SetHoverTarget(ResolveTimedDropTarget(e.GetCurrentPoint(TimedViewport).Position, _activeDragPackage?.CalendarItemViewModel)); + => UpdateHoverTargetForActiveDrag(() => ResolveTimedDropTarget(e.GetCurrentPoint(TimedViewport).Position, _activeDragPackage?.CalendarItemViewModel)); private void TimedAllDayHostPointerMoved(object sender, PointerRoutedEventArgs e) - => SetHoverTarget(ResolveTimedAllDayDropTarget(e.GetCurrentPoint(TimedAllDayHost).Position, _activeDragPackage?.CalendarItemViewModel)); + => UpdateHoverTargetForActiveDrag(() => ResolveTimedAllDayDropTarget(e.GetCurrentPoint(TimedAllDayHost).Position, _activeDragPackage?.CalendarItemViewModel)); private void MonthViewportPointerMoved(object sender, PointerRoutedEventArgs e) - => SetHoverTarget(ResolveMonthDropTarget(e.GetCurrentPoint(MonthViewport).Position, _activeDragPackage?.CalendarItemViewModel)); + => UpdateHoverTargetForActiveDrag(() => ResolveMonthDropTarget(e.GetCurrentPoint(MonthViewport).Position, _activeDragPackage?.CalendarItemViewModel)); private void CalendarDropTargetPointerExited(object sender, PointerRoutedEventArgs e) { @@ -861,6 +861,17 @@ public sealed partial class CalendarPeriodControl : UserControl, INotifyProperty } } + private void UpdateHoverTargetForActiveDrag(Func resolveHoverTarget) + { + if (_activeDragPackage == null) + { + SetHoverTarget(null); + return; + } + + SetHoverTarget(resolveHoverTarget()); + } + private void TimedViewportDragOver(object sender, DragEventArgs e) { if (!TryGetDragPackage(e, out var dragPackage)) diff --git a/Wino.Services/CalendarContextMenuItemService.cs b/Wino.Services/CalendarContextMenuItemService.cs index 4614079b..077240c9 100644 --- a/Wino.Services/CalendarContextMenuItemService.cs +++ b/Wino.Services/CalendarContextMenuItemService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Wino.Core.Domain; using Wino.Core.Domain.Entities.Calendar; using Wino.Core.Domain.Enums; using Wino.Core.Domain.Interfaces; @@ -8,22 +9,6 @@ namespace Wino.Services; public class CalendarContextMenuItemService : ICalendarContextMenuItemService { - private static readonly IReadOnlyList ShowAsOptions = - [ - CalendarItemShowAs.Free, - CalendarItemShowAs.Tentative, - CalendarItemShowAs.Busy, - CalendarItemShowAs.OutOfOffice, - CalendarItemShowAs.WorkingElsewhere - ]; - - private static readonly IReadOnlyList ResponseOptions = - [ - CalendarItemStatus.Accepted, - CalendarItemStatus.Tentative, - CalendarItemStatus.Cancelled - ]; - public IReadOnlyList GetContextMenuItems(CalendarItem calendarItem) { if (calendarItem == null) @@ -66,12 +51,12 @@ public class CalendarContextMenuItemService : ICalendarContextMenuItemService new CalendarContextMenuAction(CalendarContextMenuActionType.Delete), IsPrimary: true, ChildItems: - [ - CreateScopeLeaf(CalendarContextMenuActionType.Delete, CalendarEventTargetType.Single), - CreateScopeLeaf(CalendarContextMenuActionType.Delete, CalendarEventTargetType.Series) - ]) + [ + CreateScopeLeaf(CalendarContextMenuActionType.Delete, CalendarEventTargetType.Single), + CreateScopeLeaf(CalendarContextMenuActionType.Delete, CalendarEventTargetType.Series) + ]) : new CalendarContextMenuItem( - new CalendarContextMenuAction(CalendarContextMenuActionType.Delete, CalendarEventTargetType.Single), + new CalendarContextMenuAction(CalendarContextMenuActionType.Delete), IsPrimary: true); private static CalendarContextMenuItem CreateShowAsItem(bool isRecurringChild) @@ -102,9 +87,9 @@ public class CalendarContextMenuItemService : ICalendarContextMenuItemService private static IReadOnlyList CreateShowAsLeaves(CalendarEventTargetType targetType) { - var items = new List(ShowAsOptions.Count); + var items = new List(CalendarItemActionOptions.ShowAsOptions.Count); - foreach (var showAs in ShowAsOptions) + foreach (var showAs in CalendarItemActionOptions.ShowAsOptions) { items.Add(new CalendarContextMenuItem( new CalendarContextMenuAction(CalendarContextMenuActionType.ShowAs, targetType, showAs))); @@ -115,9 +100,9 @@ public class CalendarContextMenuItemService : ICalendarContextMenuItemService private static IReadOnlyList CreateResponseLeaves(CalendarEventTargetType targetType) { - var items = new List(ResponseOptions.Count); + var items = new List(CalendarItemActionOptions.ResponseOptions.Count); - foreach (var responseStatus in ResponseOptions) + foreach (var responseStatus in CalendarItemActionOptions.ResponseOptions) { items.Add(new CalendarContextMenuItem( new CalendarContextMenuAction(CalendarContextMenuActionType.Respond, targetType, ResponseStatus: responseStatus)));