Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stats layout and add tooltips #101

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 78 additions & 50 deletions src/components/RepositoryContributionsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,86 @@ export const RepositoryContributionsCard = ({
contributions: Contributions;
}) => {
return (
<div className="card bg-base-100">
<div className="card-body">
<h2 className="card-title flex justify-between">
<div className="flex justify-center items-center gap-2">
<Image
src={repository.owner.avatarUrl}
alt={repository.owner.login}
width={40}
height={40}
className="rounded-full"
/>
<Link
href={`https://github.com/${repository.owner.login}/${repository.name}`}
rel="noopener noreferrer"
target="_blank"
className="hover:underline"
aria-label={`${repository.name}`}
>
{repository.owner.login}/{repository.name}
</Link>
</div>
<div className="tooltip tooltip-left" data-tip="Total contributions">
<div className="rounded outline outline-1 cursor-default px-2">
{totalCount}
</div>
</div>
</h2>
<div className="max-h-[22rem] hide-scrollbar overflow-auto flex flex-col gap-1">
{nodes?.map(({ pullRequest: { state, title, id, url } }: any) => (
<div key={id} className="flex items-center justify-between gap-2">
<a href={url} target="_blank" className="truncate" title={title}>
{title}
</a>
<span
className={`h-fit rounded p-1 ${
state === "MERGED"
? "bg-purple-500"
: state === "CLOSED"
? "bg-red-500"
: "bg-green-500"
}`}
<div className="card bg-base-100 overflow-visible">
<div className="sm:w-auto card bg-base-100 repository-card">
<div className="card-body">
<div className="card-title flex items-center justify-between">
<div className="flex items-center space-x-2 flex-grow">
<Image
src={repository.owner.avatarUrl}
alt={repository.owner.login}
width={40}
height={40}
className="rounded-full"
/>
<div
className="grid grid-flow-col gap-2 flex-grow tooltip text-left"
data-tip={`${repository.owner.login}/${repository.name}`}
>
{state === "MERGED" ? (
<FaCodeMerge size={18} />
) : state === "CLOSED" ? (
<IoIosCloseCircleOutline size={18} />
) : (
<GoIssueOpened size={18} />
)}
</span>
<Link
href={`https://github.com/${repository.owner.login}/${repository.name}`}
rel="noopener noreferrer"
target="_blank"
className="hover:underline truncate flex-grow"
aria-label={`${repository.name}`}
>
<h3 className="logged-user truncate">
{repository.owner.login}/{repository.name}
</h3>
</Link>
</div>
<div
className="tooltip tooltip-left"
data-tip="Total contributions"
>
<div className="rounded outline outline-1 cursor-default px-2">
{totalCount}
</div>
</div>
</div>
))}
</div>
<div className="max-h-[22rem] hide-scrollbar overflow-auto flex flex-col gap-1">
{nodes?.map(
(
{ pullRequest: { state, title, id, url } }: any,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a better type here than any, I think there's already a type in types/github.ts for that

index: number
) => (
<div
key={id}
className={`flex items-center justify-between gap-2 tooltip text-left ${
index === 0 ? "tooltip-bottom" : "tooltip-top"
}`}
data-tip={title}
Copy link
Contributor Author

@theflucs theflucs Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround for correctly displaying the tooltips.
I noticed that if it is set to tooltip-top the first item's tooltip doesn't show, as well as if it is set to tooltip-bottom the last one doesn't appear either. Feel free to discard these lines if you know a cleaner way to achieve the correct displaying of the tooltips.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workaround is fine if you have 2+ PRs, but in case you only have one it won't appear. We need to find a different solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I didn't notice it. And it makes sense it doesn't work. We need to find another way 🤔
@CBID2 you can take over this if you like

>
<a
href={url}
target="_blank"
className="truncate"
title={title}
>
{title}
</a>
<span
className={`h-fit rounded p-1 ${
state === "MERGED"
? "bg-purple-500"
: state === "CLOSED"
? "bg-red-500"
: "bg-green-500"
}`}
>
{state === "MERGED" ? (
<FaCodeMerge size={18} />
) : state === "CLOSED" ? (
<IoIosCloseCircleOutline size={18} />
) : (
<GoIssueOpened size={18} />
)}
</span>
</div>
)
)}
</div>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/stats/[login].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default function Stats() {
</li>
</ul>
</div>
<div className="w-full grid xl:grid-cols-3 gap-3 mb-3 md:grid-cols-2">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 pb-4">
{filteredRepositories?.length > 0
? filteredRepositories?.map(
({ repository, contributions }, i) => (
Expand Down Expand Up @@ -251,7 +251,7 @@ export default function Stats() {
onChange={(e) => setSearchQuery(e.target.value)}
/>
</div>
<div className="flex sm:items-start items-center justify-center sm:justify-start">
<div className="flex sm:items-start items-center justify-center md:justify-start">
<input
type="checkbox"
name="hide-own-repo"
Expand Down
Loading