Skip to content

Commit 2242494

Browse files
migrated
1 parent 08d964d commit 2242494

File tree

1 file changed

+62
-101
lines changed

1 file changed

+62
-101
lines changed

src/components/TutorialMetadata.tsx

Lines changed: 62 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import { useRouter } from "next/router"
2-
import { useTranslation } from "next-i18next"
3-
import { Badge, Box, Flex, HStack, Text } from "@chakra-ui/react"
1+
import { useRouter } from "next/router";
2+
import { useTranslation } from "next-i18next";
3+
import { Badge } from "@chakra-ui/react";
44

5-
import type { Lang, TranslationKey } from "@/lib/types"
6-
import { TutorialFrontmatter } from "@/lib/interfaces"
5+
import type { Lang, TranslationKey } from "@/lib/types";
6+
import { TutorialFrontmatter } from "@/lib/interfaces";
77

8-
import CopyToClipboard from "@/components/CopyToClipboard"
9-
import Emoji from "@/components/Emoji"
10-
import InlineLink from "@/components/Link"
11-
import Translation from "@/components/Translation"
12-
import TutorialTags from "@/components/TutorialTags"
8+
import CopyToClipboard from "@/components/CopyToClipboard";
9+
import Emoji from "@/components/Emoji";
10+
import InlineLink from "@/components/Link";
11+
import Translation from "@/components/Translation";
12+
import TutorialTags from "@/components/TutorialTags";
1313

14-
import { getLocaleTimestamp } from "@/lib/utils/time"
14+
import { getLocaleTimestamp } from "@/lib/utils/time";
15+
import { Flex } from "./ui/flex";
1516

1617
export type TutorialMetadataProps = {
17-
frontmatter: TutorialFrontmatter
18-
timeToRead: number
19-
}
18+
frontmatter: TutorialFrontmatter;
19+
timeToRead: number;
20+
};
2021

2122
export enum Skill {
2223
BEGINNER = "beginner",
@@ -25,120 +26,80 @@ export enum Skill {
2526
}
2627

2728
export const getSkillTranslationId = (skill: Skill): TranslationKey =>
28-
`page-developers-tutorials:page-tutorial-${
29-
Skill[skill.toUpperCase() as keyof typeof Skill]
30-
}`
29+
`page-developers-tutorials:page-tutorial-${Skill[skill.toUpperCase() as keyof typeof Skill]
30+
}`;
3131

3232
const TutorialMetadata = ({
3333
frontmatter,
3434
timeToRead,
3535
}: TutorialMetadataProps) => {
36-
const { locale } = useRouter()
37-
const { t } = useTranslation("page-developers-tutorials")
36+
const { locale } = useRouter();
37+
const { t } = useTranslation("page-developers-tutorials");
3838

39-
const hasSource = frontmatter.source && frontmatter.sourceUrl
40-
const published = frontmatter.published
41-
const author = frontmatter.author
42-
const address = frontmatter.address
39+
const hasSource = frontmatter.source && frontmatter.sourceUrl;
40+
const published = frontmatter.published;
41+
const author = frontmatter.author;
42+
const address = frontmatter.address;
4343

4444
return (
45-
<Flex
46-
flexDirection="column"
47-
justifyContent="space-between"
48-
borderBottomWidth={{ base: 0, lg: "1px" }}
49-
borderBottomColor="border"
50-
>
51-
<Flex justifyContent="space-between" alignItems="center" w="full" mb={8}>
52-
<Flex flexWrap="wrap" w="full">
45+
<Flex className=" flex-col justify-between pb-2 border-b-0 lg:border-b border-border">
46+
<Flex className=" justify-between items-center w-full mb-8">
47+
<div className="flex flex-wrap w-full">
5348
<TutorialTags tags={frontmatter.tags} />
54-
</Flex>
55-
<Flex
56-
as={Badge}
57-
variant="secondary"
58-
alignSelf="flex-start"
59-
mb={2}
60-
whiteSpace="nowrap"
61-
>
49+
</div>
50+
<Badge variant="secondary" className="self-start mb-2 whitespace-nowrap">
6251
{t(getSkillTranslationId(frontmatter.skill as Skill))}
63-
</Flex>
52+
</Badge>
6453
</Flex>
65-
<HStack
66-
mb={6}
67-
flexWrap="wrap"
68-
mt={-4}
69-
fontSize="sm"
70-
color="text300"
71-
justifyContent="flex-start"
72-
alignItems="flex-start"
73-
spacing={4}
74-
>
54+
<div className="flex flex-wrap gap-4 mt-[-1rem] text-sm text-text300 mb-6">
7555
{author && (
76-
<Box>
56+
<div>
7757
<Emoji className="me-2 text-sm" text=":writing_hand:" />
7858
{author}
79-
</Box>
59+
</div>
8060
)}
8161
{hasSource && (
82-
<Box>
62+
<div >
8363
<Emoji className="me-2 text-sm" text=":books:" />
8464
<InlineLink href={frontmatter.sourceUrl}>
8565
{frontmatter.source}
8666
</InlineLink>
87-
</Box>
67+
</div>
8868
)}
8969
{published && (
90-
<Box>
70+
<div >
9171
<Emoji className="me-2 text-sm" text=":calendar:" />{" "}
9272
{getLocaleTimestamp(locale! as Lang, published)}
93-
</Box>
73+
</div>
9474
)}
95-
<Box>
96-
<Emoji className="me-2 text-sm" text=":stopwatch:" />
75+
<div >
76+
<Emoji className="me-2 text-sm" text=":stopwatch:" />
9777
{timeToRead} {t("comp-tutorial-metadata-minute-read")} minute read
98-
</Box>
99-
</HStack>
100-
<HStack
101-
mb={6}
102-
flexWrap="wrap"
103-
mt={-4}
104-
fontSize="sm"
105-
color="text300"
106-
justifyContent="flex-start"
107-
>
108-
{address && (
109-
<Flex flexWrap="wrap" w="full" me={4}>
110-
<CopyToClipboard text={address}>
111-
{(isCopied) => (
112-
<Box
113-
color="primary.base"
114-
cursor="pointer"
115-
overflow="hidden"
116-
textOverflow="ellipsis"
117-
fontFamily="monospace"
118-
bg="ednBackground"
119-
px={1}
120-
fontSize="sm"
121-
_hover={{
122-
bg: "primary100",
123-
}}
124-
>
125-
<Text
126-
as={Translation}
127-
textTransform="uppercase"
78+
</div>
79+
</div>
80+
{address && (
81+
<div className="flex flex-wrap mt-[-1rem] text-sm text-text300 mb-6">
82+
<CopyToClipboard text={address}>
83+
{(isCopied) => (
84+
<div
85+
className="text-primary cursor-pointer overflow-hidden text-ellipsis font-mono bg-ednBackground px-1 text-sm hover:bg-primary100"
86+
>
87+
<div className="uppercase">
88+
<Translation
12889
id="comp-tutorial-metadata-tip-author"
12990
/>{" "}
130-
{address} {isCopied && <Translation id="copied" />}
131-
{isCopied && (
132-
<Emoji className="me-2 text-sm" text=":white_check_mark:" />
133-
)}
134-
</Box>
135-
)}
136-
</CopyToClipboard>
137-
</Flex>
138-
)}
139-
</HStack>
91+
</div>
92+
{address} {isCopied && <Translation id="copied" />}
93+
{isCopied && (
94+
<Emoji className="mr-2 text-sm" text=":white_check_mark:" />
95+
)}
96+
</div>
97+
)}
98+
</CopyToClipboard>
99+
</div>
100+
)}
140101
</Flex>
141-
)
142-
}
102+
);
103+
};
143104

144-
export default TutorialMetadata
105+
export default TutorialMetadata;

0 commit comments

Comments
 (0)