Skip to content

Commit a587644

Browse files
committed
revisions
1 parent a3ed3cc commit a587644

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

packages/app/app/components/RepoSearch.vue

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
11
<script lang="ts" setup>
22
import type { RepoNode } from "../../server/utils/types";
33
const search = useSessionStorage("search", "");
4-
const searchResults = ref<
5-
Array<{
6-
id: string;
7-
name: string;
8-
owner: { login: string; avatarUrl: string };
9-
stars?: number;
10-
}>
11-
>([]);
4+
const searchResults = ref<RepoNode[]>([]);
125
const isLoading = ref(false);
136
14-
let activeController: AbortController | null = null;
15-
let searchToken = 0;
7+
const activeController = ref<AbortController | null>(null);
168
const throttledSearch = useThrottle(search, 500, true, false);
179
1810
watch(
1911
throttledSearch,
2012
async (newValue) => {
21-
activeController?.abort();
13+
activeController.value?.abort();
2214
searchResults.value = [];
2315
if (!newValue) {
2416
isLoading.value = false;
2517
return;
2618
}
2719
28-
searchToken++;
29-
const currentToken = searchToken;
3020
isLoading.value = true;
31-
activeController = new AbortController();
21+
activeController.value = new AbortController();
3222
try {
3323
const response = await fetch(
3424
`/api/repo/search?text=${encodeURIComponent(newValue)}`,
35-
{ signal: activeController.signal },
25+
{ signal: activeController.value.signal },
3626
);
3727
const data = (await response.json()) as { nodes?: RepoNode[] };
38-
if (currentToken === searchToken) {
39-
searchResults.value = data.nodes ? data.nodes : [];
40-
}
28+
searchResults.value = data.nodes ? data.nodes : [];
4129
} catch (err: any) {
4230
if (err.name !== "AbortError") {
4331
console.error(err);
4432
}
4533
} finally {
46-
if (currentToken === searchToken) {
47-
isLoading.value = false;
48-
}
34+
isLoading.value = false;
4935
}
5036
},
5137
{ immediate: false },

packages/app/server/api/repo/search.get.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ export default defineEventHandler(async (event) => {
3535
ownerLogin,
3636
searchText,
3737
);
38-
const includes =
39-
repoName.includes(searchText) || ownerLogin.includes(searchText);
4038

41-
if (includes || nameScore > 0.5 || ownerScore > 0.5) {
39+
if (nameScore > 0.5 || ownerScore > 0.5) {
4240
matches.push({
4341
id: repository.id,
4442
name: repository.name,
@@ -47,7 +45,7 @@ export default defineEventHandler(async (event) => {
4745
avatarUrl: repository.owner.avatar_url,
4846
},
4947
stars: repository.stargazers_count || 0,
50-
score: Math.max(nameScore, ownerScore, includes ? 1 : 0),
48+
score: Math.max(nameScore, ownerScore),
5149
});
5250
}
5351
});

0 commit comments

Comments
 (0)