Unify CCS case management flow

This commit is contained in:
hz
2026-07-19 21:29:24 -05:00
parent dacf2b89b2
commit f12904bf73
13 changed files with 938 additions and 47 deletions
+24 -5
View File
@@ -24,6 +24,7 @@ var cases: Array = []
var attempt := {}
var orders: Array = []
var history: Array = []
var history_next_cursor := ""
var prediction := {}
var rating := {"elo": 1000, "ratedCaseCount": 0}
var is_loading := false
@@ -50,6 +51,10 @@ func create_attempt(case_external_id: String, mode: String) -> void:
_send("attempt", HTTPClient.METHOD_POST, "/attempts", {"caseExternalId": case_external_id, "mode": mode})
func load_active() -> void:
_send("active", HTTPClient.METHOD_GET, "/active")
func load_attempt(attempt_id: String) -> void:
_send("attempt", HTTPClient.METHOD_GET, "/attempts/%s" % attempt_id.uri_encode())
@@ -74,8 +79,11 @@ func search_orders(query: String) -> void:
_send("orders", HTTPClient.METHOD_GET, "/orders/search?q=%s&limit=20" % query.strip_edges().uri_encode())
func load_history() -> void:
_send("history", HTTPClient.METHOD_GET, "/history?limit=50")
func load_history(cursor: String = "", status: String = "all", sort_order: String = "newest") -> void:
var suffix := "/history?limit=20&status=%s&sort=%s" % [status.uri_encode(), sort_order.uri_encode()]
if not cursor.is_empty():
suffix += "&cursor=%s" % cursor.uri_encode()
_send("history_append" if not cursor.is_empty() else "history", HTTPClient.METHOD_GET, suffix)
func load_prediction() -> void:
@@ -184,16 +192,21 @@ func _on_request_completed(result: int, response_code: int, _headers: PackedStri
else: attempt_changed.emit()
return
var parsed: Variant = JSON.parse_string(body.get_string_from_utf8())
if action in ["cases", "orders", "history"] and typeof(parsed) != TYPE_ARRAY:
if action in ["cases", "orders"] and typeof(parsed) != TYPE_ARRAY:
request_failed.emit("The CCS API returned an invalid list.")
return
if action not in ["cases", "orders", "history"] and typeof(parsed) != TYPE_DICTIONARY:
if action not in ["cases", "orders"] and typeof(parsed) != TYPE_DICTIONARY:
request_failed.emit("The CCS API returned an invalid response.")
return
match action:
"cases": cases = parsed; cases_changed.emit()
"orders": orders = parsed; orders_changed.emit()
"history": history = parsed; history_changed.emit()
"history", "history_append":
var items: Array = parsed.get("items", [])
history = history + items if action == "history_append" else items
var cursor_value: Variant = parsed.get("nextCursor", null)
history_next_cursor = "" if cursor_value == null else str(cursor_value)
history_changed.emit()
"prediction": prediction = parsed; prediction_changed.emit()
"rating": rating = parsed; rating_changed.emit()
"report": report_submitted.emit(str(parsed.get("id", "")))
@@ -218,3 +231,9 @@ func _on_auth_changed() -> void:
if not AuthState.is_logged_in:
highlights.clear()
text_scale = 1.0
attempt = {}
orders = []
history = []
history_next_cursor = ""
prediction = {}
rating = {"elo": 1000, "ratedCaseCount": 0}