forked from open-sauced/app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated
/explore
page (open-sauced#4053)
- Loading branch information
Showing
14 changed files
with
301 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import Card from "components/atoms/Card/card"; | ||
import { Spinner } from "components/atoms/SpinLoader/spin-loader"; | ||
import CardRepoList, { RepoList } from "components/molecules/CardRepoList/card-repo-list"; | ||
import useFetchWorkspace from "lib/hooks/api/useFetchWorkspace"; | ||
import { useGetWorkspaceRepositories } from "lib/hooks/api/useGetWorkspaceRepositories"; | ||
import { useWorkspaceMembers } from "lib/hooks/api/useWorkspaceMembers"; | ||
import { getAvatarById, getAvatarByUsername } from "lib/utils/github"; | ||
|
||
export default function WorkspaceCard({ workspaceId }: { workspaceId: string }) { | ||
const { data: workspace, isLoading, isError } = useFetchWorkspace({ workspaceId }); | ||
const { data: members, isLoading: isMembersLoading, isError: isMembersError } = useWorkspaceMembers({ workspaceId }); | ||
const workspaceOwner = members.find((member) => member.role === "owner"); | ||
|
||
const { | ||
data: workspaceRepositoriesData, | ||
isLoading: isWorkspaceRepositoriesLoading, | ||
error: isWorkspaceRepositoriesError, | ||
} = useGetWorkspaceRepositories({ workspaceId }); | ||
|
||
const workspaceRepositories = | ||
workspaceRepositoriesData?.data?.map((data) => { | ||
const owner = data.repo.full_name.split("/").at(0) ?? ""; | ||
return { repoOwner: owner, repoName: data.repo.name, repoIcon: getAvatarByUsername(owner) }; | ||
}) ?? ([] as RepoList[]); | ||
|
||
return ( | ||
<Link href={`/workspaces/${workspaceId}`}> | ||
<Card className="flex flex-col gap-4 justify-between py-[1.25rem] w-full"> | ||
{!(isLoading || isMembersLoading || isWorkspaceRepositoriesLoading) ? ( | ||
<> | ||
<div className="self-start flex flex-col gap-4"> | ||
<div className="flex gap-2 items-center"> | ||
<Image | ||
src={getAvatarById((workspaceOwner?.user_id ?? 0).toString())} | ||
alt={`workspace_owner_${workspaceOwner?.user_id}`} | ||
width={20} | ||
height={20} | ||
className="rounded-md" | ||
/> | ||
<p className="text-slate-500 text-sm">{workspaceOwner?.member.name}</p> | ||
</div> | ||
|
||
<section className="flex flex-col gap-2"> | ||
<h1>{workspace?.name}</h1> | ||
<p className="text-sm text-slate-500"> | ||
{(workspace?.description.length ?? 0) > 0 ? workspace?.description : "No description given."} | ||
</p> | ||
</section> | ||
</div> | ||
|
||
<CardRepoList repoList={workspaceRepositories} limit={3} /> | ||
</> | ||
) : ( | ||
<div className="flex items-center justify-center w-full h-36"> | ||
<Spinner /> | ||
</div> | ||
)} | ||
</Card> | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test("Loads explore dashboard page", async ({ page }) => { | ||
await page.goto("/explore/topic/javascript"); | ||
await expect(page.getByRole("button", { name: "Connect with GitHub", exact: true })).toBeVisible(); | ||
await page.goto("/explore"); | ||
await expect(page.getByRole("button", { name: "Connect with GitHub" }).first()).toBeVisible(); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import useSWR, { Fetcher } from "swr"; | ||
import { publicApiFetcher } from "lib/utils/public-api-fetcher"; | ||
|
||
export default function useFetchWorkspace({ workspaceId }: { workspaceId: string }) { | ||
const { data, error, isLoading, mutate } = useSWR<Workspace, Error>( | ||
`workspaces/${workspaceId}`, | ||
publicApiFetcher as Fetcher<Workspace, Error> | ||
); | ||
|
||
return { | ||
data, | ||
isError: error, | ||
isLoading, | ||
mutate, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import useSWR, { Fetcher } from "swr"; | ||
import { publicApiFetcher } from "lib/utils/public-api-fetcher"; | ||
|
||
export interface HistogramTopRepo { | ||
repo_name: string; | ||
bucket: string; | ||
star_count: number; | ||
} | ||
|
||
export default function useFetchTrendingRepositories() { | ||
const { data, error } = useSWR<HistogramTopRepo[], Error>( | ||
`histogram/top/stars`, | ||
publicApiFetcher as Fetcher<HistogramTopRepo[], Error> | ||
); | ||
|
||
return { | ||
data: data | ||
? data.filter( | ||
(repo) => !repo.repo_name.toLowerCase().includes("-auto") || !repo.repo_name.toLowerCase().includes("crack") | ||
) | ||
: [], | ||
isLoading: !error && !data, | ||
isError: !!error, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.