From 12b22bcf5638edaa2b4aa0aaca5f3b2dd6aa7ad4 Mon Sep 17 00:00:00 2001 From: Lilian Date: Thu, 6 Feb 2025 14:57:32 +0100 Subject: [PATCH] [frontend/components] Tie Polls into NoteStore --- Iceshrimp.Frontend/Components/Compose.razor | 2 +- Iceshrimp.Frontend/Components/Note/NotePoll.razor | 10 +++------- .../Core/Services/NoteStore/NoteActions.cs | 14 ++++++++++++-- .../Core/Services/NoteStore/NoteStore.cs | 3 ++- .../Core/Services/NoteStore/NotificationStore.cs | 1 + .../Core/Services/NoteStore/RelatedStore.cs | 2 ++ .../Core/Services/NoteStore/TimelineStore.cs | 4 +++- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Iceshrimp.Frontend/Components/Compose.razor b/Iceshrimp.Frontend/Components/Compose.razor index 88ed5ae3..d581b57c 100644 --- a/Iceshrimp.Frontend/Components/Compose.razor +++ b/Iceshrimp.Frontend/Components/Compose.razor @@ -296,7 +296,7 @@ if (ReplyOrQuote != null) { - await NoteActions.RefetchNoteAsync(ReplyOrQuote); + await NoteActions.RefetchNoteAsync(ReplyOrQuote.Id); } SendButton.State = StateButton.StateEnum.Success; diff --git a/Iceshrimp.Frontend/Components/Note/NotePoll.razor b/Iceshrimp.Frontend/Components/Note/NotePoll.razor index 177113e3..eaeb847c 100644 --- a/Iceshrimp.Frontend/Components/Note/NotePoll.razor +++ b/Iceshrimp.Frontend/Components/Note/NotePoll.razor @@ -1,8 +1,9 @@ @using Iceshrimp.Frontend.Core.Services +@using Iceshrimp.Frontend.Core.Services.NoteStore @using Iceshrimp.Frontend.Localization @using Iceshrimp.Shared.Schemas.Web @using Microsoft.Extensions.Localization -@inject ApiService Api; +@inject NoteActions NoteActions; @inject IStringLocalizer Loc;
@@ -82,11 +83,6 @@ { if (!CanVote()) return; - var res = await Api.Notes.AddPollVoteAsync(Poll.NoteId, Choices); - if (res != null) - { - Poll = res; - StateHasChanged(); - } + await NoteActions.AddPollVoteAsync(Poll, Choices); } } \ No newline at end of file diff --git a/Iceshrimp.Frontend/Core/Services/NoteStore/NoteActions.cs b/Iceshrimp.Frontend/Core/Services/NoteStore/NoteActions.cs index 0de9a710..e6b2acc3 100644 --- a/Iceshrimp.Frontend/Core/Services/NoteStore/NoteActions.cs +++ b/Iceshrimp.Frontend/Core/Services/NoteStore/NoteActions.cs @@ -15,11 +15,11 @@ internal class NoteActions( stateSynchronizer.Broadcast(note); } - public async Task RefetchNoteAsync(NoteBase note) + public async Task RefetchNoteAsync(string id) { try { - var res = await api.Notes.GetNoteAsync(note.Id); + var res = await api.Notes.GetNoteAsync(id); if (res == null) return; Broadcast(res); } @@ -176,6 +176,16 @@ internal class NoteActions( Broadcast(target); } } + + public async Task AddPollVoteAsync(NotePollSchema target, List choices) + { + var res = await api.Notes.AddPollVoteAsync(target.NoteId, choices); + if (res != null) + { + await RefetchNoteAsync(target.NoteId); + } + + } public async Task DeleteAsync(NoteBase note) { diff --git a/Iceshrimp.Frontend/Core/Services/NoteStore/NoteStore.cs b/Iceshrimp.Frontend/Core/Services/NoteStore/NoteStore.cs index 0f537942..a7bfc081 100644 --- a/Iceshrimp.Frontend/Core/Services/NoteStore/NoteStore.cs +++ b/Iceshrimp.Frontend/Core/Services/NoteStore/NoteStore.cs @@ -33,7 +33,8 @@ internal class NoteStore : NoteMessageProvider, IDisposable note.Replies = noteResponse.Replies; note.Attachments = noteResponse.Attachments; note.Reactions = noteResponse.Reactions; - + note.Poll = noteResponse.Poll; + AnyNoteChanged?.Invoke(this, note); NoteChangedHandlers.First(p => p.Key == note.Id).Value.Invoke(this, note); } diff --git a/Iceshrimp.Frontend/Core/Services/NoteStore/NotificationStore.cs b/Iceshrimp.Frontend/Core/Services/NoteStore/NotificationStore.cs index 8b632e92..4a6687af 100644 --- a/Iceshrimp.Frontend/Core/Services/NoteStore/NotificationStore.cs +++ b/Iceshrimp.Frontend/Core/Services/NoteStore/NotificationStore.cs @@ -82,6 +82,7 @@ internal class NotificationStore : NoteMessageProvider, IAsyncDisposable el.Value.Note.Replies = noteResponse.Replies; el.Value.Note.Attachments = noteResponse.Attachments; el.Value.Note.Reactions = noteResponse.Reactions; + el.Value.Note.Poll = noteResponse.Poll; NoteChangedHandlers.First(p => p.Key == noteResponse.Id).Value.Invoke(this, el.Value.Note); } } diff --git a/Iceshrimp.Frontend/Core/Services/NoteStore/RelatedStore.cs b/Iceshrimp.Frontend/Core/Services/NoteStore/RelatedStore.cs index 48064659..13f21273 100644 --- a/Iceshrimp.Frontend/Core/Services/NoteStore/RelatedStore.cs +++ b/Iceshrimp.Frontend/Core/Services/NoteStore/RelatedStore.cs @@ -35,6 +35,7 @@ internal class RelatedStore : NoteMessageProvider, IDisposable note.Replies = noteResponse.Replies; note.Attachments = noteResponse.Attachments; note.Reactions = noteResponse.Reactions; + note.Poll = noteResponse.Poll; NoteChangedHandlers.First(p => p.Key == note.Id).Value.Invoke(this, note); NoteChanged?.Invoke(this, note); @@ -63,6 +64,7 @@ internal class RelatedStore : NoteMessageProvider, IDisposable input.Replies = updated.Replies; input.Attachments = updated.Attachments; input.Reactions = updated.Reactions; + input.Poll = updated.Poll; var handler = NoteChangedHandlers.FirstOrDefault(p => p.Key == input.Id); handler.Value?.Invoke(this, input); NoteChanged?.Invoke(this, input); diff --git a/Iceshrimp.Frontend/Core/Services/NoteStore/TimelineStore.cs b/Iceshrimp.Frontend/Core/Services/NoteStore/TimelineStore.cs index 2a6df500..1aaa54ca 100644 --- a/Iceshrimp.Frontend/Core/Services/NoteStore/TimelineStore.cs +++ b/Iceshrimp.Frontend/Core/Services/NoteStore/TimelineStore.cs @@ -42,7 +42,8 @@ internal class TimelineStore : NoteMessageProvider, IAsyncDisposable, IStreaming el.Value.Reply.Replies = changedNote.Replies; el.Value.Reply.Attachments = changedNote.Attachments; el.Value.Reply.Reactions = changedNote.Reactions; - + el.Value.Reply.Poll = changedNote.Poll; + } if (timeline.Value.Timeline.TryGetValue(changedNote.Id, out var note)) @@ -56,6 +57,7 @@ internal class TimelineStore : NoteMessageProvider, IAsyncDisposable, IStreaming note.Replies = changedNote.Replies; note.Attachments = changedNote.Attachments; note.Reactions = changedNote.Reactions; + note.Poll = changedNote.Poll; var handler = NoteChangedHandlers.FirstOrDefault(p => p.Key == note.Id); handler.Value?.Invoke(this, note);