From f3e958990e267d4ca82b24e5acd6fad069a815d8 Mon Sep 17 00:00:00 2001 From: jinhojang6 Date: Mon, 15 May 2023 03:20:21 +0900 Subject: [PATCH] refactor: adjust links --- .../ArticleReference/ArticleReference.tsx | 11 +--- src/components/Collapse/Collapse.tsx | 9 ++- .../ContentBlock/ContentBlock.Body.tsx | 34 +++++++----- src/components/ContentBlock/ImageBlock.tsx | 26 +++------ src/components/ContentBlock/TextBlock.tsx | 25 ++++----- src/components/FeaturedPost/FeaturedPost.tsx | 18 ++---- src/components/Navbar/Navbar.tsx | 6 +- src/components/Post/Post.tsx | 55 +++++++++---------- src/components/PostList/PostList.tsx | 12 +--- src/components/Tags/Tags.tsx | 43 ++++++--------- 10 files changed, 104 insertions(+), 135 deletions(-) diff --git a/src/components/ArticleReference/ArticleReference.tsx b/src/components/ArticleReference/ArticleReference.tsx index 45cc50a..a18af57 100644 --- a/src/components/ArticleReference/ArticleReference.tsx +++ b/src/components/ArticleReference/ArticleReference.tsx @@ -21,13 +21,8 @@ export default function ArticleReference({ year: 'numeric', }) - const handleClick = (e: React.MouseEvent) => { - e.stopPropagation() - router.push(`${slug}`) - } - return ( - + {title} @@ -43,11 +38,11 @@ export default function ArticleReference({ {localDate} - + ) } -const Reference = styled.div` +const ReferenceLink = styled(Link)` display: flex; flex-direction: column; padding: 8px 14px; diff --git a/src/components/Collapse/Collapse.tsx b/src/components/Collapse/Collapse.tsx index 682a866..81cd917 100644 --- a/src/components/Collapse/Collapse.tsx +++ b/src/components/Collapse/Collapse.tsx @@ -18,13 +18,16 @@ export default function Collapse({ ...props }: Props) { const [open, setOpen] = useState(true) - const handleClick = () => { + + const handleClick = (e: React.MouseEvent) => { + e.stopPropagation() setOpen((prev) => !prev) onClick && onClick() } + return ( -
-
+
+
handleClick(e)}> diff --git a/src/components/ContentBlock/ContentBlock.Body.tsx b/src/components/ContentBlock/ContentBlock.Body.tsx index a305511..26e53b5 100644 --- a/src/components/ContentBlock/ContentBlock.Body.tsx +++ b/src/components/ContentBlock/ContentBlock.Body.tsx @@ -1,24 +1,28 @@ +import { GoogleDocEnhanced } from '@/lib/unbody/unbody.types' import { Typography } from '@acid-info/lsd-react' import styled from '@emotion/styled' +import Link from 'next/link' +import { Authors } from '../Authors' type Props = { - title: string - author: string + data: any } -const ContentBlockBody = ({ title, author }: Props) => { +const ContentBlockBody = ({ data }: Props) => { + const firstDocument = data.document[0] + const mentions = + typeof firstDocument.mentions === 'string' + ? JSON.parse(firstDocument.mentions) + : firstDocument.mentions + return ( - - {title} - - - {author} - + + + {data.document[0].title} + + + ) } @@ -27,6 +31,10 @@ const BlockBodyContainer = styled.div` display: flex; flex-direction: column; gap: 8px; + + a { + text-decoration: none; + } ` export default ContentBlockBody diff --git a/src/components/ContentBlock/ImageBlock.tsx b/src/components/ContentBlock/ImageBlock.tsx index 847bd45..bdd4980 100644 --- a/src/components/ContentBlock/ImageBlock.tsx +++ b/src/components/ContentBlock/ImageBlock.tsx @@ -5,7 +5,6 @@ import { SearchResultItem } from '@/types/data.types' import { UnbodyImageBlock } from '@/lib/unbody/unbody.types' import { GridItem } from '../Grid/Grid' -import { PostClassType } from '../Post/Post' import ContentBlockHeader, { BlockType } from './ContentBlock.Header' import ContentBlockBody from './ContentBlock.Body' import { ResponsiveImage } from '../ResponsiveImage/ResponsiveImage' @@ -16,19 +15,16 @@ const ImageBlock = ({ doc }: Props) => { return ( {/* TODO: order not working for images */} - - + + - - - - + + + + ) } @@ -39,10 +35,6 @@ const CustomGridItem = styled(GridItem)` } ` -const BlockLink = styled(Link)` - text-decoration: none; -` - const Container = styled.div` display: flex; flex-direction: column; diff --git a/src/components/ContentBlock/TextBlock.tsx b/src/components/ContentBlock/TextBlock.tsx index 262151b..0b51a20 100644 --- a/src/components/ContentBlock/TextBlock.tsx +++ b/src/components/ContentBlock/TextBlock.tsx @@ -15,21 +15,16 @@ type Props = Omit, 'score'> const TextBlock = ({ doc }: Props) => { return ( - - - - - {doc.text} - - - - + + + + {doc.text} + + + ) } diff --git a/src/components/FeaturedPost/FeaturedPost.tsx b/src/components/FeaturedPost/FeaturedPost.tsx index d5036e8..377cc01 100644 --- a/src/components/FeaturedPost/FeaturedPost.tsx +++ b/src/components/FeaturedPost/FeaturedPost.tsx @@ -11,14 +11,12 @@ const FeaturedPost = ({ post }: Props) => { return ( - - - - - + + + ) @@ -35,8 +33,4 @@ const PostWrapper = styled.div` width: 100%; ` -const PostLink = styled(Link)` - text-decoration: none; -` - export default FeaturedPost diff --git a/src/components/Navbar/Navbar.tsx b/src/components/Navbar/Navbar.tsx index 7e02713..b5d6520 100644 --- a/src/components/Navbar/Navbar.tsx +++ b/src/components/Navbar/Navbar.tsx @@ -5,6 +5,7 @@ import { SunIcon } from '../Icons/SunIcon' import { MoonIcon } from '../Icons/MoonIcon' import { useRouter } from 'next/router' import { uiConfigs } from '@/configs/ui.configs' +import Link from 'next/link' interface NavbarProps { isDark: boolean @@ -12,10 +13,9 @@ interface NavbarProps { } export default function Navbar({ isDark, toggle }: NavbarProps) { - const router = useRouter() return ( - router.push('/')}> + @@ -57,7 +57,7 @@ const Container = styled.nav` } ` -const LogosIconContainer = styled.div` +const LogosIconContainer = styled(Link)` display: flex; align-items: center; justify-content: center; diff --git a/src/components/Post/Post.tsx b/src/components/Post/Post.tsx index bd2d32d..a4634b1 100644 --- a/src/components/Post/Post.tsx +++ b/src/components/Post/Post.tsx @@ -17,6 +17,7 @@ import { ResponsiveImage, ResponsiveImageProps, } from '../ResponsiveImage/ResponsiveImage' +import Link from 'next/link' export enum PostImageRatio { PORTRAIT = 'portrait', @@ -95,6 +96,7 @@ export default function Post({ title, description, mentions, + slug, tags = [], }, ...props @@ -103,14 +105,16 @@ export default function Post({ const _title = useMemo( () => ( - - {title} - + + + {title} + + ), - [title, size], + [title, size, slug], ) const _description = useMemo( @@ -126,16 +130,20 @@ export default function Post({ const _thumbnail = useMemo(() => { if (!showImage || !coverImage) return null if (postType === PostType.BODY) { - return - } else { - // TBD - // @jinho not sure what this is for? return ( - - + + + + ) + } else { + return ( + <> + + + {_title} {_description} - + ) } }, [ @@ -199,21 +207,6 @@ const Container = styled.div` gap: 16px; ` -// @Jinho, I have implemented the ResponsiveImage component, so I guess this is not needed anymore? -const ThumbnailContainer = styled.div<{ - aspectRatio: PostImageRatio -}>` - aspect-ratio: ${(p) => - p.aspectRatio - ? PostImageRatioOptions[p.aspectRatio] - : PostImageRatioOptions[PostImageRatio.PORTRAIT]}; - position: relative; - width: 100%; - height: 100%; - max-height: 458px; // temporary max-height based on the Figma design's max height - overflow: hidden; -` - const Thumbnail = styled(Image)` object-fit: cover; ` @@ -237,3 +230,7 @@ const PodcastAuthor = styled.div` align-items: center; gap: 12px; ` + +const PostLink = styled(Link)` + text-decoration: none; +` diff --git a/src/components/PostList/PostList.tsx b/src/components/PostList/PostList.tsx index 855b58b..dc4fa1f 100644 --- a/src/components/PostList/PostList.tsx +++ b/src/components/PostList/PostList.tsx @@ -56,11 +56,9 @@ export const PostsList = (props: Props) => { } key={index} > - - - - - + + + )) ) : ( @@ -90,7 +88,3 @@ const PostWrapper = styled.div` opacity: 0.5; } ` - -const PostLink = styled(Link)` - text-decoration: none; -` diff --git a/src/components/Tags/Tags.tsx b/src/components/Tags/Tags.tsx index eb4895b..c852fb8 100644 --- a/src/components/Tags/Tags.tsx +++ b/src/components/Tags/Tags.tsx @@ -1,6 +1,7 @@ import { addTopicsToQuery } from '@/utils/search.utils' import { Tag } from '@acid-info/lsd-react' import styled from '@emotion/styled' +import Link from 'next/link' import { useRouter } from 'next/router' const Tags = ({ tags }: { tags: string[] }) => { @@ -8,40 +9,30 @@ const Tags = ({ tags }: { tags: string[] }) => { const { query } = router const { topics } = query - const onTagClick = (e: React.MouseEvent, tag: string) => { - e.preventDefault() - router.push( - { - pathname: '/search', - query: { - ...addTopicsToQuery([tag]), - }, - }, - undefined, - { shallow: true }, - ) - } - return tags.length > 0 ? ( - + {tags.map((tag, idx) => ( - onTagClick(e, tag)} - size="small" - disabled={false} - variant={topics?.includes(tag) ? 'filled' : 'outlined'} - key={`tag-${idx}`} - > - {tag} - + + + {tag} + + ))} - + ) : null } -const TagContainer = styled.div` +const TagsContainer = styled.div` display: flex; gap: 8px; + + a { + text-decoration: none; + } ` export default Tags