| | | 1 | | using Microsoft.Extensions.Logging; |
| | | 2 | | using Pomodoro.Web.Models; |
| | | 3 | | using Pomodoro.Web.Services; |
| | | 4 | | |
| | | 5 | | namespace Pomodoro.Web.Services; |
| | | 6 | | |
| | | 7 | | public class IndexPagePresenterService |
| | | 8 | | { |
| | | 9 | | private readonly ILogger<IndexPagePresenterService> _logger; |
| | | 10 | | |
| | | 11 | | public IndexPagePresenterService(ILogger<IndexPagePresenterService> logger) |
| | | 12 | | { |
| | | 13 | | _logger = logger; |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | public IndexPageState UpdateState(ITaskService taskService, ITimerService timerService) |
| | | 17 | | { |
| | | 18 | | try |
| | | 19 | | { |
| | | 20 | | return new IndexPageState |
| | | 21 | | { |
| | | 22 | | Tasks = taskService.Tasks?.ToList() ?? new List<TaskItem>(), |
| | | 23 | | CurrentTaskId = taskService.CurrentTaskId, |
| | | 24 | | RemainingTime = timerService.RemainingTime, |
| | | 25 | | CurrentSessionType = timerService.CurrentSessionType, |
| | | 26 | | IsTimerRunning = timerService.IsRunning, |
| | | 27 | | IsTimerPaused = timerService.IsPaused, |
| | | 28 | | IsTimerStarted = timerService.IsStarted |
| | | 29 | | }; |
| | | 30 | | } |
| | | 31 | | catch (Exception ex) |
| | | 32 | | { |
| | | 33 | | _logger.LogError(ex, "Error in UpdateState"); |
| | | 34 | | return new IndexPageState |
| | | 35 | | { |
| | | 36 | | Tasks = new List<TaskItem>(), |
| | | 37 | | RemainingTime = TimeSpan.FromMinutes(Constants.Timer.DefaultPomodoroMinutes), |
| | | 38 | | CurrentSessionType = SessionType.Pomodoro, |
| | | 39 | | IsTimerStarted = false |
| | | 40 | | }; |
| | | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public class IndexPageState |
| | | 46 | | { |
| | 1013 | 47 | | public List<TaskItem> Tasks { get; set; } = new(); |
| | 672 | 48 | | public Guid? CurrentTaskId { get; set; } |
| | 674 | 49 | | public TimeSpan RemainingTime { get; set; } |
| | 674 | 50 | | public SessionType CurrentSessionType { get; set; } |
| | 672 | 51 | | public bool IsTimerRunning { get; set; } |
| | 672 | 52 | | public bool IsTimerPaused { get; set; } |
| | 674 | 53 | | public bool IsTimerStarted { get; set; } |
| | | 54 | | } |