Добавьте файлы проекта.
This commit is contained in:
125
PlaylistShared.Pwa/Pages/MyPlaylists.razor
Normal file
125
PlaylistShared.Pwa/Pages/MyPlaylists.razor
Normal file
@@ -0,0 +1,125 @@
|
||||
@page "/my-playlists"
|
||||
@attribute [Authorize]
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Large" Class="mt-8">
|
||||
<MudCard>
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h5">Мои плейлисты</MudText>
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<!-- Явно указываем T="bool" для MudSwitch -->
|
||||
<MudSwitch T="bool" @bind-Checked="_showOnlyShared" Color="Color.Primary" Label="Только расшаренные" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Refresh" OnClick="LoadPlaylists" />
|
||||
</CardHeaderActions>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
@if (_loading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate />
|
||||
}
|
||||
else if (_playlists == null || !_playlists.Any())
|
||||
{
|
||||
<MudText>Плейлисты не найдены. Убедитесь, что вы сохранили корректный токен Яндекс.Музыки.</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@FilteredPlaylists" Hover="true" Breakpoint="Breakpoint.Sm">
|
||||
<HeaderContent>
|
||||
<MudTh>Название</MudTh>
|
||||
<MudTh>Треков</MudTh>
|
||||
<MudTh>Статус</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd><MudText>@context.Title</MudText></MudTd>
|
||||
<MudTd>@context.TrackCount</MudTd>
|
||||
<MudTd>
|
||||
<!-- Явно указываем T="string" для MudChip -->
|
||||
@if (context.IsShared)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success">Расшарен</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Default">Не расшарен</MudChip>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
@if (!context.IsShared)
|
||||
{
|
||||
<MudButton Variant="Variant.Text" Color="Color.Primary" OnClick="() => SharePlaylist(context)">Поделиться</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Text" Color="Color.Secondary" OnClick="() => GoToShared(context)">Управлять</MudButton>
|
||||
}
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
}
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private List<YandexPlaylistInfo> _playlists;
|
||||
private bool _loading = true;
|
||||
private bool _showOnlyShared = false;
|
||||
|
||||
private List<YandexPlaylistInfo> FilteredPlaylists => _showOnlyShared ? _playlists?.Where(p => p.IsShared).ToList() : _playlists;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadPlaylists();
|
||||
}
|
||||
|
||||
private async Task LoadPlaylists()
|
||||
{
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<List<YandexPlaylistInfo>>>("/api/playlist/my");
|
||||
if (response?.Success == true)
|
||||
_playlists = response.Data;
|
||||
else
|
||||
Snackbar.Add("Ошибка загрузки плейлистов", Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Ошибка: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SharePlaylist(YandexPlaylistInfo playlist)
|
||||
{
|
||||
var request = new SharePlaylistRequest { Kind = playlist.Kind, OwnerUid = playlist.OwnerUid };
|
||||
var response = await Http.PostAsJsonAsync("/api/playlist/share", request);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
Snackbar.Add("Плейлист расшарен", Severity.Success);
|
||||
await LoadPlaylists();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка расшаривания", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void GoToShared(YandexPlaylistInfo playlist)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(playlist.ShareToken))
|
||||
Navigation.NavigateTo($"/shared/{playlist.ShareToken}");
|
||||
else
|
||||
Snackbar.Add("Ошибка: токен расшаривания не найден", Severity.Error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user