Compare commits
No commits in common. "eba20abf5aafb8b95d03d5cbdb4a47bf02de8e3e" and "8860ace51ffb0e123edee399699dd8ad336a4f99" have entirely different histories.
eba20abf5a
...
8860ace51f
2 changed files with 11 additions and 60 deletions
25
src/app.rs
25
src/app.rs
|
@ -1,7 +1,5 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use leptos_router::*;
|
|
||||||
use leptos::logging::log;
|
|
||||||
use crate::components::items_list::ItemsList;
|
use crate::components::items_list::ItemsList;
|
||||||
use crate::models::item::Item;
|
use crate::models::item::Item;
|
||||||
use crate::nostr::NostrClient;
|
use crate::nostr::NostrClient;
|
||||||
|
@ -28,26 +26,7 @@ pub fn App() -> impl IntoView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
view! {
|
|
||||||
<Router>
|
|
||||||
<Routes>
|
|
||||||
<Route path="/:url?" view=move || {
|
|
||||||
let params = use_params_map();
|
|
||||||
let url = move || params.with(|params| params.get("url").cloned().unwrap_or_default());
|
|
||||||
|
|
||||||
// This effect will re-run when URL changes
|
|
||||||
create_effect(move |_| {
|
|
||||||
let current_url = url();
|
|
||||||
spawn_local(async move {
|
|
||||||
// Load items for new URL
|
|
||||||
match load_items_from_db(¤t_url).await {
|
|
||||||
Ok(loaded_items) => {
|
|
||||||
set_items.set(loaded_items);
|
|
||||||
}
|
|
||||||
Err(err) => log!("Error loading items: {}", err),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
view! {
|
view! {
|
||||||
<Stylesheet href="/assets/style.css" />
|
<Stylesheet href="/assets/style.css" />
|
||||||
<Stylesheet href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
|
<Stylesheet href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
|
||||||
|
@ -56,8 +35,4 @@ pub fn App() -> impl IntoView {
|
||||||
<ItemsList items=items_signal set_items=set_items />
|
<ItemsList items=items_signal set_items=set_items />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}/>
|
|
||||||
</Routes>
|
|
||||||
</Router>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
32
src/db.rs
32
src/db.rs
|
@ -25,50 +25,26 @@ mod db_impl {
|
||||||
// Create the database schema
|
// Create the database schema
|
||||||
pub async fn create_schema(&self) -> Result<(), Error> {
|
pub async fn create_schema(&self) -> Result<(), Error> {
|
||||||
let conn = self.conn.lock().await;
|
let conn = self.conn.lock().await;
|
||||||
|
|
||||||
// 1. Properties table
|
|
||||||
conn.execute_batch(
|
|
||||||
"CREATE TABLE IF NOT EXISTS properties (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL UNIQUE, // Property name
|
|
||||||
global_usage_count INTEGER DEFAULT 0 // Track usage across ALL URLs
|
|
||||||
);"
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// 2. URLs table
|
|
||||||
conn.execute_batch(
|
conn.execute_batch(
|
||||||
"CREATE TABLE IF NOT EXISTS urls (
|
"CREATE TABLE IF NOT EXISTS urls (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
url TEXT NOT NULL UNIQUE, // Enforce unique URLs
|
url TEXT NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);",
|
);",
|
||||||
)?;
|
)?;
|
||||||
logging::log!("URLs table created or verified");
|
logging::log!("URLs table created or verified");
|
||||||
|
|
||||||
// 3. Items table
|
|
||||||
conn.execute_batch(
|
conn.execute_batch(
|
||||||
"CREATE TABLE IF NOT EXISTS items (
|
"CREATE TABLE IF NOT EXISTS items (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
url_id INTEGER NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
wikidata_id TEXT,
|
wikidata_id TEXT,
|
||||||
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE
|
custom_properties TEXT,
|
||||||
|
url_id INTEGER,
|
||||||
|
FOREIGN KEY (url_id) REFERENCES urls (id)
|
||||||
);",
|
);",
|
||||||
)?;
|
)?;
|
||||||
logging::log!("Items table updated with foreign key to URLs table");
|
logging::log!("Items table updated with foreign key to URLs table");
|
||||||
|
|
||||||
// 4. Junction table for custom properties
|
|
||||||
conn.execute_batch(
|
|
||||||
"CREATE TABLE IF NOT EXISTS item_properties (
|
|
||||||
item_id TEXT NOT NULL,
|
|
||||||
property_id INTEGER NOT NULL,
|
|
||||||
value TEXT NOT NULL,
|
|
||||||
PRIMARY KEY (item_id, property_id),
|
|
||||||
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
|
|
||||||
);"
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue