add link icon

This commit is contained in:
Romulus21
2025-06-04 23:37:44 +02:00
parent 4a8d22cb47
commit 735abf577c
7 changed files with 29 additions and 22 deletions

View File

@@ -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: install:
git pull
npx tailwindcss -i ./input.css -o ./style/output.css --minify npx tailwindcss -i ./input.css -o ./style/output.css --minify
wasm-pack build --target=web --no-default-features --features=hydrate wasm-pack build --target=web --no-default-features --features=hydrate
sudo systemctl stop rust_leptos.service sudo systemctl stop rust_leptos.service
cargo sqlx migrate run
cargo leptos build --release cargo leptos build --release
sudo systemctl start rust_leptos.service sudo systemctl start rust_leptos.service

View File

@@ -32,7 +32,10 @@ WantedBy=multi-user.target
[x] router [x] router
[ ] value gestion des erreurs [ ] value gestion des erreurs
[x] deploy [x] deploy
[ ] hydratation [x] hydratation
[ ] liens icones
[ ] liens position
[ ] liens edition
## pages ## pages
[x] liens [x] liens

View File

@@ -0,0 +1,2 @@
ALTER TABLE links
DROP COLUMN icon;

View File

@@ -0,0 +1,2 @@
ALTER TABLE links
ADD COLUMN icon TEXT NOT NULL DEFAULT "missing" AFTER link;

View File

@@ -8,10 +8,10 @@ async fn create_pool() -> sqlx::MySqlPool {
.await .await
.expect("could not connect to database_url"); .expect("could not connect to database_url");
sqlx::migrate!() /*sqlx::migrate!()
.run(&pool) .run(&pool)
.await .await
.expect("migrations failed"); .expect("migrations failed");*/
pool pool
} }

View File

@@ -5,6 +5,7 @@ pub struct Link {
pub id: u64, pub id: u64,
pub link: String, pub link: String,
pub name: String, pub name: String,
pub icon: String,
position: i64, position: i64,
created_at: String, created_at: String,
} }
@@ -14,11 +15,13 @@ impl Link {
pub async fn insert( pub async fn insert(
name: String, name: String,
link: String, link: String,
icon: String,
) -> Result<sqlx::mysql::MySqlQueryResult, sqlx::Error> { ) -> Result<sqlx::mysql::MySqlQueryResult, sqlx::Error> {
sqlx::query!( 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, name,
link, link,
icon,
chrono::Local::now().naive_local(), chrono::Local::now().naive_local(),
) )
.execute(crate::database::get_db()) .execute(crate::database::get_db())
@@ -27,11 +30,12 @@ impl Link {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
pub async fn get_all() -> Result<Vec<Self>, sqlx::Error> { pub async fn get_all() -> Result<Vec<Self>, 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 { .map(|x| Self {
id: x.id, id: x.id,
name: x.name, name: x.name,
link: x.link, link: x.link,
icon: x.icon,
position: x.position, position: x.position,
created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(), created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(),
}) })
@@ -45,13 +49,14 @@ impl Link {
direction: String, direction: String,
) -> Result<sqlx::mysql::MySqlQueryResult, sqlx::Error> { ) -> Result<sqlx::mysql::MySqlQueryResult, sqlx::Error> {
let link = sqlx::query!( 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 link_id
) )
.map(|x| Self { .map(|x| Self {
id: x.id, id: x.id,
name: x.name, name: x.name,
link: x.link, link: x.link,
icon: x.icon,
position: x.position, position: x.position,
created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(), created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(),
}) })

View File

@@ -13,8 +13,8 @@ pub async fn get_links() -> Result<Vec<crate::models::Link>, ServerFnError> {
} }
#[server(LinkAction, "/api")] #[server(LinkAction, "/api")]
pub async fn add_value(name: String, link: String) -> Result<(), ServerFnError> { pub async fn add_value(name: String, link: String, icon: String) -> Result<(), ServerFnError> {
crate::models::Link::insert(name, link) crate::models::Link::insert(name, link, icon)
.await .await
.map(|_| ()) .map(|_| ())
.map_err(|x| { .map_err(|x| {
@@ -67,6 +67,7 @@ pub fn Links() -> impl IntoView {
<input type="url" <input type="url"
name="icon" name="icon"
placeholder="http..." placeholder="http..."
prop:value=move || reset_form.get()
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-60" /> class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-60" />
</div> </div>
<div> <div>
@@ -134,7 +135,12 @@ fn Link<T: 'static + Clone, S: 'static>(
<a class="bg-prim-light hover:bg-prim-lightest border-b hover:border-third border-transparent text-xl rounded-lg text-center hover:text-third transition-colors px-5 py-4 min-w-60 inline-block" <a class="bg-prim-light hover:bg-prim-lightest border-b hover:border-third border-transparent text-xl rounded-lg text-center hover:text-third transition-colors px-5 py-4 min-w-60 inline-block"
target="_blank" target="_blank"
href={move || link.with(|x| x.link.to_string())}> href={move || link.with(|x| x.link.to_string())}>
{move || link.with(|x| x.name.to_string())} <div class="size-54 min-w-54 bg-red-400 mb-2">
<img src={move || link.with(|x| x.icon.to_string())}
alt={move || link.with(|x| x.name.to_string())} class="size-54 object-cover" />
</div>
<span>{move || link.with(|x| x.name.to_string())}</span>
</a> </a>
{move || { {move || {
edit.get().then(|| { edit.get().then(|| {