feat(web): jank search page

should actually store the results in cache and do the same thing i do
for timelines... oh well!
This commit is contained in:
əlemi 2024-08-11 14:56:42 +02:00
parent b427000364
commit 89b2b598f4
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,5 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use apb::{Base, Collection};
use leptos::*; use leptos::*;
use leptos_router::*; use leptos_router::*;
use crate::prelude::*; use crate::prelude::*;
@ -24,6 +25,14 @@ pub fn SearchPage() -> impl IntoView {
} }
); );
let text_search = create_local_resource(
move || use_query_map().get().get("q").cloned().unwrap_or_default(),
move |q| {
let search = format!("{URL_BASE}/search?q={q}");
async move { Http::fetch::<serde_json::Value>(&search, auth).await.ok() }
}
);
view! { view! {
<blockquote class="mt-3 mb-3"> <blockquote class="mt-3 mb-3">
<details open> <details open>
@ -54,5 +63,24 @@ pub fn SearchPage() -> impl IntoView {
</div> </div>
</details> </details>
</blockquote> </blockquote>
{move || match text_search.get() {
None => Some(view! { <p class="center"><small>searching...</small></p> }.into_view()),
Some(None) => None,
Some(Some(items)) => Some(view! {
// TODO this is jank af! i should do the same thing i do for timelines, aka first process
// all items and store in cache and then pass a vec of strings here!!!
<For
each=move || items.ordered_items()
key=|item| item.id().unwrap_or_default().to_string()
children=move |item| {
view! {
<Item item=item.into() />
<hr />
}.into_view()
}
/ >
}.into_view())
}}
} }
} }