forked from alemi/upub
feat(web): bad search bar and page
This commit is contained in:
parent
85a2bedc1a
commit
188dd7ee81
3 changed files with 72 additions and 4 deletions
|
@ -112,6 +112,7 @@ pub fn App() -> impl IntoView {
|
||||||
<Route path="/web/objects/:id" view=move || view! { <ObjectPage tl=context_tl /> } />
|
<Route path="/web/objects/:id" view=move || view! { <ObjectPage tl=context_tl /> } />
|
||||||
|
|
||||||
<Route path="/web/debug" view=DebugPage />
|
<Route path="/web/debug" view=DebugPage />
|
||||||
|
<Route path="/web/search" view=SearchPage />
|
||||||
|
|
||||||
<Route path="/" view=move || view! { <Redirect path="/web" /> } />
|
<Route path="/" view=move || view! { <Redirect path="/web" /> } />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
|
@ -6,11 +6,24 @@ use crate::prelude::*;
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Navigator() -> impl IntoView {
|
pub fn Navigator() -> impl IntoView {
|
||||||
let auth = use_context::<Auth>().expect("missing auth context");
|
let auth = use_context::<Auth>().expect("missing auth context");
|
||||||
|
let (query, set_query) = create_signal("".to_string());
|
||||||
view! {
|
view! {
|
||||||
<a href="/web/home"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="home timeline" /></a>
|
<table class="align">
|
||||||
<a href="/web/server"><input class="w-100" type="submit" value="server timeline" /></a>
|
<tr>
|
||||||
<a href="/web/about"><input class="w-100" type="submit" value="about" /></a>
|
<td class="w-100">
|
||||||
<a href="/web/debug"><input class="w-100" type="submit" value="debug" class:hidden=move|| !auth.present() /></a>
|
<input type="text" class="w-100" on:input=move |ev| {
|
||||||
|
set_query.set(event_target_value(&ev))
|
||||||
|
} />
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href={move|| format!("/web/search?q={}", query.get())}><input type="submit" value="go" /></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td colspan="2"><a href="/web/home"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="home timeline" /></a></td></tr>
|
||||||
|
<tr><td colspan="2"><a href="/web/server"><input class="w-100" type="submit" value="server timeline" /></a></td></tr>
|
||||||
|
<tr><td colspan="2"><a href="/web/about"><input class="w-100" type="submit" value="about" /></a></td></tr>
|
||||||
|
<tr><td colspan="2"><a href="/web/debug"><input class="w-100" type="submit" value="debug" class:hidden=move|| !auth.present() /></a></td></tr>
|
||||||
|
</table>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -331,3 +331,57 @@ pub fn DebugPage() -> impl IntoView {
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn SearchPage() -> impl IntoView {
|
||||||
|
let auth = use_context::<Auth>().expect("missing auth context");
|
||||||
|
|
||||||
|
let user = create_local_resource(
|
||||||
|
move || use_query_map().get().get("q").cloned().unwrap_or_default(),
|
||||||
|
move |q| {
|
||||||
|
let user_fetch = Uri::api(FetchKind::User, &q, true);
|
||||||
|
async move { Some(Arc::new(Http::fetch::<serde_json::Value>(&user_fetch, auth).await.ok()?)) }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let object = create_local_resource(
|
||||||
|
move || use_query_map().get().get("q").cloned().unwrap_or_default(),
|
||||||
|
move |q| {
|
||||||
|
let object_fetch = Uri::api(FetchKind::Object, &q, true);
|
||||||
|
async move { Some(Arc::new(Http::fetch::<serde_json::Value>(&object_fetch, auth).await.ok()?)) }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<Breadcrumb>search</Breadcrumb>
|
||||||
|
<blockquote class="mt-1 mb-1">
|
||||||
|
<details open>
|
||||||
|
<summary class="mb-2">
|
||||||
|
<code class="cw center color ml-s w-100">users</code>
|
||||||
|
</summary>
|
||||||
|
{move || match user.get() {
|
||||||
|
None => None,
|
||||||
|
Some(None) => None,
|
||||||
|
Some(Some(u)) => Some(view! {
|
||||||
|
<ActorBanner object=u />
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
</details>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<blockquote class="mt-1 mb-1">
|
||||||
|
<details open>
|
||||||
|
<summary class="mb-2">
|
||||||
|
<code class="cw center color ml-s w-100">objects</code>
|
||||||
|
</summary>
|
||||||
|
{move || match object.get() {
|
||||||
|
None => None,
|
||||||
|
Some(None) => None,
|
||||||
|
Some(Some(o)) => Some(view! {
|
||||||
|
<Object object=o />
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
</details>
|
||||||
|
</blockquote>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue