diff --git a/Cargo.lock b/Cargo.lock index c585264..26c0191 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1428,6 +1428,7 @@ dependencies = [ "leptos_router", "serde", "serde_json", + "urlencoding", "web-sys", ] @@ -1645,6 +1646,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index c850b71..163e12f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ leptos_router = { version = "0.7.0-rc2" } web-sys = { version = "0.3", features = ["Storage"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +urlencoding = "2.1.3" [workspace] members = ["."] -resolver = "2" \ No newline at end of file +resolver = "2" diff --git a/src/components/board.rs b/src/components/board.rs index 2dc4644..8182728 100644 --- a/src/components/board.rs +++ b/src/components/board.rs @@ -2,6 +2,8 @@ use leptos::*; use leptos::prelude::*; use serde::{Serialize, Deserialize}; +use crate::components::utils::generate_thumbnail; + #[derive(Clone, Serialize, Deserialize)] pub enum CellContent { Empty, @@ -11,8 +13,8 @@ pub enum CellContent { #[derive(Clone, Serialize, Deserialize)] pub struct Board { - grid: Vec>, - size: usize, + pub grid: Vec>, + pub size: usize, } impl Board { @@ -162,6 +164,16 @@ pub fn BoardCreator( "Cancel" + {move || finished.get().then(|| view! { +
+

"Board Preview"

+ Board thumbnail +
+ })} } } diff --git a/src/components/mod.rs b/src/components/mod.rs index 90d1407..7d52d3d 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1 +1,3 @@ -pub mod board; \ No newline at end of file +pub mod board; +pub mod saved_boards; +pub mod utils; \ No newline at end of file diff --git a/src/components/saved_boards.rs b/src/components/saved_boards.rs new file mode 100644 index 0000000..9d51728 --- /dev/null +++ b/src/components/saved_boards.rs @@ -0,0 +1,11 @@ +use leptos::*; +use leptos::prelude::*; + +#[component] +pub fn SavedBoards() -> impl IntoView { + view! { +
+ // Thumbnails will go here +
+ } +} \ No newline at end of file diff --git a/src/components/utils.rs b/src/components/utils.rs new file mode 100644 index 0000000..9d11e08 --- /dev/null +++ b/src/components/utils.rs @@ -0,0 +1,37 @@ +use super::board::{Board, CellContent}; + +pub fn generate_thumbnail(board: &Board) -> String { + let svg = format!( + r#" + + {} + "#, + board.grid.iter().enumerate().map(|(i, row)| { + row.iter().enumerate().map(|(j, cell)| { + let x = j as f32 * 45.0; + let y = i as f32 * 45.0; + match cell { + CellContent::Empty => format!( + r#""#, + x, y + ), + CellContent::Player => format!( + r#" + "#, + x, y, x + 20.0, y + 20.0 + ), + CellContent::Trap => format!( + r#" + "#, + x, y, x + 5.0, y + 5.0 + ), + } + }).collect::() + }).collect::() + ); + + format!( + r#"data:image/svg+xml,{}"#, + urlencoding::encode(&svg) + ) +}