-
setOpenManager(false)}
- class="flex items-center p-1"
- >
-
-
+
+
+
)}
diff --git a/src/components/search.tsx b/src/components/search.tsx
index c09395a..d7f1667 100644
--- a/src/components/search.tsx
+++ b/src/components/search.tsx
@@ -1,6 +1,8 @@
-import { useLocation, useNavigate } from "@solidjs/router";
-import { createSignal, onCleanup, onMount, Show } from "solid-js";
+import { Client, CredentialManager } from "@atcute/client";
+import { A, useLocation, useNavigate } from "@solidjs/router";
+import { createResource, createSignal, For, onCleanup, onMount, Show, Suspense } from "solid-js";
import { isTouchDevice } from "../layout";
+import { createDebouncedValue } from "../utils/hooks/debounced";
export const [showSearch, setShowSearch] = createSignal(false);
@@ -38,11 +40,28 @@ const SearchButton = () => {
const Search = () => {
const navigate = useNavigate();
let searchInput!: HTMLInputElement;
+ const rpc = new Client({
+ handler: new CredentialManager({ service: "https://public.api.bsky.app" }),
+ });
onMount(() => {
if (useLocation().pathname !== "/") searchInput.focus();
});
+ const fetchTypeahead = async (input: string) => {
+ if (!input.length) return [];
+ const res = await rpc.get("app.bsky.actor.searchActorsTypeahead", {
+ params: { q: input, limit: 5 },
+ });
+ if (res.ok) {
+ return res.data.actors;
+ }
+ return [];
+ };
+
+ const [input, setInput] = createSignal
();
+ const [search] = createResource(createDebouncedValue(input, 300), fetchTypeahead);
+
const processInput = (input: string) => {
input = input.trim().replace(/^@/, "");
if (!input.length) return;
@@ -54,6 +73,8 @@ const Search = () => {
(input.startsWith("https://") || input.startsWith("http://"))
) {
navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`);
+ } else if (search()?.length) {
+ navigate(`/at://${search()![0].did}`);
} else {
const uri = input
.replace("at://", "")
@@ -64,11 +85,12 @@ const Search = () => {
`/at://${uriParts[0]}${uriParts.length > 1 ? `/${uriParts.slice(1).join("/")}` : ""}`,
);
}
+ setShowSearch(false);
};
return (