[frontend/components] Tie Polls into NoteStore

This commit is contained in:
Lilian 2025-02-06 14:57:32 +01:00
parent 60a38bd768
commit 12b22bcf56
No known key found for this signature in database
7 changed files with 24 additions and 12 deletions

View file

@ -296,7 +296,7 @@
if (ReplyOrQuote != null)
{
await NoteActions.RefetchNoteAsync(ReplyOrQuote);
await NoteActions.RefetchNoteAsync(ReplyOrQuote.Id);
}
SendButton.State = StateButton.StateEnum.Success;

View file

@ -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<Localization> Loc;
<div class="poll">
@ -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);
}
}

View file

@ -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);
}
@ -177,6 +177,16 @@ internal class NoteActions(
}
}
public async Task AddPollVoteAsync(NotePollSchema target, List<int> choices)
{
var res = await api.Notes.AddPollVoteAsync(target.NoteId, choices);
if (res != null)
{
await RefetchNoteAsync(target.NoteId);
}
}
public async Task DeleteAsync(NoteBase note)
{
await api.Notes.DeleteNoteAsync(note.Id);

View file

@ -33,6 +33,7 @@ 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);

View file

@ -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);
}
}

View file

@ -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);

View file

@ -42,6 +42,7 @@ 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;
}
@ -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);