Added suggestions

This commit is contained in:
BurnyLlama 2023-08-09 17:16:41 +02:00
parent 384e4b1444
commit 0529faf9bf
3 changed files with 29 additions and 3 deletions

View File

@ -36,7 +36,15 @@ async fn location_via_id(db: &State<DatabaseHandler>, id: String) -> Result<Temp
Err(_) => return Err("Sorry, that location seems invalid!".to_string()),
};
Ok(Template::render("location", context! { location }))
let all_map_names = match Location::get_all_map_names(db).await {
Ok(all_map_names) => all_map_names,
Err(_) => vec![],
};
Ok(Template::render(
"location",
context! { location, all_map_names },
))
}
#[get("/location/<id>?<guess>")]
@ -57,9 +65,14 @@ async fn location_guess_via_id(
let is_guess_correct = guess == location.map;
let guess_with_results = Guess::create(guess, is_guess_correct);
let all_map_names = match Location::get_all_map_names(db).await {
Ok(all_map_names) => all_map_names,
Err(_) => vec![],
};
Ok(Template::render(
"location",
context! { location, guess: guess_with_results },
context! { location, guess: guess_with_results, all_map_names },
))
}

View File

@ -40,6 +40,11 @@ a#start-game {
margin: 0 auto;
}
a#new-game {
margin: 2rem auto;
width: fit-content;
}
form {
width: 100%;
display: flex;

View File

@ -14,7 +14,15 @@
{% endif %}
<form action="/location/{{ location.id }}" method="get">
<label for="guess">Enter map to guess for:</label>
<input type="text" name="guess" id="guess" autofocus>
<input type="text" name="guess" id="guess" list="map-names" autofocus>
<button class="btn primary outline" type="submit">Guess!</button>
<datalist id="map-names">
{% for map_name in all_map_names %}
<option value="{{ map_name }}"></option>
{% endfor %}
</datalist>
</form>
{% if guess %}
<a href="/start-game" class="btn primary raised" id="new-game">New location!</a>
{% endif %}
{% endblock main %}