Skip to content

Commit 8c5d451

Browse files
committed
fix: ssr search endppoint
1 parent 91c93fc commit 8c5d451

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

packages/app/app/components/RepoSearch.vue

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
<script lang="ts" setup>
22
import type { RepoNode } from "../../server/utils/types";
33
4-
const search = useSessionStorage("search", "");
4+
const route = useRoute();
5+
const router = useRouter();
6+
const search = computed({
7+
get: () => {
8+
const text = route.query.text;
9+
return typeof text === "string" ? text : "";
10+
},
11+
set: (value: string) => {
12+
const queryText = value.trim();
13+
router.replace({
14+
query: {
15+
...route.query,
16+
text: queryText || undefined,
17+
},
18+
});
19+
},
20+
});
521
const searchResults = ref<RepoNode[]>([]);
622
const isLoading = ref(false);
723
@@ -24,11 +40,10 @@ watch(
2440
isLoading.value = true;
2541
2642
try {
27-
const response = await fetch(
28-
`/api/repo/search?text=${encodeURIComponent(query)}`,
29-
{ signal: controller.signal },
30-
);
31-
const data = await response.json();
43+
const data = await $fetch<{ nodes?: RepoNode[] }>("/api/repo/search", {
44+
query: { text: query },
45+
signal: controller.signal,
46+
});
3247
3348
if (abortController !== controller) {
3449
return;
@@ -47,7 +62,7 @@ watch(
4762
}
4863
}
4964
},
50-
{ immediate: false },
65+
{ immediate: true },
5166
);
5267
5368
const examples = [
@@ -78,7 +93,6 @@ const examples = [
7893
},
7994
];
8095
81-
const router = useRouter();
8296
function openFirstResult() {
8397
const [first] = searchResults.value;
8498
if (first) {

0 commit comments

Comments
 (0)