diff --git a/api-test/init.sh b/api-test/init.sh new file mode 100644 index 0000000..f155b67 --- /dev/null +++ b/api-test/init.sh @@ -0,0 +1,34 @@ +#!/bin/sh +export API_KEY="X-api-key: 66db96c6-97c9-419e-ac80-6cf920158844" +export URL=http://localhost:1234 +echo $URL + +echo "Rooms!" +for i in A B C D E F G +do + echo "{ \"id\": \"TM$i\", \"name\": \"Team $i\", \"pin_enc\": \"`echo "PIN$i" | sha256 -x`\" }" \ + | curl --header "$API_KEY" --json @- $URL/api/room +done +echo +echo "questions!" + +echo "[" > ship.json +for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 +do + echo "{ \"index\": $i, \"text\": \"What question number is this? Hint (one more than previous question!)?\" }," >> ship.json +done +echo "{ \"index\": 14, \"text\": \"What question number is this? Hint (one more than previous question!)?\" }" >> ship.json +echo "]" >> ship.json +curl --header "$API_KEY" --json @- $URL/api/questions < ship.json +rm ship.json +echo +echo "answers!" +echo "[" > ship.json +for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 +do + echo "{ \"index\": $i, \"text\": \"The answer to the question is, of course, $i! Keep counting!\" }," >> ship.json +done +echo "{ \"index\": 14, \"text\": \"The answer to the question is, of course, 14! Keep counting!\"} " >> ship.json +echo "]" >> ship.json +curl --header "$API_KEY" --json @- $URL/api/answers < ship.json +rm ship.json diff --git a/server/src/web/components/card.gleam b/server/src/web/components/card.gleam index 695eb92..a152783 100644 --- a/server/src/web/components/card.gleam +++ b/server/src/web/components/card.gleam @@ -132,35 +132,6 @@ fn handle_server_message(model: Model, notify_client) { fn view(model: Model) -> Element(Msg) { let #(question, lobby) = model.lobby element.fragment([ - html.div([attribute.class("terminal-prompt")], [ - case model.state { - AskName -> - case model.players { - [] -> input_new_player(ReceiveName) - _ -> - view_players( - list.map(model.players, fn(player) { - let #(id, #(name, _)) = player - #(id, name) - }), - AcceptName, - ) - } - NameOk(name) -> { - shared.confirm_cells( - Some("Join as this player: " <> name <> "?"), - #("", name), - AcceptName, - ) - } - Answer(name) -> - step_prompt( - "The Quiz Lead will now ask the question, and you may answer.", - fn() { view_named_input(name, GiveAnswer) }, - ) - _ -> html.h3([], [html.text("Waiting for next question")]) - }, - ]), html.div([class("terminal-header")], [ html.div([class("terminal-status")], [ html.span([class("status-blink")], [html.text("●")]), @@ -179,6 +150,46 @@ fn view(model: Model) -> Element(Msg) { ]), ]), ]), + + case model.state { + AskName -> { + html.div([class("participants-grid")], [ + case model.players { + [] -> input_new_player(ReceiveName) + _ -> + view_players( + list.map(model.players, fn(player) { + let #(id, #(name, _)) = player + #(id, name) + }), + AcceptName, + ) + }, + ]) + } + NameOk(name) -> { + html.div([class("participants-grid")], [ + shared.confirm_cells( + Some("Join as this player: " <> name <> "?"), + #("", name), + AcceptName, + ), + ]) + } + Answer(name) -> { + html.div([attribute.class("terminal-prompt")], [ + step_prompt( + "The Quiz Lead will now ask the question, and you may answer.", + fn() { view_named_input(name, GiveAnswer) }, + ), + ]) + } + _ -> { + html.div([attribute.class("terminal-prompt")], [ + html.h3([], [html.text("Waiting for next question")]), + ]) + } + }, html.div([class("terminal-section")], case lobby { [] -> [] lobby -> {