diff --git a/Makefile b/Makefile index 54b4039..cef1036 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,8 @@ -deploy: - #npx tailwindcss -i ./input.css -o ./style/output.css --minify - #tac Cargo.toml | sed '1s/^.//' | tac > fichier_temp.txt && mv fichier_temp.txt Cargo.toml - #cargo leptos build - #cargo leptos build --release - #tac Cargo.toml | sed '1s/^/#/' | tac > fichier_temp.txt && mv fichier_temp.txt Cargo.toml - #ssh raspiwork "sudo systemctl stop rust_leptos.service" - #scp target/aarch64-unknown-linux-gnu/release/rust_leptos raspiwork:/var/www/rust_leptos/rust_leptos - #scp target/aarch64-unknown-linux-gnu/debug/rust_leptos raspiwork:/var/www/rust_leptos/rust_leptos - #scp -r target/site raspiwork:/var/www/rust_leptos/ - #ssh raspiwork "sudo systemctl start rust_leptos.service" - ssh raspitipi 'cd /home/pi/scripts/rust_leptos && git pull origin main && make install' - install: + git pull npx tailwindcss -i ./input.css -o ./style/output.css --minify wasm-pack build --target=web --no-default-features --features=hydrate sudo systemctl stop rust_leptos.service + cargo sqlx migrate run cargo leptos build --release sudo systemctl start rust_leptos.service diff --git a/README.md b/README.md index f3b0d5c..2e8ca33 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,10 @@ WantedBy=multi-user.target [x] router [ ] value gestion des erreurs [x] deploy -[ ] hydratation +[x] hydratation +[ ] liens icones +[ ] liens position +[ ] liens edition ## pages [x] liens diff --git a/migrations/20250604201415_add_icon_to_links.down.sql b/migrations/20250604201415_add_icon_to_links.down.sql new file mode 100644 index 0000000..215d44a --- /dev/null +++ b/migrations/20250604201415_add_icon_to_links.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE links +DROP COLUMN icon; diff --git a/migrations/20250604201415_add_icon_to_links.up.sql b/migrations/20250604201415_add_icon_to_links.up.sql new file mode 100644 index 0000000..2dc6678 --- /dev/null +++ b/migrations/20250604201415_add_icon_to_links.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE links +ADD COLUMN icon TEXT NOT NULL DEFAULT "missing" AFTER link; diff --git a/src/database.rs b/src/database.rs index 1e8d33f..5254415 100644 --- a/src/database.rs +++ b/src/database.rs @@ -8,10 +8,10 @@ async fn create_pool() -> sqlx::MySqlPool { .await .expect("could not connect to database_url"); - sqlx::migrate!() + /*sqlx::migrate!() .run(&pool) .await - .expect("migrations failed"); + .expect("migrations failed");*/ pool } diff --git a/src/models/link.rs b/src/models/link.rs index 503a69b..4aac25f 100644 --- a/src/models/link.rs +++ b/src/models/link.rs @@ -5,6 +5,7 @@ pub struct Link { pub id: u64, pub link: String, pub name: String, + pub icon: String, position: i64, created_at: String, } @@ -14,11 +15,13 @@ impl Link { pub async fn insert( name: String, link: String, + icon: String, ) -> Result { sqlx::query!( - "INSERT INTO links (name, link, position, created_at) VALUES (?, ?, (SELECT COALESCE(MAX(position) + 1, 1) FROM links lin), ?)", + "INSERT INTO links (name, link, icon, position, created_at) VALUES (?, ?, ?, (SELECT COALESCE(MAX(position) + 1, 1) FROM links lin), ?)", name, link, + icon, chrono::Local::now().naive_local(), ) .execute(crate::database::get_db()) @@ -27,11 +30,12 @@ impl Link { #[cfg(feature = "ssr")] pub async fn get_all() -> Result, sqlx::Error> { - sqlx::query!("SELECT id, name, link, position, created_at FROM links ORDER BY position") + sqlx::query!("SELECT id, name, link, icon, position, created_at FROM links ORDER BY position") .map(|x| Self { id: x.id, name: x.name, link: x.link, + icon: x.icon, position: x.position, created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(), }) @@ -45,13 +49,14 @@ impl Link { direction: String, ) -> Result { let link = sqlx::query!( - "SELECT id, name, link, position, created_at FROM links WHERE id = ?", + "SELECT id, name, link, icon, position, created_at FROM links WHERE id = ?", link_id ) .map(|x| Self { id: x.id, name: x.name, link: x.link, + icon: x.icon, position: x.position, created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(), }) diff --git a/src/routes/link.rs b/src/routes/link.rs index a1acb1f..1a54012 100644 --- a/src/routes/link.rs +++ b/src/routes/link.rs @@ -13,8 +13,8 @@ pub async fn get_links() -> Result, ServerFnError> { } #[server(LinkAction, "/api")] -pub async fn add_value(name: String, link: String) -> Result<(), ServerFnError> { - crate::models::Link::insert(name, link) +pub async fn add_value(name: String, link: String, icon: String) -> Result<(), ServerFnError> { + crate::models::Link::insert(name, link, icon) .await .map(|_| ()) .map_err(|x| { @@ -67,6 +67,7 @@ pub fn Links() -> impl IntoView {
@@ -134,7 +135,12 @@ fn Link( - {move || link.with(|x| x.name.to_string())} +
+ {move +
+ + {move || link.with(|x| x.name.to_string())}
{move || { edit.get().then(|| {