feat(autocomplete name): autofill name with wikidata suggestions
This commit is contained in:
parent
22e6ae38d4
commit
e9b4c12a6d
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="EMPTY_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Compware.iml" filepath="$PROJECT_DIR$/.idea/Compware.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -7,7 +7,12 @@
|
||||||
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="eb7658c0-6daa-4def-a5ad-3d491e9b76c8" name="Changes" comment="" />
|
<list default="true" id="eb7658c0-6daa-4def-a5ad-3d491e9b76c8" name="Changes" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/app.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/app.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/components/editable_cell.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/editable_cell.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/components/items_list.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/items_list.rs" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
@ -28,26 +33,31 @@
|
||||||
}</component>
|
}</component>
|
||||||
<component name="ProjectId" id="2pngw94pMiCvlaySWR2RUofHfwc" />
|
<component name="ProjectId" id="2pngw94pMiCvlaySWR2RUofHfwc" />
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
|
<option name="autoscrollToSource" value="true" />
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="openDirectoriesWithSingleClick" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"Cargo.Run compareware.executor": "Run",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.rust.reset.selective.auto.import": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "main",
|
"RunOnceActivity.rust.reset.selective.auto.import": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"git-widget-placeholder": "editable-cells-wiki",
|
||||||
"node.js.detected.package.tslint": "true",
|
"last_opened_file_path": "/home/noah/Desktop/Internship_tasks/Compware",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.detected.package.tslint": "true",
|
||||||
"nodejs_package_manager_path": "npm",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
|
"nodejs_package_manager_path": "npm",
|
||||||
"org.rust.first.attach.projects": "true",
|
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
|
||||||
|
"org.rust.first.attach.projects": "true",
|
||||||
|
"settings.editor.selected.configurable": "settings.sync",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="Cargo.Run compareware">
|
<component name="RunManager" selected="Cargo.Run compareware">
|
||||||
<configuration name="Run compareware" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
<configuration name="Run compareware" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
<option name="buildProfileId" value="dev" />
|
<option name="buildProfileId" value="dev" />
|
||||||
|
@ -97,6 +107,7 @@
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1733407491778</updated>
|
<updated>1733407491778</updated>
|
||||||
<workItem from="1733407498746" duration="5306000" />
|
<workItem from="1733407498746" duration="5306000" />
|
||||||
|
<workItem from="1734955316600" duration="1248000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use crate::components::items_list::ItemsList;
|
use crate::components::items_list::ItemsList;
|
||||||
use crate::models::item::{Item, ReviewWithRating};
|
use crate::models::item::Item;
|
||||||
use crate::nostr::NostrClient;
|
use crate::nostr::NostrClient;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub fn EditableCell(
|
||||||
|
|
||||||
let handle_input = move |e: web_sys::Event| {
|
let handle_input = move |e: web_sys::Event| {
|
||||||
let new_value = event_target_value(&e);
|
let new_value = event_target_value(&e);
|
||||||
set_input_value(new_value.clone());
|
set_input_value.set(new_value.clone());
|
||||||
on_input(new_value);
|
on_input(new_value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ use crate::components::tag_editor::TagEditor;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use leptos::logging::log;
|
||||||
|
use crate::models::item::Item;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
struct WikidataSuggestion {
|
struct WikidataSuggestion {
|
||||||
|
@ -11,14 +14,6 @@ struct WikidataSuggestion {
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct Item {
|
|
||||||
id: String,
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
tags: Vec<(String, String)>,
|
|
||||||
wikidata_id: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ItemsList(
|
pub fn ItemsList(
|
||||||
|
@ -32,7 +27,7 @@ pub fn ItemsList(
|
||||||
let fetch_wikidata_suggestions = move |query: String| {
|
let fetch_wikidata_suggestions = move |query: String| {
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
set_wikidata_suggestions(Vec::new());
|
set_wikidata_suggestions.set(Vec::new());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +39,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 {
|
||||||
set_wikidata_suggestions(data.search);
|
set_wikidata_suggestions.set(data.search);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => log!("Failed to fetch Wikidata suggestions"),
|
Err(_) => log!("Failed to fetch Wikidata suggestions"),
|
||||||
|
@ -87,13 +82,14 @@ pub fn ItemsList(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add a new item
|
// Add a new item
|
||||||
let add_item = move || {
|
let add_item = move |_: web_sys::MouseEvent|{
|
||||||
set_items.update(|items| {
|
set_items.update(|items| {
|
||||||
items.push(Item {
|
items.push(Item {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
description: String::new(),
|
description: String::new(),
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
|
reviews:vec![],
|
||||||
wikidata_id: None,
|
wikidata_id: None,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -131,17 +127,24 @@ pub fn ItemsList(
|
||||||
/>
|
/>
|
||||||
<ul>
|
<ul>
|
||||||
{move || {
|
{move || {
|
||||||
wikidata_suggestions.get().iter().map(|suggestion| {
|
let suggestions = wikidata_suggestions.get().to_vec();
|
||||||
|
suggestions.into_iter().map(|suggestion| {
|
||||||
|
// Clone all necessary fields upfront
|
||||||
|
let label_for_click = suggestion.label.clone();
|
||||||
|
let label_for_display = suggestion.label.clone();
|
||||||
|
let description = suggestion.description.clone().unwrap_or_default();
|
||||||
|
let id = suggestion.id.clone();
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<li on:click=move |_| {
|
<li on:click=move |_| {
|
||||||
set_items.update(|items| {
|
set_items.update(|items| {
|
||||||
if let Some(item) = items.get_mut(index) {
|
if let Some(item) = items.get_mut(index) {
|
||||||
item.wikidata_id = Some(suggestion.id.clone());
|
item.wikidata_id = Some(id.clone());
|
||||||
item.name = suggestion.label.clone();
|
item.name = label_for_click.clone(); // Use the cloned version for updating
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}>
|
}>
|
||||||
{ format!("{} - {}", suggestion.label, suggestion.description.clone().unwrap_or_default()) }
|
{ format!("{} - {}", label_for_display, description) } // Use the cloned version for display
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +164,7 @@ pub fn ItemsList(
|
||||||
<TagEditor
|
<TagEditor
|
||||||
tags=item.tags.clone()
|
tags=item.tags.clone()
|
||||||
on_add=move |key, value| add_tag(index, key, value)
|
on_add=move |key, value| add_tag(index, key, value)
|
||||||
on_remove=move |tag_index| remove_tag(index, tag_index)
|
on_remove=Arc::new (Mutex:: new (move |tag_index:usize| remove_tag(index, tag_index)))
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
// Actions
|
// Actions
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn TagEditor(
|
pub fn TagEditor(
|
||||||
tags: Vec<(String, String)>,
|
tags: Vec<(String, String)>,
|
||||||
on_add: impl Fn(String, String) + 'static,
|
on_add: impl Fn(String, String) + 'static,
|
||||||
on_remove: impl Fn(usize) + 'static,
|
on_remove: Arc<Mutex<dyn FnMut(usize) + Send + Sync>>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
let (key, set_key) = create_signal(String::new());
|
let (key, set_key) = create_signal(String::new());
|
||||||
let (value, set_value) = create_signal(String::new());
|
let (value, set_value) = create_signal(String::new());
|
||||||
|
|
||||||
let add_tag = move || {
|
let add_tag = move |_| {
|
||||||
if !key.get().is_empty() && !value.get().is_empty() {
|
if !key.get().is_empty() && !value.get().is_empty() {
|
||||||
on_add(key.get(), value.get());
|
on_add(key.get(), value.get());
|
||||||
set_key(String::new());
|
set_key.set(String::new());
|
||||||
set_value(String::new());
|
set_value.set(String::new());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,10 +24,16 @@ pub fn TagEditor(
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
{tags.iter().enumerate().map(|(index, (k, v))| {
|
{tags.iter().enumerate().map(|(index, (k, v))| {
|
||||||
|
let on_remove = on_remove.clone();
|
||||||
view! {
|
view! {
|
||||||
<li>
|
<li>
|
||||||
{format!("{}: {}", k, v)}
|
{format!("{}: {}", k, v)}
|
||||||
<button on:click=move |_| on_remove(index)>{ "Remove" }</button>
|
<button on:click=move |_| {
|
||||||
|
let mut on_remove = on_remove.lock().unwrap();
|
||||||
|
on_remove(index);
|
||||||
|
}>
|
||||||
|
{ "Remove" }
|
||||||
|
</button>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
}).collect::<Vec<_>>()}
|
}).collect::<Vec<_>>()}
|
||||||
|
@ -32,12 +41,12 @@ pub fn TagEditor(
|
||||||
<input
|
<input
|
||||||
placeholder="Key"
|
placeholder="Key"
|
||||||
value={key.get()}
|
value={key.get()}
|
||||||
on:input=move |e| set_key(event_target_value(&e))
|
on:input=move |e| set_key.set(event_target_value(&e))
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
placeholder="Value"
|
placeholder="Value"
|
||||||
value={value.get()}
|
value={value.get()}
|
||||||
on:input=move |e| set_value(event_target_value(&e))
|
on:input=move |e| set_value.set(event_target_value(&e))
|
||||||
/>
|
/>
|
||||||
<button on:click=add_tag>{ "Add Tag" }</button>
|
<button on:click=add_tag>{ "Add Tag" }</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue