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.
Merge branch 'beta' into issue-open-sauced#1374
- Loading branch information
Showing
13 changed files
with
201 additions
and
93 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
79 changes: 79 additions & 0 deletions
79
components/atoms/TopContributorCard/top-contributor-card.tsx
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,79 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { getAvatarByUsername } from "lib/utils/github"; | ||
import useFollowUser from "lib/hooks/useFollowUser"; | ||
import useSupabaseAuth from "lib/hooks/useSupabaseAuth"; | ||
|
||
import Avatar from "../Avatar/avatar"; | ||
import Button from "../Button/button"; | ||
|
||
export interface TopContributorCardProps { | ||
login: string; | ||
} | ||
|
||
const TopContributorCard = ({ login }: TopContributorCardProps) => { | ||
const router = useRouter(); | ||
const currentPath = router.asPath; | ||
|
||
const { isError: notFollowing, follow, unFollow } = useFollowUser(login); | ||
const [host, setHost] = useState(""); | ||
const { sessionToken, signIn } = useSupabaseAuth(); | ||
|
||
const handleFollowContributor = async () => { | ||
try { | ||
if (notFollowing) { | ||
await follow(); | ||
return; | ||
} | ||
await unFollow(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
setHost(window.location.origin as string); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div className="flex items-center justify-between w-full gap-4 bg-light-slate-1"> | ||
<Link href={`/user/${login}`}> | ||
<div className="flex items-center gap-2"> | ||
<Avatar isCircle size={35} avatarURL={getAvatarByUsername(login)} /> | ||
<p className="font-semibold text-light-slate-12">{login}</p> | ||
</div> | ||
</Link> | ||
{sessionToken && !notFollowing ? ( | ||
<Button | ||
onClick={() => | ||
sessionToken | ||
? handleFollowContributor() | ||
: signIn({ provider: "github", options: { redirectTo: `${host}/${currentPath}` } }) | ||
} | ||
className="!px-2 !py-1" | ||
variant="primary" | ||
> | ||
following | ||
</Button> | ||
) : ( | ||
<Button | ||
onClick={() => | ||
sessionToken | ||
? handleFollowContributor() | ||
: signIn({ provider: "github", options: { redirectTo: `${host}/${currentPath}` } }) | ||
} | ||
className="!px-2 !py-1 border-light-orange-7 text-light-orange-10" | ||
variant="text" | ||
> | ||
follow | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TopContributorCard; |
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
components/molecules/TopContributorsPanel/top-contributors-panel.tsx
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,32 @@ | ||
import React from "react"; | ||
import TopContributorCard from "components/atoms/TopContributorCard/top-contributor-card"; | ||
import { useFetchTopContributors } from "lib/hooks/useFetchTopContributors"; | ||
import SkeletonWrapper from "components/atoms/SkeletonLoader/skeleton-wrapper"; | ||
|
||
interface TopContributorsPanelProps { | ||
loggedInUserLogin: string; | ||
} | ||
const TopContributorsPanel = ({ loggedInUserLogin }: TopContributorsPanelProps) => { | ||
const { data, isLoading } = useFetchTopContributors(); | ||
|
||
const topContributorsWithoutLoggedInUser = data ? data.filter((user) => user.login !== loggedInUserLogin) : []; | ||
const top3Contributors = topContributorsWithoutLoggedInUser.slice(0, 3).map((user) => user.login); | ||
|
||
return ( | ||
<div className="flex flex-col max-w-xs gap-6 p-6 bg-white border rounded-xl"> | ||
<h2 className="pb-2 text-2xl border-b">Top Contributors</h2> | ||
|
||
{isLoading && | ||
Array.from({ length: 3 }).map((_, i) => ( | ||
<div key={i} className="flex items-center justify-between gap-4 "> | ||
<SkeletonWrapper radius={100} height={40} width={40} /> <SkeletonWrapper height={40} classNames="w-full" /> | ||
</div> | ||
))} | ||
{top3Contributors.map((login, i) => ( | ||
<TopContributorCard key={i} login={login} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TopContributorsPanel; |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import useSWR, { Fetcher } from "swr"; | ||
import publicApiFetcher from "lib/utils/public-api-fetcher"; | ||
|
||
type TopContributorsResponse = { login: string }[]; | ||
|
||
const useFetchTopContributors = () => { | ||
const { data, error, mutate } = useSWR<TopContributorsResponse, Error>( | ||
"users/top", | ||
publicApiFetcher as Fetcher<TopContributorsResponse, Error> | ||
); | ||
|
||
return { | ||
data: data ?? [], | ||
isLoading: !error && !data, | ||
isError: !!error, | ||
mutate, | ||
}; | ||
}; | ||
|
||
export { useFetchTopContributors }; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 +1,20 @@ | ||
import { ComponentStory } from "@storybook/react"; | ||
import TopUserCard from "components/atoms/TopUserCard/top-user-card"; | ||
import { StoryFn } from "@storybook/react"; | ||
import TopContributorCard from "components/atoms/TopContributorCard/top-contributor-card"; | ||
|
||
const storyConfig = { | ||
title: "Design System/Atoms/TopUserCard", | ||
title: "Design System/Atoms/TopContributorCard", | ||
}; | ||
export default storyConfig; | ||
|
||
const TopUserCardTemplate: ComponentStory<typeof TopUserCard> = (args) => <TopUserCard {...args} />; | ||
const TopContributorCardTemplate: StoryFn<typeof TopContributorCard> = (args) => <TopContributorCard {...args} />; | ||
|
||
export const Following = TopUserCardTemplate.bind({}); | ||
export const NotFollowing = TopUserCardTemplate.bind({}); | ||
export const Following = TopContributorCardTemplate.bind({}); | ||
export const NotFollowing = TopContributorCardTemplate.bind({}); | ||
|
||
Following.args = { | ||
username: "diivi", | ||
following: true, | ||
login: "diivi", | ||
}; | ||
|
||
NotFollowing.args = { | ||
username: "ogdev-01", | ||
following: false, | ||
login: "ogdev-01", | ||
}; |
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 { Meta, StoryFn } from "@storybook/react"; | ||
import TopContributorsPanel from "components/molecules/TopContributorsPanel/top-contributors-panel"; | ||
|
||
const storyConfig = { | ||
title: "Design System/Molecules/TopContributorsPanel", | ||
} as Meta<typeof TopContributorsPanel>; | ||
|
||
export default storyConfig; | ||
|
||
const TopContributorsPanelTemplate: StoryFn<typeof TopContributorsPanel> = (args) => <TopContributorsPanel {...args} />; | ||
|
||
export const Default = TopContributorsPanelTemplate.bind({}); | ||
|
||
Default.args = { | ||
loggedInUserLogin: "ogdev-01", | ||
}; |
This file was deleted.
Oops, something went wrong.