From 6defbb648d71400eabc3678937473d1c6fb410da Mon Sep 17 00:00:00 2001 From: Lilian Date: Fri, 11 Oct 2024 00:01:19 +0200 Subject: [PATCH] [frontend/pages] Fix erroneous "note not found" message in SingleNote view (ISH-511) --- Iceshrimp.Frontend/Pages/SingleNote.razor | 44 +++++++++++------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/Iceshrimp.Frontend/Pages/SingleNote.razor b/Iceshrimp.Frontend/Pages/SingleNote.razor index 7f0d87b7..3bad2bf8 100644 --- a/Iceshrimp.Frontend/Pages/SingleNote.razor +++ b/Iceshrimp.Frontend/Pages/SingleNote.razor @@ -3,7 +3,7 @@ @inject ApiService ApiService @inject IJSRuntime Js @inject MessageService MessageService -@inject StateService State +@inject StateService StateSvc @inject NavigationManager Navigation @inject IStringLocalizer Loc @inject ILogger Logger; @@ -21,7 +21,7 @@ @using Microsoft.Extensions.Localization @implements IDisposable -@if (_componentState == LoadState.Init) +@if (_componentState == State.Loaded) { @@ -79,18 +79,22 @@ } -@if (_componentState == LoadState.Loading) +@if (_componentState == State.Loading) {
Loading
} -@if (_componentState == LoadState.Error) +@if (_componentState == State.NotFound) {
This note does not exist!
} -@if (_componentState == LoadState.Deleted) +@if (_componentState == State.Empty) {
@Loc["This post has been deleted"]
} +@if (_componentState == State.Error) +{ +
An error occured loading the notes. Please inspect logs.
+} @code { [Parameter] public string? NoteId { get; set; } @@ -103,24 +107,16 @@ private ElementReference Scroller { get; set; } private IDisposable? _locationChangingHandlerDisposable; private IDisposable? _noteChangedHandler; - private LoadState _componentState; + private State _componentState; private bool _firstLoad = true; - private enum LoadState - { - Loading, - Init, - Error, - Deleted - } - private async Task Load() { Logger.LogTrace($"Opening NoteID: {NoteId}"); - _componentState = LoadState.Loading; + _componentState = State.Loading; if (NoteId == null) { - _componentState = LoadState.Error; + _componentState = State.NotFound; return; } @@ -136,17 +132,17 @@ catch (ApiException e) { Logger.LogWarning($"Failed to load ID '{NoteId}' due to API Exception: {e.Message}"); - _componentState = LoadState.Error; + _componentState = State.Error; return; } if (RootNote == null) { - _componentState = LoadState.Error; + _componentState = State.NotFound; return; } - _componentState = LoadState.Init; + _componentState = State.Loaded; } protected override async Task OnInitializedAsync() @@ -181,7 +177,7 @@ { if (NoteId == note.Id) { - _componentState = LoadState.Deleted; + _componentState = State.Empty; } else { @@ -213,9 +209,9 @@ Module = (IJSInProcessObjectReference)await Js.InvokeAsync("import", "/Pages/SingleNote.razor.js"); } - if (_componentState == LoadState.Init) + if (_componentState == State.Loaded) { - var state = State.SingleNote.GetState(NoteId!); + var state = StateSvc.SingleNote.GetState(NoteId!); if (state != null) { Module.InvokeVoid("SetScrollTop", Scroller, state.ScrollTop); @@ -229,10 +225,10 @@ private void SaveState() { - if (NoteId == null || _componentState != LoadState.Init) return; + if (NoteId == null || _componentState != State.Loaded) return; var scrollTop = Module.Invoke("GetScrollTop", Scroller); var state = new SingleNoteState { ScrollTop = scrollTop }; - State.SingleNote.SetState(NoteId, state); + StateSvc.SingleNote.SetState(NoteId, state); } public void Dispose()