Files
Wino-Mail/Wino.Calendar.ViewModels/EventDetailsPageViewModel.cs

116 lines
3.2 KiB
C#
Raw Normal View History

2025-01-14 00:53:54 +01:00
using System;
using System.Diagnostics;
2025-01-14 00:53:54 +01:00
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Calendar.ViewModels.Data;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Calendar;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.ViewModels;
using Wino.Messaging.Client.Calendar;
2025-05-18 14:06:25 +02:00
namespace Wino.Calendar.ViewModels;
public partial class EventDetailsPageViewModel : CalendarBaseViewModel
2025-01-14 00:53:54 +01:00
{
2025-05-18 14:06:25 +02:00
private readonly ICalendarService _calendarService;
private readonly INativeAppService _nativeAppService;
private readonly IPreferencesService _preferencesService;
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
public CalendarSettings CurrentSettings { get; }
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
#region Details
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanViewSeries))]
private CalendarItemViewModel _currentEvent;
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
[ObservableProperty]
private CalendarItemViewModel _seriesParent;
2025-05-18 14:06:25 +02:00
public bool CanViewSeries => CurrentEvent?.IsRecurringChild ?? false;
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
#endregion
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
public EventDetailsPageViewModel(ICalendarService calendarService, INativeAppService nativeAppService, IPreferencesService preferencesService)
{
_calendarService = calendarService;
_nativeAppService = nativeAppService;
_preferencesService = preferencesService;
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
CurrentSettings = _preferencesService.GetCurrentCalendarSettings();
}
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
public override async void OnNavigatedTo(NavigationMode mode, object parameters)
{
base.OnNavigatedTo(mode, parameters);
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
Messenger.Send(new DetailsPageStateChangedMessage(true));
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
if (parameters == null || parameters is not CalendarItemTarget args)
return;
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
await LoadCalendarItemTargetAsync(args);
}
2025-05-18 14:06:25 +02:00
private async Task LoadCalendarItemTargetAsync(CalendarItemTarget target)
{
try
{
2025-05-18 14:06:25 +02:00
var currentEventItem = await _calendarService.GetCalendarItemTargetAsync(target);
2025-05-18 14:06:25 +02:00
if (currentEventItem == null)
return;
2025-05-18 14:06:25 +02:00
CurrentEvent = new CalendarItemViewModel(currentEventItem);
2025-05-18 14:06:25 +02:00
var attendees = await _calendarService.GetAttendeesAsync(currentEventItem.EventTrackingId);
2025-05-18 14:06:25 +02:00
foreach (var item in attendees)
{
2025-05-18 14:06:25 +02:00
CurrentEvent.Attendees.Add(item);
}
2025-01-14 00:53:54 +01:00
}
2025-05-18 14:06:25 +02:00
catch (Exception ex)
2025-01-14 00:53:54 +01:00
{
2025-05-18 14:06:25 +02:00
Debug.WriteLine(ex.Message);
2025-01-14 00:53:54 +01:00
}
2025-05-18 14:06:25 +02:00
}
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
public override void OnNavigatedFrom(NavigationMode mode, object parameters)
{
base.OnNavigatedFrom(mode, parameters);
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
Messenger.Send(new DetailsPageStateChangedMessage(false));
}
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
[RelayCommand]
private async Task SaveAsync()
{
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
}
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
[RelayCommand]
private async Task DeleteAsync()
{
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
}
2025-01-14 00:53:54 +01:00
2025-05-18 14:06:25 +02:00
[RelayCommand]
private Task JoinOnline()
{
if (CurrentEvent == null || string.IsNullOrEmpty(CurrentEvent.CalendarItem.HtmlLink)) return Task.CompletedTask;
return _nativeAppService.LaunchUriAsync(new Uri(CurrentEvent.CalendarItem.HtmlLink));
}
[RelayCommand]
private async Task Respond(CalendarItemStatus status)
{
if (CurrentEvent == null) return;
2025-01-14 00:53:54 +01:00
}
}