diff --git a/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor index 6ea6f0c..8f16d64 100644 --- a/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor +++ b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor @@ -85,8 +85,7 @@ - - + @@ -198,8 +197,7 @@ private async Task OnPictureUploaded(IBrowserFile file) { _picture = file; - - // Base64-Vorschau generieren (max. 5 MB) + const long maxPreviewSize = 5 * 1024 * 1024; await using var stream = file.OpenReadStream(maxPreviewSize); using var ms = new MemoryStream(); @@ -266,6 +264,7 @@ Snackbar.Add("Global Entity created!", Severity.Success); MudDialog.Close(DialogResult.Ok(entity.Id)); + NavigationManager.NavigateTo(NavigationManager.Uri, true); } catch (Exception ex) { diff --git a/CouchLog/Components/Pages/GlobalList/GlobalList.razor b/CouchLog/Components/Pages/GlobalList/GlobalList.razor index 41693ba..4bcb4be 100644 --- a/CouchLog/Components/Pages/GlobalList/GlobalList.razor +++ b/CouchLog/Components/Pages/GlobalList/GlobalList.razor @@ -1,6 +1,7 @@ @page "/GlobalList" @rendermode InteractiveServer +@using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using CouchLog.Data @using Microsoft.AspNetCore.Identity @@ -18,6 +19,10 @@ GlobalList +TODO: Add Paging +TODO: Add only reload for the pages +TODO: Make Search work + @*Top of the Page*@ @@ -34,29 +39,75 @@ +
+ + + + + + + + + + + + Show already added Entities + + + + + +
+ - @foreach (var entity in _globalEntities) + @foreach (var globalEntity in _globalEntities) { - if (!entity.IsPrivate || (entity.IsPrivate && (entity.CreatorId == _appUser?.Id))) + if (!globalEntity.IsPrivate || (globalEntity.IsPrivate && (globalEntity.CreatorId == _appUser?.Id))) { - - - - - @entity.Title - - - - - - - - - - - + if (_showAlreadyAddedEntities || !_userPrivateEntityIds.Contains(globalEntity.Id)) + { + + + + + + + @globalEntity.Title + + + + + + + @if (_userPrivateEntityIds.Contains(globalEntity.Id)) + { + + + + } + else + { + + + + } + + + + } } } @@ -65,6 +116,13 @@ @code { + //Search + private string _searchString; + + //Filter Variables + private bool _showFilters; + private bool _showAlreadyAddedEntities = false; + private ApplicationUser? _appUser; private List _globalEntities = []; private HashSet _userPrivateEntityIds = []; @@ -88,12 +146,56 @@ .ToHashSetAsync(); } + private async Task OpenAddNewGlobalEntityDialog() { var dialog = await DialogService.ShowAsync("Add new Global Entity"); } - private async Task AddGlobalEntityToSharedList() + private async Task IsFilterValid(GlobalEntity globalEntity) + { + if (!_showAlreadyAddedEntities && await IsInPrivateList(globalEntity.Id)) + { + return false; + } + + return true; + } + + private async Task AddGlobalEntityToPrivateList(GlobalEntity globalEntity) + { + if(_appUser is null) { Snackbar.Add("Not logged in!", Severity.Error); return;} + + if (!await IsInPrivateList(globalEntity.Id)) + { + PrivateEntity privateEntity = new() + { + UserId = _appUser.Id, + CreationTime = DateTime.Now, + GlobalEntityId = globalEntity.Id, + UserWatchStatusId = 1, + }; + + CouchLogDb.PrivateEntities.Add(privateEntity); + await CouchLogDb.SaveChangesAsync(); + + StateHasChanged(); + Snackbar.Add("Added Entity to private List", Severity.Success); + } + else + { + Snackbar.Add("Entity already in private List!", Severity.Warning); + } + } + + private async Task IsInPrivateList(int globalEntityId) + { + if (_appUser is null) return false; + + return await CouchLogDb.PrivateEntities.Where(entity => entity.UserId == _appUser.Id).AnyAsync(entity => entity.GlobalEntityId == globalEntityId); + } + + private void AddGlobalEntityToSharedList() { Snackbar.Add("Feature not implemented yet!", Severity.Error); }