Files
YandexMusic/PlaylistShared/Components/Pages/MyPlaylists.razor
2026-04-11 15:41:24 +03:00

57 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@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();
}
}
}