Skip to content

Commit

Permalink
feat: set default image if none
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed Sep 28, 2024
1 parent bac436a commit 96b8c33
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions public/no-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions src/components/LoadingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use client';

import styled from '@emotion/styled';
import { useState, useEffect } from 'react';
import { useEffect, useState } from 'react';

interface Loading {
$isLoading: boolean;
}

interface NoImage {
$isNoImage: boolean;
}

export function LoadingCard({
title,
imageUrl,
Expand Down Expand Up @@ -41,6 +45,7 @@ export function LoadingCard({
/>
<styles.contents
$isLoading={imageLoading}
$isNoImage={imageUrl === '/no-image.svg'}
src={imageUrl}
alt='card-contents'
/>
Expand All @@ -58,6 +63,7 @@ const styles = {
align-items: center;
gap: 0.7rem;
`,

card: styled.div<Loading>`
width: 6.875rem;
height: 7.6875rem;
Expand Down Expand Up @@ -87,17 +93,17 @@ const styles = {
}
`,

contents: styled.img<Loading>`
contents: styled.img<Loading & NoImage>`
object-fit: cover;
width: 100%;
height: 100%;
display: ${(props) => (props.$isLoading ? 'none' : 'block')};
scale: ${(props) => (props.$isNoImage ? 0.5 : 1)};
`,

checkIcon: styled.img`
width: 1.25rem;
height: 1.25rem;
object-fit: content;
position: absolute;
top: 0.5rem;
right: 0.3rem;
Expand Down
13 changes: 11 additions & 2 deletions src/components/travel/DetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type { TripItem } from '@/features/trip';

type Times = '오전' | '오후' | '저녁' | '밤' | '기본';

interface NoImage {
$isNoImage: boolean;
}

interface Location {
item: TripItem;
selected?: boolean;
Expand Down Expand Up @@ -111,7 +115,11 @@ export function DetailCard({
<styles.addr>
{tourSpot?.data.addr1} {tourSpot?.data.addr2}
</styles.addr>
<styles.placeImg src={tourSpot?.data.firstImage} alt='place-image' />
<styles.placeImg
$isNoImage={tourSpot?.data.firstImage === '/no-image.svg'}
src={tourSpot?.data.firstImage}
alt='place-image'
/>
</styles.placeCon>
<styles.timeCardCon>
<TimeCard
Expand Down Expand Up @@ -206,11 +214,12 @@ const styles = {
gap: 1rem;
`,

placeImg: styled.img`
placeImg: styled.img<NoImage>`
width: 100%;
height: 16rem;
border-radius: 8px;
margin-top: 0.8rem;
scale: ${(props) => (props.$isNoImage ? 0.5 : 1)};
`,

xIcon: styled.img`
Expand Down
12 changes: 10 additions & 2 deletions src/features/tour-spot/tour-spot.api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios';

import {
type GetTourSpotsDTO,
type GetTourSpotContentDTO,
type GetTourSpotsDTO,
} from './tour-spot.dto';

export const getTourSpots = (keyword: string, sigunguCode: string) =>
Expand All @@ -19,4 +19,12 @@ export const getTourSpotContents = (contentId: string, contentTypeId: string) =>
contentTypeId,
},
})
.then((res) => res.data);
.then((res) => res.data)
.then((res) => ({
...res,
data: {
...res.data,
firstImage:
res.data.firstImage === '' ? '/no-image.svg' : res.data.firstImage,
},
}));
18 changes: 13 additions & 5 deletions src/features/trip/trip.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import axios from 'axios';

import type {
GetTripScheduleResponseDTO,
PutTripActivityHistoryDTO,
PutTripActivityRecommendDTO,
PutTripScheduleRequestDTO,
GetTripSchedulesResponseDTO,
PostDayTripRequestDTO,
PostDayTripResponseDTO,
PostTripScheduleDTO,
GetTripSchedulesResponseDTO,
PutTripActivityHistoryDTO,
PutTripActivityRecommendDTO,
PutTripScheduleRequestDTO,
} from './trip.dto';

export const getTripSchedules = () =>
Expand Down Expand Up @@ -48,4 +48,12 @@ export const postTripSchedule = (body: PostTripScheduleDTO) =>
export const postDayTrip = (body: PostDayTripRequestDTO) =>
axios
.post<PostDayTripResponseDTO>(`/p-travel-log/trips/day`, body)
.then((res) => res.data);
.then((res) => res.data)
.then((res) => ({
status: res.status,
data: res.data.map((location) =>
location.imageUrl === ''
? { ...location, imageUrl: '/no-image.svg' }
: location,
),
}));

0 comments on commit 96b8c33

Please sign in to comment.