Compware/src/app.rs
ryan 07405db017 feat(typeahead): Enhance Bloodhound and Typeahead initialization logic
- Improved Bloodhound initialization by adding explicit global storage for the instance.
- Enhanced `initialize_bloodhound` to include proper rate limiting, wildcard configuration, and tokenizer setup.
- Refactored `initialize_typeahead` to include a more robust dataset configuration with templates for rendering suggestions.
- Fixed DOM element access in the `on:input` handler to ensure proper interaction with the input element.
- Simplified the `remote_fn` logic in `initialize_bloodhound` for fetching and syncing suggestions.
- Added error handling and logging for better debugging during Typeahead initialization.
- Ensured closures are properly registered in the global scope to handle Typeahead events.
- Updated the JavaScript initialization script to use bracket notation for safer handler invocation.
- Removed the additional inclusion of `corejs-typeahead` script from the `<head>` section.
2025-04-08 17:55:46 +03:00

67 lines
2.5 KiB
Rust

use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use leptos::logging::log;
use crate::components::items_list::{ItemsList, load_items_from_db};
use crate::models::item::Item;
use leptos::spawn_local;
// use tokio::sync::mpsc;
// use crate::nostr::NostrClient;
// use nostr_sdk::serde_json;
#[component]
pub fn App() -> impl IntoView {
provide_meta_context();
// Signal to manage the list of items
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
// let (tx, mut rx) = mpsc::channel::<String>(100);
// // Nostr client subscription for items
// spawn_local(async move {
// let nostr_client = NostrClient::new("wss://relay.example.com").await.unwrap();
// nostr_client.subscribe_to_items(tx.clone()).await.unwrap();
// while let Some(content) = rx.recv().await {
// if let Ok(item) = serde_json::from_str::<Item>(&content) {
// set_items.update(|items| items.push(item));
// }
// }
// });
view! {
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.min.js"></script>
</head>
<Router>
<Routes>
<Route path="/*url" view=move || {
let location = use_location();
let current_url = move || location.pathname.get();
// Proper async handling
spawn_local({
let current_url = current_url.clone();
async move {
match load_items_from_db(&current_url()).await {
Ok(items) => set_items.set(items),
Err(e) => log!("Error loading items: {}", e),
}
}
});
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
url=current_url()
items=items_signal
set_items=set_items />
</div>
}
}/>
</Routes>
</Router>
}
}