update responsive featured image for mobile

This commit is contained in:
jinhojang6 2023-05-16 13:59:34 +09:00 committed by Jinho Jang
parent adfb5b14fc
commit 7e203e184d
5 changed files with 33 additions and 6 deletions

View File

@ -1,13 +1,15 @@
import Link from 'next/link'
import { Grid, GridItem } from '../Grid/Grid'
import styled from '@emotion/styled'
import Post, { PostDataProps, PostSize } from '../Post/Post'
import useWindowSize from '@/utils/ui.utils'
type Props = {
post: PostDataProps
}
const FeaturedPost = ({ post }: Props) => {
const { width } = useWindowSize()
return (
<CustomGrid>
<GridItem className="w-16">
@ -18,7 +20,7 @@ const FeaturedPost = ({ post }: Props) => {
size: PostSize.LARGE,
imageProps: {
fill: true,
height: '432px',
height: width > 786 ? '432px' : null,
nextImageProps: post.coverImage
? {
quality: 100,

View File

@ -118,7 +118,7 @@ export default function Post({
</Title>
</TitleLink>
),
[title, size, slug, isFeatured],
[title, size, slug],
)
const _description = useMemo(
@ -132,7 +132,7 @@ export default function Post({
{description}
</Description>
),
[classType, description, isFeatured],
[classType, description, isFeatured, size],
)
const _thumbnail = useMemo(() => {

View File

@ -4,7 +4,7 @@ import { ImageBlockEnhanced, UnbodyImageBlock } from '@/lib/unbody/unbody.types'
import styled from '@emotion/styled'
export type ResponsiveImageProps = {
height?: number | string
height?: number | string | null
nextImageProps?: Partial<ImageProps>
fill?: boolean
}

View File

@ -132,7 +132,7 @@ export default function Searchbar(props: SearchbarProps) {
)
}, 130)
}
}, [active, searchScope])
}, [active, searchScope, query.length])
const showResultsNumber = resultsNumber !== null && active
const renderTagFilters = tags.length > 0 && !isArticlePage

View File

@ -100,3 +100,28 @@ export function useIntersectionObserver(
return headingElementsRef
}
export function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: 0,
height: 0,
})
useEffect(() => {
function handleResize() {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
})
}
window.addEventListener('resize', handleResize)
handleResize()
return () => window.removeEventListener('resize', handleResize)
}, [])
const { width, height } = windowSize
return {
width,
height,
}
}
export default useWindowSize