Preview a match by join code before joining
CI / Build and push docker image (push) Successful in 1m22s
CI / Build and push docker image (push) Successful in 1m22s
GET /api/games/preview returns the lobby behind a code plus the game's name and engine-echoed options. The lobby debounces the lookup as a complete code is typed and shows the game, seated players, open seats and option badges rendered from the game's schema, disabling Join when the lobby is full or the match has already started.
This commit is contained in:
@@ -70,6 +70,23 @@ pub async fn join_game(code: &str) -> Result<GameView, String> {
|
||||
resp.json().await.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Look up a game by join code without joining, for the pre-join summary.
|
||||
/// `Ok(None)` means the code names no live game (404); other failures are
|
||||
/// `Err`.
|
||||
pub async fn join_preview(code: &str) -> Result<Option<JoinPreview>, String> {
|
||||
let resp = Request::get(&format!("/api/games/preview?code={code}"))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
if resp.status() == 404 {
|
||||
return Ok(None);
|
||||
}
|
||||
if !resp.ok() {
|
||||
return Err(server_error(resp.status()));
|
||||
}
|
||||
resp.json().await.map(Some).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn game_state(game_id: &str) -> Result<GameView, String> {
|
||||
let resp = Request::get(&format!("/api/games/{game_id}"))
|
||||
|
||||
Reference in New Issue
Block a user