Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use next/image component for campaign images #1580

Merged
merged 5 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/components/client/campaigns/CampaignCard/CampaignCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react'
import { useTranslation, i18n } from 'next-i18next'
import { CampaignResponse } from 'gql/campaigns'

import { CardMedia } from '@mui/material'
import { Box, CardMedia } from '@mui/material'

import { routes } from 'common/routes'
import { campaignListPictureUrl } from 'common/util/campaignImageUrls'
Expand All @@ -23,6 +23,7 @@ import {
SumNumber,
SumWrapper,
} from '../../index/sections/ActiveCampaignsSection/ActiveCampaignCard/ActiveCampaignCard.styled'
import Image from 'next/image'

type Props = { campaign: CampaignResponse; index: number }

Expand All @@ -47,26 +48,24 @@ export default function ActiveCampaignCard({ campaign, index }: Props) {

return (
<Root data-testid={`campaign-card-${index}`}>
<Link href={routes.campaigns.viewCampaignBySlug(slug)} sx={{ position: 'relative' }}>
<CardMedia
component="img"
height="100%"
image={campaignImagesUrl}
alt={title}
<Link href={routes.campaigns.viewCampaignBySlug(slug)}>
<Box
position={'relative'}
sx={{
maxHeight: theme.spacing(42.5),

[theme.breakpoints.up('lg')]: {
aspectRatio: '2',
height: theme.spacing(22.3),
maxHeight: 'inherit',
},

[theme.breakpoints.up(1430)]: {
height: theme.spacing(27.9),
},
}}
/>
width: '100%',
aspectRatio: 1.5,
maxHeight: theme.spacing(27.9),
}}>
<Image
priority
src={campaignImagesUrl}
alt={title}
fill
sizes="(min-width: 2000px) 312px, (min-width: 1200px) calc(30vw - 38px), (min-width: 900px) calc(40.57vw - 29px), (min-width: 600px) calc(50vw - 28px), calc(100vw - 32px)"
quality={index === 0 ? 100 : 75}
style={{ objectFit: 'cover' }}
/>
</Box>
{campaignState === CampaignState.complete && percentage >= 100 ? (
<SuccessfullCampaignTag />
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useTranslation, i18n } from 'next-i18next'
import { CampaignResponse } from 'gql/campaigns'

import { CardMedia } from '@mui/material'
import { Box, CardMedia } from '@mui/material'

import Link from 'components/common/Link'
import CampaignProgress from 'components/client/campaigns/CampaignProgress'
import theme from 'common/theme'
import { routes } from 'common/routes'
import { campaignListPictureUrl } from 'common/util/campaignImageUrls'
import { moneyPublic } from 'common/util/money'
import Image from 'next/image'

import {
CampaignTitle,
Expand All @@ -34,26 +35,32 @@ export default function ActiveCampaignCard({ campaign, index }: Props) {

return (
<Root data-testid={`completed-campaign-${index}`}>
<Link href={routes.campaigns.viewCampaignBySlug(slug)} sx={{ position: 'relative' }}>
<CardMedia
component="img"
height="100%"
image={campaignImagesUrl}
alt={title}
<Link href={routes.campaigns.viewCampaignBySlug(slug)}>
<Box
position={'relative'}
sx={{
maxHeight: theme.spacing(42.5),

// aspectRatio: 4 / 3,
// [theme.breakpoints.up('lg')]: {
// aspectRatio: 0,
// height: index === 0 ? theme.spacing(71.6) : theme.spacing(27.85),
// },
width: '100%',
aspectRatio: 1.5,
[theme.breakpoints.up('lg')]: {
aspectRatio: '2',
height: theme.spacing(22.3),
maxHeight: 'inherit',
},

[theme.breakpoints.up(1430)]: {
height: theme.spacing(27.9),
maxHeight: index === 0 ? theme.spacing(71.6) : theme.spacing(27.85),
aspectRatio: index === 0 ? 1.24 : 1.55,
},
}}
/>
}}>
<Image
priority
src={campaignImagesUrl}
alt={title}
fill
sizes="(min-width: 2000px) 312px, (min-width: 1200px) calc(30vw - 38px), (min-width: 900px) calc(40.57vw - 29px), (min-width: 600px) calc(50vw - 28px), calc(100vw - 32px)"
quality={index === 0 ? 100 : 75}
style={{ objectFit: 'cover' }}
/>
</Box>
<StyledContent>
<SumWrapper>
<Sum>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
SuccessfullCampiagnText,
} from './CompletedCampaignsSection.styled'

import Image from 'next/image'

export default function CompletedCampaignsSection() {
const { t } = useTranslation('campaigns')
const { data } = useCampaignList()
Expand All @@ -51,10 +53,15 @@ export default function CompletedCampaignsSection() {
<CompletedCampaignLink
onMouseDown={onLinkMouseDown}
href={routes.campaigns.viewCampaignBySlug(campaign.slug)}
sx={{
background: `url(${campaignListPictureUrl(campaign)})`,
}}
/>
sx={{ position: 'relative', aspectRatio: 1, height: (theme) => theme.spacing(37.5) }}>
<Image
fill
alt={campaign.title}
src={campaignListPictureUrl(campaign)}
sizes="(min-width: 2000px) 312px, (min-width: 1200px) calc(30vw - 38px), (min-width: 900px) calc(40.57vw - 29px), (min-width: 600px) calc(50vw - 28px), calc(100vw - 32px)"
style={{ objectFit: 'cover' }}
/>
</CompletedCampaignLink>
<CompletedSumWrapper>
<Sum>
{i18n.language === 'bg'
Expand Down
Loading