fix: reset page if error occurred
This commit is contained in:
parent
c18c55675c
commit
4176b52002
|
@ -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; }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue