57 lines
1.8 KiB
Plaintext
57 lines
1.8 KiB
Plaintext
@page "/myplaylists"
|
||
@attribute [Authorize]
|
||
@using System.Security.Claims
|
||
@using Microsoft.EntityFrameworkCore
|
||
@using Microsoft.AspNetCore.Components.Authorization
|
||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||
@inject AppDbContext Db
|
||
@inject NavigationManager Navigation
|
||
|
||
<h3>Мои плейлисты</h3>
|
||
<a href="/createplaylist" class="btn btn-success mb-3">Создать новый плейлист</a>
|
||
|
||
@if (playlists == null)
|
||
{
|
||
<p>Загрузка...</p>
|
||
}
|
||
else if (!playlists.Any())
|
||
{
|
||
<p>У вас пока нет общих плейлистов. Создайте первый!</p>
|
||
}
|
||
else
|
||
{
|
||
<table class="table">
|
||
<thead>
|
||
<tr><th>Название</th><th>Дата создания</th><th>Ссылка</th><th>Настройки</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
@foreach (var pl in playlists)
|
||
{
|
||
<tr>
|
||
<td>@pl.Title</td>
|
||
<td>@pl.CreatedAt.ToShortDateString()</td>
|
||
<td><a href="/playlist/@pl.ShareSlug">открыть</a></td>
|
||
<td><a href="/settings/@pl.Id">настройки</a></td>
|
||
</tr>
|
||
}
|
||
</tbody>
|
||
</table>
|
||
}
|
||
|
||
@code {
|
||
private List<SharedPlaylist>? playlists;
|
||
private string? userId;
|
||
|
||
protected override async Task OnInitializedAsync()
|
||
{
|
||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||
userId = authState.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||
if (userId != null)
|
||
{
|
||
playlists = await Db.SharedPlaylists
|
||
.Where(p => p.OwnerUserId == userId)
|
||
.OrderByDescending(p => p.CreatedAt)
|
||
.ToListAsync();
|
||
}
|
||
}
|
||
} |