refactor: adjust links

This commit is contained in:
jinhojang6 2023-05-15 03:20:21 +09:00 committed by Jinho Jang
parent a14ef84dbd
commit f3e958990e
10 changed files with 104 additions and 135 deletions

View File

@ -21,13 +21,8 @@ export default function ArticleReference({
year: 'numeric', year: 'numeric',
}) })
const handleClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation()
router.push(`${slug}`)
}
return ( return (
<Reference onClick={handleClick} {...props}> <ReferenceLink href={slug} {...props}>
<Typography component="span" variant="body1"> <Typography component="span" variant="body1">
{title} {title}
</Typography> </Typography>
@ -43,11 +38,11 @@ export default function ArticleReference({
{localDate} {localDate}
</Typography> </Typography>
</Info> </Info>
</Reference> </ReferenceLink>
) )
} }
const Reference = styled.div` const ReferenceLink = styled(Link)`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 8px 14px; padding: 8px 14px;

View File

@ -18,13 +18,16 @@ export default function Collapse({
...props ...props
}: Props) { }: Props) {
const [open, setOpen] = useState(true) const [open, setOpen] = useState(true)
const handleClick = () => {
const handleClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation()
setOpen((prev) => !prev) setOpen((prev) => !prev)
onClick && onClick() onClick && onClick()
} }
return ( return (
<div onClick={handleClick} {...props} className={clsx(className)}> <div {...props} className={clsx(className)}>
<Header> <Header onClick={(e) => handleClick(e)}>
<Label color="primary" component="label" variant="label1"> <Label color="primary" component="label" variant="label1">
{label} {label}
</Label> </Label>

View File

@ -1,24 +1,28 @@
import { GoogleDocEnhanced } from '@/lib/unbody/unbody.types'
import { Typography } from '@acid-info/lsd-react' import { Typography } from '@acid-info/lsd-react'
import styled from '@emotion/styled' import styled from '@emotion/styled'
import Link from 'next/link'
import { Authors } from '../Authors'
type Props = { type Props = {
title: string data: any
author: string
} }
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 ( return (
<BlockBodyContainer> <BlockBodyContainer>
<Typography variant="body1" component="div" genericFontFamily="serif"> <Link href={`/article/${data.document[0].slug}#p-${data.order}`}>
{title} <Typography variant="body1" component="div" genericFontFamily="serif">
</Typography> {data.document[0].title}
<Typography </Typography>
variant="body3" </Link>
component="div" <Authors mentions={mentions} email={false} />
genericFontFamily="sans-serif"
>
{author}
</Typography>
</BlockBodyContainer> </BlockBodyContainer>
) )
} }
@ -27,6 +31,10 @@ const BlockBodyContainer = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 8px; gap: 8px;
a {
text-decoration: none;
}
` `
export default ContentBlockBody export default ContentBlockBody

View File

@ -5,7 +5,6 @@ import { SearchResultItem } from '@/types/data.types'
import { UnbodyImageBlock } from '@/lib/unbody/unbody.types' import { UnbodyImageBlock } from '@/lib/unbody/unbody.types'
import { GridItem } from '../Grid/Grid' import { GridItem } from '../Grid/Grid'
import { PostClassType } from '../Post/Post'
import ContentBlockHeader, { BlockType } from './ContentBlock.Header' import ContentBlockHeader, { BlockType } from './ContentBlock.Header'
import ContentBlockBody from './ContentBlock.Body' import ContentBlockBody from './ContentBlock.Body'
import { ResponsiveImage } from '../ResponsiveImage/ResponsiveImage' import { ResponsiveImage } from '../ResponsiveImage/ResponsiveImage'
@ -16,19 +15,16 @@ const ImageBlock = ({ doc }: Props) => {
return ( return (
<CustomGridItem className="w-2"> <CustomGridItem className="w-2">
{/* TODO: order not working for images */} {/* TODO: order not working for images */}
<BlockLink href={`/article/${doc.document[0].slug}#p-${doc.order}`}> <Container>
<Container> <Link href={`/article/${doc.document[0].slug}#p-${doc.order}`}>
<ResponsiveImage data={doc} /> <ResponsiveImage data={doc} />
<ContentBlockHeader </Link>
type={BlockType.IMAGE} <ContentBlockHeader
date={doc?.document[0].modifiedAt} type={BlockType.IMAGE}
/> date={doc?.document[0].modifiedAt}
<ContentBlockBody />
title={doc.document[0].title} <ContentBlockBody data={doc} />
author="Jason Freeman" </Container>
/>
</Container>
</BlockLink>
</CustomGridItem> </CustomGridItem>
) )
} }
@ -39,10 +35,6 @@ const CustomGridItem = styled(GridItem)`
} }
` `
const BlockLink = styled(Link)`
text-decoration: none;
`
const Container = styled.div` const Container = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@ -15,21 +15,16 @@ type Props = Omit<SearchResultItem<UnbodyTextBlock>, 'score'>
const TextBlock = ({ doc }: Props) => { const TextBlock = ({ doc }: Props) => {
return ( return (
<GridItem className="w-4"> <GridItem className="w-4">
<BlockLink href={`/article/${doc.document[0].slug}#p-${doc.order}`}> <Container>
<Container> <ContentBlockHeader
<ContentBlockHeader type={BlockType.TEXT}
type={BlockType.TEXT} date={doc?.document[0].modifiedAt}
date={doc?.document[0].modifiedAt} />
/> <Typography variant="body2" genericFontFamily="sans-serif">
<Typography variant="body2" genericFontFamily="sans-serif"> {doc.text}
{doc.text} </Typography>
</Typography> <ContentBlockBody data={doc} />
<ContentBlockBody </Container>
title={doc.document[0].title}
author="Jason Freeman"
/>
</Container>
</BlockLink>
</GridItem> </GridItem>
) )
} }

View File

@ -11,14 +11,12 @@ const FeaturedPost = ({ post }: Props) => {
return ( return (
<CustomGrid> <CustomGrid>
<GridItem className="w-16"> <GridItem className="w-16">
<PostLink href={`/article/${post.slug}`}> <PostWrapper>
<PostWrapper> <Post
<Post data={post}
data={post} appearance={{ imageProps: { fill: true, height: '480px' } }}
appearance={{ imageProps: { fill: true, height: '480px' } }} />
/> </PostWrapper>
</PostWrapper>
</PostLink>
</GridItem> </GridItem>
</CustomGrid> </CustomGrid>
) )
@ -35,8 +33,4 @@ const PostWrapper = styled.div`
width: 100%; width: 100%;
` `
const PostLink = styled(Link)`
text-decoration: none;
`
export default FeaturedPost export default FeaturedPost

View File

@ -5,6 +5,7 @@ import { SunIcon } from '../Icons/SunIcon'
import { MoonIcon } from '../Icons/MoonIcon' import { MoonIcon } from '../Icons/MoonIcon'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { uiConfigs } from '@/configs/ui.configs' import { uiConfigs } from '@/configs/ui.configs'
import Link from 'next/link'
interface NavbarProps { interface NavbarProps {
isDark: boolean isDark: boolean
@ -12,10 +13,9 @@ interface NavbarProps {
} }
export default function Navbar({ isDark, toggle }: NavbarProps) { export default function Navbar({ isDark, toggle }: NavbarProps) {
const router = useRouter()
return ( return (
<Container> <Container>
<LogosIconContainer onClick={() => router.push('/')}> <LogosIconContainer href={'/'}>
<LogosIcon color="primary" /> <LogosIcon color="primary" />
</LogosIconContainer> </LogosIconContainer>
<Icons> <Icons>
@ -57,7 +57,7 @@ const Container = styled.nav`
} }
` `
const LogosIconContainer = styled.div` const LogosIconContainer = styled(Link)`
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;

View File

@ -17,6 +17,7 @@ import {
ResponsiveImage, ResponsiveImage,
ResponsiveImageProps, ResponsiveImageProps,
} from '../ResponsiveImage/ResponsiveImage' } from '../ResponsiveImage/ResponsiveImage'
import Link from 'next/link'
export enum PostImageRatio { export enum PostImageRatio {
PORTRAIT = 'portrait', PORTRAIT = 'portrait',
@ -95,6 +96,7 @@ export default function Post({
title, title,
description, description,
mentions, mentions,
slug,
tags = [], tags = [],
}, },
...props ...props
@ -103,14 +105,16 @@ export default function Post({
const _title = useMemo( const _title = useMemo(
() => ( () => (
<CustomTypography <PostLink href={`/article/${slug}`}>
variant={size === PostSize.SMALL ? 'h4' : 'h2'} <CustomTypography
genericFontFamily="serif" variant={size === PostSize.SMALL ? 'h4' : 'h2'}
> genericFontFamily="serif"
{title} >
</CustomTypography> {title}
</CustomTypography>
</PostLink>
), ),
[title, size], [title, size, slug],
) )
const _description = useMemo( const _description = useMemo(
@ -126,16 +130,20 @@ export default function Post({
const _thumbnail = useMemo(() => { const _thumbnail = useMemo(() => {
if (!showImage || !coverImage) return null if (!showImage || !coverImage) return null
if (postType === PostType.BODY) { if (postType === PostType.BODY) {
return <ResponsiveImage {...imageProps} data={coverImage} />
} else {
// TBD
// @jinho not sure what this is for?
return ( return (
<ThumbnailContainer aspectRatio={aspectRatio}> <Link href={`/article/${slug}`}>
<Thumbnail fill src={coverImage.url} alt={coverImage.alt} /> <ResponsiveImage {...imageProps} data={coverImage} />
</Link>
)
} else {
return (
<>
<Link href={`/article/${slug}`}>
<ResponsiveImage data={coverImage} alt={coverImage.alt} />
</Link>
{_title} {_title}
{_description} {_description}
</ThumbnailContainer> </>
) )
} }
}, [ }, [
@ -199,21 +207,6 @@ const Container = styled.div`
gap: 16px; 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)` const Thumbnail = styled(Image)`
object-fit: cover; object-fit: cover;
` `
@ -237,3 +230,7 @@ const PodcastAuthor = styled.div`
align-items: center; align-items: center;
gap: 12px; gap: 12px;
` `
const PostLink = styled(Link)`
text-decoration: none;
`

View File

@ -56,11 +56,9 @@ export const PostsList = (props: Props) => {
} }
key={index} key={index}
> >
<PostLink href={`/article/${post.slug}`}> <PostWrapper className={props.loading ? 'loading' : ''}>
<PostWrapper className={props.loading ? 'loading' : ''}> <Post data={post} />
<Post data={post} /> </PostWrapper>
</PostWrapper>
</PostLink>
</GridItem> </GridItem>
)) ))
) : ( ) : (
@ -90,7 +88,3 @@ const PostWrapper = styled.div`
opacity: 0.5; opacity: 0.5;
} }
` `
const PostLink = styled(Link)`
text-decoration: none;
`

View File

@ -1,6 +1,7 @@
import { addTopicsToQuery } from '@/utils/search.utils' import { addTopicsToQuery } from '@/utils/search.utils'
import { Tag } from '@acid-info/lsd-react' import { Tag } from '@acid-info/lsd-react'
import styled from '@emotion/styled' import styled from '@emotion/styled'
import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
const Tags = ({ tags }: { tags: string[] }) => { const Tags = ({ tags }: { tags: string[] }) => {
@ -8,40 +9,30 @@ const Tags = ({ tags }: { tags: string[] }) => {
const { query } = router const { query } = router
const { topics } = query const { topics } = query
const onTagClick = (e: React.MouseEvent<HTMLElement>, tag: string) => {
e.preventDefault()
router.push(
{
pathname: '/search',
query: {
...addTopicsToQuery([tag]),
},
},
undefined,
{ shallow: true },
)
}
return tags.length > 0 ? ( return tags.length > 0 ? (
<TagContainer> <TagsContainer>
{tags.map((tag, idx) => ( {tags.map((tag, idx) => (
<Tag <Link key={`tag-${idx}`} href={`/search?topics=${tag}`}>
onClick={(e) => onTagClick(e, tag)} <Tag
size="small" size="small"
disabled={false} disabled={false}
variant={topics?.includes(tag) ? 'filled' : 'outlined'} variant={topics?.includes(tag) ? 'filled' : 'outlined'}
key={`tag-${idx}`} >
> {tag}
{tag} </Tag>
</Tag> </Link>
))} ))}
</TagContainer> </TagsContainer>
) : null ) : null
} }
const TagContainer = styled.div` const TagsContainer = styled.div`
display: flex; display: flex;
gap: 8px; gap: 8px;
a {
text-decoration: none;
}
` `
export default Tags export default Tags