Compare commits
2 commits
1a5c245250
...
7939c9e7b6
Author | SHA1 | Date | |
---|---|---|---|
7939c9e7b6 | |||
fddec7f728 |
2 changed files with 29 additions and 6 deletions
|
@ -8,9 +8,7 @@ use crate::models::item::Item;
|
|||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use wasm_bindgen::JsCast;
|
||||
use urlencoding::encode;
|
||||
use gloo_net::http::Request;
|
||||
use serde_json::Value;
|
||||
use web_sys::window;
|
||||
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
struct WikidataSuggestion {
|
||||
|
@ -52,8 +50,16 @@ pub fn ItemsList(
|
|||
// Signal to store the fetched property labels
|
||||
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
|
||||
|
||||
fn get_current_url() -> String {
|
||||
window()
|
||||
.and_then(|win| win.location().href().ok())
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
}
|
||||
|
||||
let current_url = get_current_url();
|
||||
|
||||
spawn_local(async move {
|
||||
match load_items_from_db().await {
|
||||
match load_items_from_db(¤t_url).await {
|
||||
Ok(loaded_items) => {
|
||||
// Set the loaded items
|
||||
if loaded_items.is_empty() {
|
||||
|
@ -172,8 +178,8 @@ pub fn ItemsList(
|
|||
}
|
||||
|
||||
//function to load items from database
|
||||
async fn load_items_from_db() -> Result<Vec<Item>, String> {
|
||||
let response = gloo_net::http::Request::get("/api/items")
|
||||
async fn load_items_from_db(url: &str) -> Result<Vec<Item>, String> {
|
||||
let response = gloo_net::http::Request::get("/api/items?url={}")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|err| format!("Failed to fetch items: {:?}", err))?;
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,4 +1,6 @@
|
|||
#[cfg(feature = "ssr")]
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
use actix_files::Files;
|
||||
|
@ -55,11 +57,26 @@ async fn main() -> std::io::Result<()> {
|
|||
//.wrap(middleware::Compress::default())
|
||||
// Pass the database as shared state
|
||||
.app_data(web::Data::new(db))
|
||||
// Register URL routing
|
||||
.service(web::resource("/").route(web::get().to(index)))
|
||||
.service(web::resource("/{url}").route(web::get().to(url_handler)))
|
||||
})
|
||||
.bind(&addr)?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
#[cfg(feature = "ssr")]
|
||||
// Define the index handler
|
||||
async fn index() -> HttpResponse {
|
||||
HttpResponse::Ok().body("Welcome to CompareWare!")
|
||||
}
|
||||
#[cfg(feature = "ssr")]
|
||||
// Define the URL handler
|
||||
async fn url_handler(url: web::Path<String>) -> HttpResponse {
|
||||
let url = url.into_inner();
|
||||
// TO DO: Implement URL-based content storage and editing functionality
|
||||
HttpResponse::Ok().body(format!("You are viewing the content at {}", url))
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[actix_web::get("favicon.ico")]
|
||||
|
|
Loading…
Add table
Reference in a new issue