80 lines
2.2 KiB
Plaintext
80 lines
2.2 KiB
Plaintext
@page "/"
|
|
|
|
@using BlazorApp.Data
|
|
@inject CalendarService _calendarService
|
|
|
|
@if (_calendars == null)
|
|
{
|
|
<p>
|
|
<em>Loading...</em>
|
|
</p>
|
|
}
|
|
else
|
|
{
|
|
<h1>Calendars</h1>
|
|
<ul>
|
|
@foreach (var calendar in _calendars)
|
|
{
|
|
<li>
|
|
<a href="/calendars/@calendar.Id">@calendar.Name</a>
|
|
</li>
|
|
}
|
|
</ul>
|
|
|
|
@if (_showAddCalendar)
|
|
{
|
|
<h2>Add New Calendar</h2>
|
|
|
|
<EditForm Model="@_addCalendarModel" OnValidSubmit="@HandleValidSubmit">
|
|
<div class="form-group">
|
|
<label for="url">URL</label>
|
|
<InputText id="url" class="form-control" placeholder="Enter URL" @bind-Value="_addCalendarModel.Url"/>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<InputText id="username" class="form-control" placeholder="Enter username" @bind-Value="_addCalendarModel.Username"/>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<InputText type="password" id="password" class="form-control" placeholder="Enter password" @bind-Value="_addCalendarModel.Password"/>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="name">Name</label>
|
|
<InputText type="text" id="name" class="form-control" placeholder="Enter name" @bind-Value="_addCalendarModel.Name"/>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
</EditForm>
|
|
}
|
|
else
|
|
{
|
|
<button class="btn btn-primary" @onclick="ShowAddCalendar">Add Calendar</button>
|
|
}
|
|
}
|
|
|
|
@code
|
|
{
|
|
private List<Data.Calendar> _calendars;
|
|
private bool _showAddCalendar;
|
|
|
|
private Data.Calendar _addCalendarModel = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_calendars = await CalendarService.GetCalendars();
|
|
}
|
|
|
|
private void ShowAddCalendar()
|
|
{
|
|
_showAddCalendar = true;
|
|
}
|
|
|
|
private async void HandleValidSubmit()
|
|
{
|
|
Console.WriteLine(_addCalendarModel.Name);
|
|
await CalendarService.CreateCalendar(_addCalendarModel);
|
|
}
|
|
} |