blazor-calendar/BlazorApp/Pages/Event.razor

104 lines
2.2 KiB
Plaintext
Raw Normal View History

2021-07-03 12:19:53 +00:00
@page "/calendars/{calendarId:int}/events/{eventUid}"
@inject Data.CalendarService _calendarService
2021-07-05 22:04:24 +00:00
@inject NavigationManager _navigationManager
2021-07-03 12:19:53 +00:00
2021-07-04 11:38:52 +00:00
<a href="/calendars/@CalendarId">
<span class="oi oi-arrow-left"></span> Back
</a>
2021-07-03 12:19:53 +00:00
@if (_event == null)
{
<p>
2021-07-05 22:04:24 +00:00
<em>@(_notFound ? "Event not found" : "Loading...")</em>
2021-07-03 12:19:53 +00:00
</p>
}
else
{
@if (!_editTitle)
{
<h1 class="event-summary">
<span @onclick="() => _editTitle = true">@_event.Summary</span>
</h1>
}
else
{
<input @bind="@_event.Summary">
<button @onclick="UpdateEvent">Save</button>
}
<div>
<strong>ETag:</strong> @_event.ETag
</div>
@if (_event.DtStart != null)
{
<div>
<strong>Start:</strong> @_event.DtStart
</div>
}
2021-07-04 12:36:21 +00:00
@if (_event.CalculatedEnd != null)
{
<div>
2021-07-04 12:36:21 +00:00
<strong>End:</strong> @_event.CalculatedEnd
</div>
}
2021-07-05 22:04:24 +00:00
@if (_event.Description != null)
{
<p class="event-description">@_event.Description</p>
}
@if (!_confirmDelete)
{
<button class="btn btn-outline-danger" @onclick="DeleteEvent">Delete</button>
}
else
{
<button class="btn btn-danger" @onclick="DeleteEvent">Are you sure?</button>
}
2021-07-03 12:19:53 +00:00
}
@code
{
[Parameter]
public int CalendarId { get; set; }
[Parameter]
public string EventUid { get; set; }
private Data.Calendar _calendar;
2021-07-03 12:19:53 +00:00
private Data.Event _event;
2021-07-05 22:04:24 +00:00
private bool _notFound;
private bool _editTitle;
2021-07-05 22:04:24 +00:00
private bool _confirmDelete;
2021-07-03 12:19:53 +00:00
protected override async Task OnInitializedAsync()
{
_calendar = await Data.CalendarService.GetCalendarById(CalendarId);
_event = await _calendar.GetEventByUid(EventUid);
2021-07-05 22:04:24 +00:00
_notFound = _event == null;
}
2021-07-05 22:04:24 +00:00
private async Task UpdateEvent()
{
_event = await _calendar.UpdateEvent(_event);
2021-07-03 12:19:53 +00:00
}
2021-07-05 22:04:24 +00:00
private async Task DeleteEvent()
{
if (!_confirmDelete)
{
_confirmDelete = true;
await Task.Delay(2000);
}
else
{
await _calendar.DeleteEvent(_event);
_navigationManager.NavigateTo($"/calendars/{CalendarId}");
}
_confirmDelete = false;
}
2021-07-03 12:19:53 +00:00
}