show ranking for each camera on sighting
This commit is contained in:
@@ -3,6 +3,6 @@ digital_shadows: "Digitaler Schatten"
|
|||||||
icon_home: "🏠"
|
icon_home: "🏠"
|
||||||
icon_camera: "📸"
|
icon_camera: "📸"
|
||||||
found_camera_title: "Kamera '%{name}' gefunden"
|
found_camera_title: "Kamera '%{name}' gefunden"
|
||||||
found_camera_body: "✨ You are a star ✨ Star dust sprinkle, sprinkle."
|
found_camera_body: "✨ Du bist #%{amount} der/die diese Kamera gefunden hat ✨"
|
||||||
ask_to_change_name: "%{name}, do you want to be named something different? No worries, change here 👇"
|
ask_to_change_name: "%{name}, do you want to be named something different? No worries, change here 👇"
|
||||||
funny_name_change_placeholder: "✨ Your new name starts here ✨"
|
funny_name_change_placeholder: "✨ Your new name starts here ✨"
|
||||||
|
@@ -3,6 +3,6 @@ digital_shadows: "Digital Shadows"
|
|||||||
icon_home: "🏠"
|
icon_home: "🏠"
|
||||||
icon_camera: "📸"
|
icon_camera: "📸"
|
||||||
found_camera_title: "Camera '%{name}' found"
|
found_camera_title: "Camera '%{name}' found"
|
||||||
found_camera_body: "✨ You are a star ✨ Star dust sprinkle, sprinkle."
|
found_camera_body: "✨ You are #%{amount} who has found this camera ✨"
|
||||||
ask_to_change_name: "%{name}, do you want to be named something different? No worries, change here 👇"
|
ask_to_change_name: "%{name}, do you want to be named something different? No worries, change here 👇"
|
||||||
funny_name_change_placeholder: "✨ Your new name starts here ✨"
|
funny_name_change_placeholder: "✨ Your new name starts here ✨"
|
||||||
|
@@ -102,8 +102,8 @@ async fn game(
|
|||||||
return Err(not_found(cookies, headers).await.into_response());
|
return Err(not_found(cookies, headers).await.into_response());
|
||||||
};
|
};
|
||||||
|
|
||||||
if backend.client_found_camera(&client, &camera).await {
|
if let Ok(number) = backend.client_found_camera(&client, &camera).await {
|
||||||
messages.info(format!("found-cam|{}", camera.name));
|
messages.info(format!("found-cam|{}|{number}", camera.name));
|
||||||
} else {
|
} else {
|
||||||
messages.info("err|Try to find a new camera!|You have already collected this camera.|");
|
messages.info("err|Try to find a new camera!|You have already collected this camera.|");
|
||||||
}
|
}
|
||||||
|
@@ -58,19 +58,33 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn client_found_camera(&self, client: &Client, camera: &Camera) -> bool {
|
pub(crate) async fn client_found_camera(
|
||||||
|
&self,
|
||||||
|
client: &Client,
|
||||||
|
camera: &Camera,
|
||||||
|
) -> Result<i64, ()> {
|
||||||
let client_uuid = client.uuid.to_string();
|
let client_uuid = client.uuid.to_string();
|
||||||
let camera_uuid = camera.uuid.to_string();
|
let camera_uuid = camera.uuid.to_string();
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Backend::Sqlite(db) => sqlx::query!(
|
Backend::Sqlite(db) => {
|
||||||
"INSERT INTO sightings(client_uuid, camera_id) VALUES (?, ?) RETURNING client_uuid",
|
sqlx::query!(
|
||||||
client_uuid,
|
"INSERT INTO sightings(client_uuid, camera_id) VALUES (?, ?)",
|
||||||
camera_uuid
|
client_uuid,
|
||||||
)
|
camera_uuid
|
||||||
.fetch_one(db)
|
)
|
||||||
.await
|
.execute(db)
|
||||||
.is_ok(),
|
.await
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
Ok(sqlx::query_scalar!(
|
||||||
|
"SELECT COUNT(client_uuid) FROM sightings WHERE camera_id = ?",
|
||||||
|
camera_uuid
|
||||||
|
)
|
||||||
|
.fetch_one(db)
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
src/page.rs
19
src/page.rs
@@ -6,7 +6,7 @@ use maud::{html, Markup, DOCTYPE};
|
|||||||
|
|
||||||
pub(crate) struct Page {
|
pub(crate) struct Page {
|
||||||
lang: Language,
|
lang: Language,
|
||||||
found_camera: Option<String>,
|
found_camera: Option<(String, i64)>,
|
||||||
new_name: bool,
|
new_name: bool,
|
||||||
err: Option<(String, String, String)>,
|
err: Option<(String, String, String)>,
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,13 @@ impl Page {
|
|||||||
self.new_name = true;
|
self.new_name = true;
|
||||||
}
|
}
|
||||||
(_, msg) if msg.starts_with("found-cam|") => {
|
(_, msg) if msg.starts_with("found-cam|") => {
|
||||||
let (_, name) = msg.split_once('|').expect("we just checked |");
|
let mut parts = msg.splitn(3, '|');
|
||||||
self.found_camera = Some(name.into());
|
let _ = parts.next().expect("just checked |");
|
||||||
|
if let (Some(name), Some(amount)) = (parts.next(), parts.next()) {
|
||||||
|
if let Ok(amount) = amount.parse::<i64>() {
|
||||||
|
self.found_camera = Some((name.into(), amount));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(_, msg) if msg.starts_with("err|") => {
|
(_, msg) if msg.starts_with("err|") => {
|
||||||
let mut parts = msg.splitn(4, '|');
|
let mut parts = msg.splitn(4, '|');
|
||||||
@@ -96,11 +101,9 @@ impl Page {
|
|||||||
main.container {
|
main.container {
|
||||||
@if let Some(found_camera) = &self.found_camera {
|
@if let Some(found_camera) = &self.found_camera {
|
||||||
article class="succ w-full" {
|
article class="succ w-full" {
|
||||||
header { (t!("found_camera_title", name = found_camera)) }
|
header { (t!("found_camera_title", name = found_camera.0)) }
|
||||||
(t!("found_camera_body"))
|
(t!("found_camera_body", amount = found_camera.1))
|
||||||
" "
|
footer { a href="#ranking" { "See your ranking" } }
|
||||||
a href="#ranking" { "See your ranking" }
|
|
||||||
footer { (found_camera) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if self.new_name {
|
@if self.new_name {
|
||||||
|
Reference in New Issue
Block a user