1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 06:18:27 -04:00
jarv.is/components/RepositoryCard/RepositoryCard.tsx
Jake Jarvis eccf2108c7
React 18 (#863)
* gymnastics to make theme script work with react 18 hydration

* try next 12.1.3 canary to fix SSG head tags?

* revert theme script changes

* next 12.1.3-canary.3

* double-revert some of the use-theme.tsx changes

* separate theme restoration script & move to _document

* bump next

* bump next (again)

* clean up some theme stuff

* use hashed image URLs in webmanifest and feeds

* text experimental react config

* Update ThemeScript.tsx

* switch selfie image to `layout="raw"`

* use `layout="raw"` for all non-imported images

* revert raw images in some places, messes up responsiveness

* fix nitpicky "no divs inside buttons" html validation error

* fix react-player hydration errors

* fix hydration errors from server/client time zone differences

* clean up hydration fixes

* Update format-date.ts

* last-minute cleanup
2022-04-06 09:37:16 -04:00

140 lines
3.3 KiB
TypeScript

import Link from "../Link";
import { StarOcticon, ForkOcticon } from "../Icons";
import { useHasMounted } from "../../hooks/use-has-mounted";
import { formatDateTZ, formatTimeAgo } from "../../lib/helpers/format-date";
import { styled } from "../../lib/styles/stitches.config";
import { siteLocale } from "../../lib/config";
import type { RepositoryType } from "../../types";
const Wrapper = styled("div", {
width: "100%",
padding: "1.2em 1.2em 0.8em 1.2em",
border: "1px solid $kindaLight",
borderRadius: "$rounded",
fontSize: "0.85em",
color: "$mediumDark",
// light-dark theme switch fading
transition: "border 0.25s ease",
});
const Name = styled(Link, {
fontSize: "1.2em",
fontWeight: 600,
});
const Description = styled("p", {
marginTop: "0.7em",
marginBottom: "0.5em",
lineHeight: 1.7,
});
const Meta = styled("div", {
display: "flex",
flexWrap: "wrap",
alignItems: "baseline",
});
const MetaItem = styled("div", {
marginRight: "1.5em",
fontSize: "0.875em",
lineHeight: 2,
color: "$medium",
});
const MetaLink = styled("a", {
color: "inherit",
textDecoration: "none",
"&:hover": {
color: "$link",
},
});
const MetaIcon = styled("svg", {
width: "16px",
height: "16px",
verticalAlign: "text-bottom",
marginRight: "0.5em",
fill: "currentColor",
});
const LanguageCircle = styled("span", {
display: "inline-block",
position: "relative",
width: "1.15em",
height: "1.15em",
marginRight: "0.5em",
borderRadius: "50%",
verticalAlign: "text-top",
});
export type RepositoryCardProps = RepositoryType & {
className?: string;
};
const RepositoryCard = ({
name,
url,
description,
language,
stars,
forks,
updatedAt,
className,
}: RepositoryCardProps) => {
const hasMounted = useHasMounted();
return (
<Wrapper className={className}>
<Name href={url}>{name}</Name>
{description && <Description>{description}</Description>}
<Meta>
{language && (
<MetaItem>
<LanguageCircle css={{ backgroundColor: language.color }} />
<span>{language.name}</span>
</MetaItem>
)}
{stars > 0 && (
<MetaItem>
<MetaLink
href={`${url}/stargazers`}
title={`${stars.toLocaleString(siteLocale)} ${stars === 1 ? "star" : "stars"}`}
target="_blank"
rel="noopener noreferrer"
>
<MetaIcon as={StarOcticon} />
<span>{stars.toLocaleString(siteLocale)}</span>
</MetaLink>
</MetaItem>
)}
{forks > 0 && (
<MetaItem>
<MetaLink
href={`${url}/network/members`}
title={`${forks.toLocaleString(siteLocale)} ${forks === 1 ? "fork" : "forks"}`}
target="_blank"
rel="noopener noreferrer"
>
<MetaIcon as={ForkOcticon} />
<span>{forks.toLocaleString(siteLocale)}</span>
</MetaLink>
</MetaItem>
)}
{/* only use relative "time ago" on client side, since it'll be outdated via SSG and cause hydration errors */}
<MetaItem title={formatDateTZ(updatedAt)}>
<span>Updated {hasMounted ? formatTimeAgo(updatedAt) : `on ${formatDateTZ(updatedAt, "PP")}`}</span>
</MetaItem>
</Meta>
</Wrapper>
);
};
export default RepositoryCard;