Compare commits

..

No commits in common. "139ea0805cd5b68fb7b98bf525a0d8899811dea8" and "d81b2a285ebc3da9efc5d091fdd614ca28d991d4" have entirely different histories.

5 changed files with 47 additions and 130 deletions

1
Cargo.lock generated
View file

@ -723,7 +723,6 @@ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"futures", "futures",
"gloo-net 0.5.0", "gloo-net 0.5.0",
"gloo-timers",
"http 1.2.0", "http 1.2.0",
"leptos", "leptos",
"leptos_actix", "leptos_actix",

View file

@ -22,7 +22,6 @@ web-sys = { version = "0.3", features = ["Event"] }
nostr-sdk = "0.37" nostr-sdk = "0.37"
tokio = "1" tokio = "1"
gloo-net = "0.5" gloo-net = "0.5"
gloo-timers = { version = "0.2", features = ["futures"] }
futures = "0.3" futures = "0.3"
wasm-bindgen-futures = "0.4" wasm-bindgen-futures = "0.4"
serde_json="1.0.133" serde_json="1.0.133"

View file

@ -81,12 +81,10 @@ th {
/* Style for individual cells */ /* Style for individual cells */
.editable-cell { .editable-cell {
display: flex; /* Use flexbox for better layout control */ display: block; /* Allow it to fill the parent container */
flex-direction: column; /* Stack children vertically */
width: 100%; /* Full width of the allocated space */ width: 100%; /* Full width of the allocated space */
height: 100%; /* Full height of the allocated space */ height: 100%; /* Full height of the allocated space */
position: relative; /* Relative positioning for absolute children */ position: relative;
box-sizing: border-box; /* Ensure padding and border are included in width/height */
} }
/* Style for the input field inside the editable cell */ /* Style for the input field inside the editable cell */
@ -102,33 +100,8 @@ th {
background-color: transparent; /* Make background transparent */ background-color: transparent; /* Make background transparent */
} }
/* Style for the focused input field */ /* Optional: Style for the focused input field */
.editable-cell-input:focus { .editable-cell-input:focus {
background-color: #e0f7fa; /* Light blue background when focused */ background-color: #e0f7fa; /* Light blue background when focused */
border: 1px solid #00796b; /* Green border when focused */ border: 1px solid #00796b; /* Green border when focused */
}
/* Style for the suggestions list */
.editable-cell-suggestions {
position: absolute; /* Position suggestions absolutely within the cell */
top: 100%; /* Place suggestions below the input field */
left: 0; /* Align suggestions with the left edge of the cell */
width: 100%; /* Full width of the cell */
max-height: 200px; /* Limit height of suggestions list */
overflow-y: auto; /* Add scrollbar if suggestions exceed max height */
background-color: white; /* White background for suggestions */
border: 1px solid #ddd; /* Light border for suggestions */
z-index: 10; /* Ensure suggestions appear above other content */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Add shadow for better visibility */
}
/* Style for individual suggestion items */
.editable-cell-suggestions li {
padding: 8px; /* Add padding for spacing */
cursor: pointer; /* Change cursor to pointer on hover */
border-bottom: 1px solid #eee; /* Add separator between items */
}
.editable-cell-suggestions li:hover {
background-color: #f5f5f5; /* Light gray background on hover */
} }

View file

@ -9,8 +9,6 @@ pub fn EditableCell(
key: Arc<String>, key: Arc<String>,
focused_cell: ReadSignal<Option<String>>, focused_cell: ReadSignal<Option<String>>,
set_focused_cell: WriteSignal<Option<String>>, set_focused_cell: WriteSignal<Option<String>>,
on_focus: Option<Callback<()>>,
on_blur: Option<Callback<()>>,
) -> impl IntoView { ) -> impl IntoView {
let input_ref = create_node_ref::<html::Input>(); let input_ref = create_node_ref::<html::Input>();
let (local_value, set_local_value) = create_signal(value.clone()); let (local_value, set_local_value) = create_signal(value.clone());
@ -35,9 +33,6 @@ pub fn EditableCell(
move |_| { move |_| {
log!("Focus gained for key: {}", key); log!("Focus gained for key: {}", key);
set_focused_cell.set(Some(key.to_string())); set_focused_cell.set(Some(key.to_string()));
if let Some(on_focus) = &on_focus {
on_focus.call(());
}
} }
}; };
@ -45,9 +40,6 @@ pub fn EditableCell(
log!("Focus lost"); log!("Focus lost");
set_focused_cell.set(None); set_focused_cell.set(None);
commit_input(); commit_input();
if let Some(on_blur) = &on_blur {
on_blur.call(());
}
}; };
// Update input field value when focused cell changes // Update input field value when focused cell changes

View file

@ -27,9 +27,6 @@ pub fn ItemsList(
// State to manage dynamic property names // State to manage dynamic property names
let (custom_properties, set_custom_properties) = create_signal(Vec::<String>::new()); let (custom_properties, set_custom_properties) = create_signal(Vec::<String>::new());
// state to manage suggestions visibility
let (show_suggestions, set_show_suggestions) = create_signal(false);
// Ensure there's an initial empty row // Ensure there's an initial empty row
set_items.set(vec![Item { set_items.set(vec![Item {
id: Uuid::new_v4().to_string(), id: Uuid::new_v4().to_string(),
@ -45,7 +42,6 @@ pub fn ItemsList(
// Fetch Wikidata suggestions // Fetch Wikidata suggestions
let fetch_wikidata_suggestions = move |key:String, query: String| { let fetch_wikidata_suggestions = move |key:String, query: String| {
log!("Fetching suggestions for key: {}, query: {}", key, query);
spawn_local(async move { spawn_local(async move {
if query.is_empty() { if query.is_empty() {
set_wikidata_suggestions.update(|suggestions| { set_wikidata_suggestions.update(|suggestions| {
@ -62,9 +58,7 @@ pub fn ItemsList(
match gloo_net::http::Request::get(&url).send().await { match gloo_net::http::Request::get(&url).send().await {
Ok(response) => { Ok(response) => {
if let Ok(data) = response.json::<WikidataResponse>().await { if let Ok(data) = response.json::<WikidataResponse>().await {
log!("Fetching suggestions for key: {}, query: {}", key, query);
set_wikidata_suggestions.update(|suggestions| { set_wikidata_suggestions.update(|suggestions| {
log!("Updated suggestions: {:?}", suggestions);
suggestions.insert(key, data.search); suggestions.insert(key, data.search);
}); });
} }
@ -169,80 +163,52 @@ pub fn ItemsList(
<td> <td>
{match property { {match property {
"Name" => view! { "Name" => view! {
<div class="editable-cell"> <EditableCell
<EditableCell value=item.name.clone()
value=item.name.clone() on_input=move |value| {
on_input=move |value| { update_item(index, "name", value.clone());
update_item(index, "name", value.clone()); fetch_wikidata_suggestions(format!("name-{}", index), value);
fetch_wikidata_suggestions(format!("name-{}", index), value); }
} key=Arc::new(format!("name-{}", index))
key=Arc::new(format!("name-{}", index)) focused_cell=focused_cell
focused_cell=focused_cell set_focused_cell=set_focused_cell.clone()
set_focused_cell=set_focused_cell.clone() />
on_focus=Some(Callback::new(move |_| { <ul>
log!("Input focused, showing suggestions");
set_show_suggestions.set(true);
}))
on_blur=Some(Callback::new(move |_| {
log!("Input blurred, delaying hiding suggestions");
spawn_local(async move {
gloo_timers::future::sleep(std::time::Duration::from_millis(500)).await;
log!("Hiding suggestions after delay");
set_show_suggestions.set(false);
});
}))
/>
{move || { {move || {
if show_suggestions.get() { let suggestions = wikidata_suggestions.get()
log!("Rendering suggestions list"); .get(&format!("name-{}", index))
view! { .cloned()
<ul class="editable-cell-suggestions"> .unwrap_or_default();
{move || { suggestions.into_iter().map(|suggestion| {
let suggestions = wikidata_suggestions.get() let label_for_click = suggestion.label.clone();
.get(&format!("name-{}", index)) let label_for_display = suggestion.label.clone();
.cloned() let description_for_click = suggestion.description.clone().unwrap_or_default();
.unwrap_or_default(); let description_for_display = suggestion.description.clone().unwrap_or_default();
log!("Suggestions for cell {}: {:?}", index, suggestions); let id = suggestion.id.clone();
suggestions.into_iter().map(|suggestion| {
let label_for_click = suggestion.label.clone(); // Tags for the item
let label_for_display = suggestion.label.clone(); let tags = vec![
let description_for_click = suggestion.description.clone().unwrap_or_default(); ("source".to_string(), "wikidata".to_string()),
let description_for_display = suggestion.description.clone().unwrap_or_default(); ("wikidata_id".to_string(), id.clone()),
let id = suggestion.id.clone(); ];
// Tags for the item view! {
let tags = vec![ <li on:click=move |_| {
("source".to_string(), "wikidata".to_string()), set_items.update(|items| {
("wikidata_id".to_string(), id.clone()), if let Some(item) = items.get_mut(index) {
]; item.description = description_for_click.clone();
item.tags.extend(tags.clone());
view! { item.wikidata_id = Some(id.clone());
<li class="editable-cell-suggestions-li" on:click=move |_| { item.name = label_for_click.clone();
set_items.update(|items| { }
if let Some(item) = items.get_mut(index) { });
item.description = description_for_click.clone(); }>
item.tags.extend(tags.clone()); { format!("{} - {}", label_for_display, description_for_display) }
item.wikidata_id = Some(id.clone()); </li>
item.name = label_for_click.clone(); }
} }).collect::<Vec<_>>()
});
set_show_suggestions.set(false);
}>
{ format!("{} - {}", label_for_display, description_for_display) }
</li>
}
}).collect::<Vec<_>>()
}}
</ul>
}
} else {
log!("Suggestions list hidden");
view! {
<ul></ul>
}
}
}} }}
</div> </ul>
}.into_view(), }.into_view(),
"Description" => view! { "Description" => view! {
<EditableCell <EditableCell
@ -251,12 +217,6 @@ pub fn ItemsList(
key=Arc::new(format!("description-{}", index)) key=Arc::new(format!("description-{}", index))
focused_cell=focused_cell focused_cell=focused_cell
set_focused_cell=set_focused_cell.clone() set_focused_cell=set_focused_cell.clone()
on_focus=Some(Callback::new(move |_| {
log!("Description input focused");
}))
on_blur=Some(Callback::new(move |_| {
log!("Description input blurred");
}))
/> />
}.into_view(), }.into_view(),
"Tags" => view! { "Tags" => view! {
@ -299,12 +259,6 @@ pub fn ItemsList(
key=Arc::new(format!("custom-{}-{}", property_clone, index)) key=Arc::new(format!("custom-{}-{}", property_clone, index))
focused_cell=focused_cell focused_cell=focused_cell
set_focused_cell=set_focused_cell.clone() set_focused_cell=set_focused_cell.clone()
on_focus=Some(Callback::new(move |_| {
log!("Custom property input focused");
}))
on_blur=Some(Callback::new(move |_| {
log!("Custom property input blurred");
}))
/> />
</td> </td>
} }