Compare commits

...

2 commits

2 changed files with 60 additions and 11 deletions

View file

@ -1,5 +1,7 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use leptos::logging::log;
use crate::components::items_list::ItemsList;
use crate::models::item::Item;
use crate::nostr::NostrClient;
@ -26,13 +28,36 @@ pub fn App() -> impl IntoView {
}
}
});
view! {
<Stylesheet href="/assets/style.css" />
<Stylesheet href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
<div>
<h1>{ "CompareWare" }</h1>
<ItemsList items=items_signal set_items=set_items />
</div>
<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(&current_url).await {
Ok(loaded_items) => {
set_items.set(loaded_items);
}
Err(err) => log!("Error loading items: {}", err),
}
});
});
view! {
<Stylesheet href="/assets/style.css" />
<Stylesheet href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
<div>
<h1>{ "CompareWare" }</h1>
<ItemsList items=items_signal set_items=set_items />
</div>
}
}/>
</Routes>
</Router>
}
}

View file

@ -25,26 +25,50 @@ mod db_impl {
// Create the database schema
pub async fn create_schema(&self) -> Result<(), Error> {
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(
"CREATE TABLE IF NOT EXISTS urls (
id INTEGER PRIMARY KEY,
url TEXT NOT NULL,
url TEXT NOT NULL UNIQUE, // Enforce unique URLs
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);",
)?;
logging::log!("URLs table created or verified");
// 3. Items table
conn.execute_batch(
"CREATE TABLE IF NOT EXISTS items (
id TEXT PRIMARY KEY,
url_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT,
wikidata_id TEXT,
custom_properties TEXT,
url_id INTEGER,
FOREIGN KEY (url_id) REFERENCES urls (id)
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE
);",
)?;
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(())
}