diff --git a/PlaylistShared.Pwa/Components/Global/ContextualBarContent.razor b/PlaylistShared.Pwa/Components/Global/ContextualBarContent.razor index 26eeb80..2ec9545 100644 --- a/PlaylistShared.Pwa/Components/Global/ContextualBarContent.razor +++ b/PlaylistShared.Pwa/Components/Global/ContextualBarContent.razor @@ -7,21 +7,9 @@ protected override void OnParametersSet() { - bool isChanged = false; - - if (ContextualActionBarService.Content != ChildContent) - { - ContextualActionBarService.Content = ChildContent; - isChanged = true; - } - - if (ContextualActionBarService.Bottom != Bottom) - { - ContextualActionBarService.Bottom = Bottom; - isChanged = true; - } - - if (isChanged) ContextualActionBarService.ChangeParameters(); + ContextualActionBarService.Content = ChildContent; + ContextualActionBarService.Bottom = Bottom; + ContextualActionBarService.ChangeParameters(); } public void Dispose() diff --git a/PlaylistShared.Pwa/Pages/SharedPlaylistView.razor b/PlaylistShared.Pwa/Pages/SharedPlaylistView.razor index 08c11f7..f15ae4a 100644 --- a/PlaylistShared.Pwa/Pages/SharedPlaylistView.razor +++ b/PlaylistShared.Pwa/Pages/SharedPlaylistView.razor @@ -25,7 +25,32 @@ - @PlaylistCardContent + + + + @PlaylistCardHeaderContent + + + + + + + @if (_isCreator && _isAuthenticated) + { + + } + + + + + + @PlaylistCardBodyContent + + @if (_canAdd) @@ -46,7 +71,17 @@
- @PlaylistCardContent + + + + @PlaylistCardHeaderContent + + + + + @PlaylistCardBodyContent + +
@@ -62,18 +97,33 @@ @* Кастомная панель навигации внизу *@ - - @if (_canAdd) - { + - } - - + + + + + + + @if (_isCreator && _isAuthenticated) + { + + } +
@@ -108,63 +158,69 @@ /// Токен расшаренного плейлиста [Parameter] public required string Token { get; set; } - private RenderFragment PlaylistCardContent => __builder => + + /// Элемент: заголовок плейлиста + private RenderFragment PlaylistCardHeaderContent => __builder => { - - - - @if(_loading) - { - - } - else - { - - } - - - - - + @if (_loading) + { + + } + else + { - - @if (_loading || _tracksLoading) + + @if (!string.IsNullOrEmpty(_playlist?.CoverUrl)) { - - - - - - + } - else - { - - - - - - @if (_canRemove) - { - - - - } - - - } - - + + + @_playlist?.Title + + + } }; - + + /// Элемент: треки плейлиста + private RenderFragment PlaylistCardBodyContent => __builder => + { + @if (_loading || _tracksLoading) + { + + + + + + + } + else + { + + + + + + @if (_canRemove) + { + + + + } + + + } + }; + + /// Элемент: блок добавления треков private RenderFragment AddTrackCardContent => __builder => { - + Добавление треков Ссылка на поле ввода private MudTextField _searchField; - /// Результат поиска. private YandexSearchResult? _searchResult = null; + + /******************************** + * Вкладка добавления треков + *********************************/ + /// Признак, что альбом в фаворитах. + private bool _isFavorite; + /// Загрузка признака "фаворит". + private bool _favoriteLoading; protected override async Task OnInitializedAsync() { @@ -392,6 +455,7 @@ _activeMobileTab = 0; await ConfigurePermissions(); + await CheckFavoriteStatus(); } else { @@ -643,4 +707,91 @@ throw new ArgumentException("Unsupported URL pattern"); } #endregion + + #region Избранное / Фаворит + /// Установка галочки "избранное" + private async Task CheckFavoriteStatus() + { + if (string.IsNullOrWhiteSpace(Token)) return; + try + { + var response = await Http.GetFromJsonAsync>($"/api/favorites/{Token}/check"); + if (response?.Success == true) + _isFavorite = response.Data; + } + catch { } + } + + private async Task ToggleFavorite() + { + if (string.IsNullOrWhiteSpace(Token)) return; + + if (!_isAuthenticated) + { + Snackbar.Add("Добавление в избранное только авторизованным пользователям", Severity.Warning); + return; + } + + _favoriteLoading = true; + try + { + if (_isFavorite) + { + var response = await Http.DeleteAsync($"/api/favorites/{Token}"); + if (response.IsSuccessStatusCode) + { + _isFavorite = false; + Snackbar.Add("Плейлист удалён из избранного", Severity.Success); + } + else + { + Snackbar.Add("Ошибка удаления из избранного", Severity.Error); + } + } + else + { + var response = await Http.PostAsync($"/api/favorites/{Token}", null); + if (response.IsSuccessStatusCode) + { + _isFavorite = true; + Snackbar.Add("Плейлист добавлен в избранное", Severity.Success); + } + else + { + Snackbar.Add("Ошибка добавления в избранное", Severity.Error); + } + } + } + catch (Exception ex) + { + Snackbar.Add($"Ошибка: {ex.Message}", Severity.Error); + } + finally + { + _favoriteLoading = false; + StateHasChanged(); + } + } + #endregion + + #region Настройка доступов к плейлисту + private async Task OpenPermissionsDialog() + { + if (_playlist == null) return; + var initialPermissions = new UpdatePermissionsDto + { + ViewPermission = _playlist.ViewPermission, + PlayPermission = _playlist.PlayPermission, + AddPermission = _playlist.AddPermission, + RemovePermission = _playlist.RemovePermission + }; + var parameters = new DialogParameters + { + { nameof(PermissionsDialog.ShareToken), Token }, + { nameof(PermissionsDialog.InitialPermissions), initialPermissions } + }; + var dialog = await DialogService.ShowAsync("Настройки доступа", parameters); + var result = await dialog.Result; + } + #endregion } \ No newline at end of file