|
1 | 1 | import React, { useCallback, useEffect, useMemo, useState } from "react"; |
2 | 2 | import { Locale, useLocale } from "./locale"; |
3 | 3 | import { useSearch } from "src/utils/search"; |
4 | | -import { ProjectEntity } from "@dzcode.io/models/dist/project"; |
5 | | -import { ContributorEntity } from "@dzcode.io/models/dist/contributor"; |
6 | | -import { ContributionEntity } from "@dzcode.io/models/dist/contribution"; |
7 | | -import { RepositoryEntity } from "@dzcode.io/models/dist/repository"; |
8 | 4 | import { useSearchModal } from "src/utils/search-modal"; |
9 | 5 | import { ContributionCard } from "./contribution-card"; |
10 | 6 | import { ContributorCard } from "./contributor-card"; |
11 | 7 | import { ProjectCard } from "./project-card"; |
| 8 | +import { GetContributionsResponse } from "@dzcode.io/api/dist/contribution/types"; |
| 9 | +import { GetContributorsResponse } from "@dzcode.io/api/dist/contributor/types"; |
| 10 | +import { GetProjectsResponse } from "@dzcode.io/api/dist/project/types"; |
12 | 11 |
|
13 | 12 | export function Search(): JSX.Element { |
14 | 13 | const { localize } = useLocale(); |
@@ -40,42 +39,37 @@ export function Search(): JSX.Element { |
40 | 39 | }, []); |
41 | 40 |
|
42 | 41 | const projectsList = useMemo(() => { |
43 | | - return (results?.searchResults.results || []) |
44 | | - .filter((result) => result.indexUid === "project") |
45 | | - .flatMap((projects) => projects.hits) as unknown as Array< |
46 | | - Pick<ProjectEntity, "id" | "name"> & { |
47 | | - totalRepoContributorCount: number; |
48 | | - totalRepoScore: number; |
49 | | - totalRepoStars: number; |
50 | | - ranking: number; |
51 | | - } |
52 | | - >; |
53 | | - }, [results?.searchResults.results]); |
| 42 | + return ( |
| 43 | + (results || []) |
| 44 | + .filter((result) => result.indexUid === "project") |
| 45 | + // @TODO-OB: fix type casting |
| 46 | + .flatMap((projects) => projects.hits) as unknown as Array< |
| 47 | + GetProjectsResponse["projects"][number] |
| 48 | + > |
| 49 | + ); |
| 50 | + }, [results]); |
54 | 51 |
|
55 | 52 | const contributorsList = useMemo(() => { |
56 | | - return (results?.searchResults.results || []) |
57 | | - .filter((result) => result.indexUid === "contributor") |
58 | | - .flatMap((contributors) => contributors.hits) as unknown as Array< |
59 | | - Pick<ContributorEntity, "id" | "name" | "avatarUrl"> & { |
60 | | - ranking: number; |
61 | | - totalContributionScore: number; |
62 | | - totalRepositoryCount: number; |
63 | | - } |
64 | | - >; |
65 | | - }, [results?.searchResults.results]); |
| 53 | + return ( |
| 54 | + (results || []) |
| 55 | + .filter((result) => result.indexUid === "contributor") |
| 56 | + // @TODO-OB: fix type casting |
| 57 | + .flatMap((contributors) => contributors.hits) as unknown as Array< |
| 58 | + GetContributorsResponse["contributors"][number] |
| 59 | + > |
| 60 | + ); |
| 61 | + }, [results]); |
66 | 62 |
|
67 | 63 | const contributionsList = useMemo(() => { |
68 | | - return (results?.searchResults.results || []) |
69 | | - .filter((result) => result.indexUid === "contribution") |
70 | | - .flatMap((contributions) => contributions.hits) as unknown as Array< |
71 | | - Pick<ContributionEntity, "id" | "title" | "type" | "url" | "updatedAt" | "activityCount"> & { |
72 | | - repository: Pick<RepositoryEntity, "id" | "owner" | "name"> & { |
73 | | - project: Pick<ProjectEntity, "id" | "name">; |
74 | | - }; |
75 | | - contributor: Pick<ContributorEntity, "id" | "name" | "username" | "avatarUrl">; |
76 | | - } |
77 | | - >; |
78 | | - }, [results?.searchResults.results]); |
| 64 | + return ( |
| 65 | + (results || []) |
| 66 | + .filter((result) => result.indexUid === "contribution") |
| 67 | + // @TODO-OB: fix type casting |
| 68 | + .flatMap((contributions) => contributions.hits) as unknown as Array< |
| 69 | + GetContributionsResponse["contributions"][number] |
| 70 | + > |
| 71 | + ); |
| 72 | + }, [results]); |
79 | 73 |
|
80 | 74 | const searchTextOutput = useMemo(() => { |
81 | 75 | if (isFetching) { |
|
0 commit comments