fix: reset page if error occurred

This commit is contained in:
Anna 2024-01-04 00:05:24 -05:00
parent c18c55675c
commit 4176b52002
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 12 additions and 5 deletions

View File

@ -2,7 +2,6 @@ using System.Collections;
using System.Net.Http.Headers;
using Dalamud.Game.ClientState.Objects.Enums;
using EorzeaVotes.Model;
using EorzeaVotes.Utilities;
using Newtonsoft.Json;
namespace EorzeaVotes;
@ -44,15 +43,23 @@ internal class QuestionManager : IDisposable, IReadOnlyList<IQuestion> {
get => this._page;
set {
if (this.Loading) {
return;
throw new InvalidOperationException("cannot set page while still loading");
}
var old = this._page;
this.Loading = true;
this._page = Math.Max(1, value);
Task.Run(async () => {
using var notLoading = new OnDispose(() => this.Loading = false);
await this.Check();
try {
await this.Check();
} catch {
this._page = old;
throw;
} finally {
this.Loading = false;
}
});
}
}
@ -133,7 +140,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList<IQuestion> {
[Serializable]
private class QuestionsResponse {
public IQuestion? Current { get; init; }
public List<IQuestion> Page { get; init; }
public required List<IQuestion> Page { get; init; }
public bool HasNext { get; init; }
}