add link icon
This commit is contained in:
15
Makefile
15
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
|
||||
|
||||
@@ -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
|
||||
|
||||
2
migrations/20250604201415_add_icon_to_links.down.sql
Normal file
2
migrations/20250604201415_add_icon_to_links.down.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE links
|
||||
DROP COLUMN icon;
|
||||
2
migrations/20250604201415_add_icon_to_links.up.sql
Normal file
2
migrations/20250604201415_add_icon_to_links.up.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE links
|
||||
ADD COLUMN icon TEXT NOT NULL DEFAULT "missing" AFTER link;
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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::mysql::MySqlQueryResult, sqlx::Error> {
|
||||
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<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 {
|
||||
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<sqlx::mysql::MySqlQueryResult, sqlx::Error> {
|
||||
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(),
|
||||
})
|
||||
|
||||
@@ -13,8 +13,8 @@ pub async fn get_links() -> Result<Vec<crate::models::Link>, 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 {
|
||||
<input type="url"
|
||||
name="icon"
|
||||
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" />
|
||||
</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"
|
||||
target="_blank"
|
||||
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>
|
||||
{move || {
|
||||
edit.get().then(|| {
|
||||
|
||||
Reference in New Issue
Block a user