Add post-answer review and per-question loading

This commit is contained in:
hz
2026-07-14 15:34:38 -05:00
parent abbe6cf9f8
commit 7529ed5863
9 changed files with 265 additions and 42 deletions
+34 -6
View File
@@ -43,6 +43,7 @@ var pending_report_question_id := ""
var attempt_queue: Array = []
var active_attempt_index := -1
var attempt_request_active := false
var pending_excluded_question_ids: Array = []
func _ready() -> void:
questions_api_url = EndpointConfig.resolve(
@@ -92,30 +93,34 @@ func _ready() -> void:
_process_attempt_queue()
func load_questions_from_api(reset_retry: bool = true) -> void:
func load_questions_from_api(reset_retry: bool = true, excluded_question_ids: Array = []) -> void:
if AuthState.access_token.is_empty():
_set_load_error("Login required before loading questions.", false)
return
if reset_retry:
pending_excluded_question_ids = excluded_question_ids.duplicate()
retry_attempt = 0
next_retry_seconds = 0
retry_timer.stop()
var should_load_ratings := load_state == "idle"
is_loading = true
load_state = "retrying" if retry_attempt > 0 else "loading"
last_error = ""
questions.clear()
questions_changed.emit()
load_ratings_from_api()
if should_load_ratings:
load_ratings_from_api()
var headers := PackedStringArray([
"Content-Type: application/json",
"Authorization: Bearer %s" % AuthState.access_token
])
var payload := {
"limit": 80,
"supportsChoicePools": true
"limit": 1,
"supportsChoicePools": true,
"excludeExternalIds": pending_excluded_question_ids
}
var err := request.request(questions_api_url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
if err != OK:
@@ -156,7 +161,11 @@ func retry_now() -> void:
retry_attempt = 0
next_retry_seconds = 0
retry_timer.stop()
load_questions_from_api(false)
load_questions_from_api(false, pending_excluded_question_ids)
func load_next_random_question(excluded_question_ids: Array) -> void:
load_questions_from_api(true, excluded_question_ids)
func clear_questions() -> void:
@@ -185,6 +194,7 @@ func clear_questions() -> void:
category_elos = {}
last_rating_change = {}
pending_report_question_id = ""
pending_excluded_question_ids.clear()
questions_changed.emit()
ratings_changed.emit()
@@ -592,6 +602,24 @@ func _normalize_api_question(item: Variant) -> Dictionary:
"labs": item.get("labs", []),
"media": item.get("media", []),
"tags": item.get("tags", []),
"references": item.get("references", [])
"references": _normalize_references(item.get("references", []))
}
return normalized
func _normalize_references(raw_references: Variant) -> Array:
var normalized: Array = []
if typeof(raw_references) != TYPE_ARRAY:
return normalized
for raw_reference in raw_references:
if typeof(raw_reference) != TYPE_DICTIONARY:
continue
normalized.append({
"title": str(raw_reference.get("title", raw_reference.get("Title", ""))).strip_edges(),
"publisher": str(raw_reference.get("publisher", raw_reference.get("Publisher", ""))).strip_edges(),
"url": str(raw_reference.get("url", raw_reference.get("Url", ""))).strip_edges(),
"supports": str(raw_reference.get("supports", raw_reference.get("Supports", ""))).strip_edges(),
"accessed_on": str(raw_reference.get("accessedOn", raw_reference.get("accessed_on", raw_reference.get("AccessedOn", "")))).strip_edges(),
"reviewer": str(raw_reference.get("reviewer", raw_reference.get("Reviewer", ""))).strip_edges()
})
return normalized