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

release: 프론트엔드 v1.0.2 #696

Merged
merged 3 commits into from
Apr 5, 2024
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
2 changes: 1 addition & 1 deletion frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

"stylelint.config": null,
"stylelint.validate": ["css", "scss", "typescript", "typescriptreact"],
"cSpell.words": ["JSESSION", "tanstack", "zustand"]
"cSpell.words": ["JSESSION", "tanstack", "webp", "zustand"]
}
2 changes: 1 addition & 1 deletion frontend/.webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
sideEffects: true,
},
{
test: /\.(jpg|jpeg|gif|png|ico)?$/,
test: /\.(jpg|jpeg|gif|png|ico|webp)?$/,
type: 'asset',
generator: {
filename: 'images/[name][ext]',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare module '*.png';
declare module '*.woff2';
declare module '*.webp';
declare module '*.svg' {
import * as React from 'react';

Expand Down
Binary file added frontend/src/assets/images/no-image.webp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { styled, css } from 'styled-components';
import useOnClickBlock from '~/hooks/useOnClickBlock';
import { BORDER_RADIUS, FONT_SIZE, paintSkeleton } from '~/styles/common';
import { getImgUrl } from '~/utils/image';

Expand All @@ -12,13 +13,14 @@ interface WaterMarkImageProps {

function WaterMarkImage({ waterMark, imageUrl, type, sns }: WaterMarkImageProps) {
const [isImageLoading, setIsImageLoading] = useState<boolean>(true);
const register = useOnClickBlock({
callback: e => {
e.stopPropagation();

const onClickWaterMark = (e: React.MouseEvent) => {
e.stopPropagation();

if (sns === 'INSTAGRAM') window.open(`https://www.instagram.com/${waterMark.substring(1)}`, '_blank');
if (sns === 'YOUTUBE') window.open(`https://www.youtube.com/${waterMark}`, '_blank');
};
if (sns === 'INSTAGRAM') window.open(`https://www.instagram.com/${waterMark.substring(1)}`, '_blank');
if (sns === 'YOUTUBE') window.open(`https://www.youtube.com/${waterMark}`, '_blank');
},
});

return (
<StyledWaterMarkImage type={type} isImageLoading={isImageLoading}>
Expand All @@ -33,7 +35,7 @@ function WaterMarkImage({ waterMark, imageUrl, type, sns }: WaterMarkImageProps)
/>
</picture>
{waterMark && (
<StyledWaterMark onClick={onClickWaterMark} aria-hidden="true">
<StyledWaterMark {...register} aria-hidden="true">
{waterMark}
</StyledWaterMark>
)}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/hooks/useOnClickBlock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react';
import { MouseEvent, useCallback, useState } from 'react';

interface UseOnClickBlockProps {
callback: () => void;
callback: (e?: MouseEvent) => void;
}

const useOnClickBlock = ({ callback }: UseOnClickBlockProps) => {
Expand All @@ -15,9 +15,9 @@ const useOnClickBlock = ({ callback }: UseOnClickBlockProps) => {
setIsDragging(true);
}, []);

const handleClick = () => {
const handleClick = (e: MouseEvent) => {
if (isDragging) return;
callback();
callback(e);
};

return { onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onClick: handleClick };
Expand Down
1 change: 0 additions & 1 deletion frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
retry: 1,
},
},
});
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/mocks/handler/mainPage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { rest } from 'msw';
import restaurants from '~/mocks/data/restaurants';
import { recommendation } from '~/mocks/data/recommendation';
import { RECOMMENDED_REGION } from '~/constants/recommendedRegion';
import { getRandomNumber } from '~/utils/getRandomNumber';
import { getRandomResponse } from '~/utils/getRandomResponse';

export const newMainPageHandler = [
rest.get('/address', (req, res, ctx) => {
Expand All @@ -18,9 +18,12 @@ export const newMainPageHandler = [
}),

rest.get('/main-page/recommendation', (req, res, ctx) => {
const responses = [res(ctx.status(401)), res(ctx.status(401)), res(ctx.status(200), ctx.json(recommendation))];
return responses[getRandomNumber()];
// return res(ctx.status(400), ctx.json(recommendation));
// return res(ctx.status(200), ctx.json(recommendation));
/** 에러바운더리를 테스트하려면 이 주석을 해제해주세요 */
// return getRandomResponse(
// res(ctx.status(200), ctx.json(recommendation)),
// res(ctx.status(400)),
// );

return res(ctx.status(200), ctx.json(recommendation));
}),
];
6 changes: 3 additions & 3 deletions frontend/src/mocks/handler/mapPages/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { profile } from '../../data/user';

import type { Celeb } from '~/@types/celeb.types';
import type { RestaurantData, RestaurantListData } from '~/@types/api.types';
import { getRandomNumber } from '~/utils/getRandomNumber';
import { getRandomResponse } from '~/utils/getRandomResponse';

export const MainPageSuccessHandler = [
rest.get('/restaurants', (req, res, ctx) => {
Expand Down Expand Up @@ -130,8 +130,8 @@ export const MainPageSuccessHandler = [
const restaurant = restaurants.find(restaurant => restaurant.id === Number(restaurantId));
restaurant.isLiked ? (restaurant['isLiked'] = false) : (restaurant['isLiked'] = true);

// const responses = [res(ctx.status(429)), res(ctx.status(429)), res(ctx.status(200))];
// return responses[getRandomNumber()];
/** 에러핸들링을 테스트하려면 이 주석을 해제해주세요 */
// return getRandomResponse(res(ctx.status(200)), res(ctx.status(429)))

if (JSESSION === undefined) {
return res(ctx.status(401), ctx.json({ message: '만료된 세션입니다.' }));
Expand Down
56 changes: 54 additions & 2 deletions frontend/src/pages/RestaurantDetailPage/ImageViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { useQuery } from '@tanstack/react-query';
import Slider from 'react-slick';
import styled from 'styled-components';
import { RestaurantData } from '~/@types/api.types';
import { getRestaurantDetail } from '~/api/restaurant';
import ImageCarousel from '~/components/@common/ImageCarousel';
import ImageGrid from '~/components/@common/ImageGrid';
import WaterMarkImage from '~/components/@common/WaterMarkImage';
import useMediaQuery from '~/hooks/useMediaQuery';
import Next from '~/assets/icons/arrow/next.svg';
import Prev from '~/assets/icons/arrow/prev.svg';
import { BORDER_RADIUS } from '~/styles/common';
import noImageUrl from '~/assets/images/no-image.webp';

interface ImageViewerProps {
restaurantId: string;
celebId: string;
}

const sliderProps = {
arrows: true,
dots: true,
infinite: true,
speed: 1000,
slidesToShow: 2,
slidesToScroll: 2,
nextArrow: <Next />,
prevArrow: <Prev />,
};

function ImageViewer({ restaurantId, celebId }: ImageViewerProps) {
const { isMobile } = useMediaQuery();

Expand All @@ -23,7 +40,42 @@ function ImageViewer({ restaurantId, celebId }: ImageViewerProps) {

if (isMobile) return <ImageCarousel type="list" images={images} showWaterMark />;

return <ImageGrid images={images.map(({ name: url, author, sns }) => ({ waterMark: author, url, sns }))} />;
if (images.length === 1) {
const { name: url, author, sns } = images[0];

return (
<Slider {...sliderProps}>
<SlideItem>
<WaterMarkImage type="list" imageUrl={url} waterMark={author} sns={sns} />
</SlideItem>
<SlideItem>
<StyledNoImage src={noImageUrl} />
</SlideItem>
</Slider>
);
}

return (
<Slider {...sliderProps}>
{images.map(({ name: url, author, sns }) => (
<SlideItem key={url}>
<WaterMarkImage type="list" imageUrl={url} waterMark={author} sns={sns} />
</SlideItem>
))}
</Slider>
);
}

export default ImageViewer;

const SlideItem = styled.li`
padding: 1.2rem;
`;

const StyledNoImage = styled.img`
width: 100%;

object-fit: cover;

border-radius: ${BORDER_RADIUS.md};
`;
11 changes: 0 additions & 11 deletions frontend/src/pages/RestaurantDetailPage/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ const StyledHeader = styled.div`
flex-direction: column;
gap: 0.8rem 0;

width: calc(100vw - 2.4rem);

padding: 1.2rem 0 2.4rem;

& > div:first-child {
Expand All @@ -85,7 +83,6 @@ const StyledHeader = styled.div`

const StyledImageViewer = styled.div`
${paintSkeleton}
width: calc(100vw - 2.4rem);
height: calc((100vw - 2.4rem) * 0.9);

padding: 2.4rem 0;
Expand All @@ -98,8 +95,6 @@ const StyledDetailInformation = styled.div`
flex-direction: column;
gap: 2.4rem;

width: calc(100vw - 2.4rem);

padding: 4.8rem 0;

& > div {
Expand All @@ -114,15 +109,13 @@ const StyledDetailInformation = styled.div`

& > div > div:first-child {
${paintSkeleton}
width: calc((100vw - 2.4rem) * 0.7);
height: 24px;

border-radius: ${BORDER_RADIUS.xs};
}

& > div > div:last-child {
${paintSkeleton}
width: calc((100vw - 2.4rem) * 0.5);
height: 20px;

border-radius: ${BORDER_RADIUS.xs};
Expand All @@ -135,16 +128,13 @@ const StyledLine = styled.div`
flex-direction: column;
gap: 1.2rem;

width: calc(100vw - 2.4rem);

padding: 4.8rem 0;

border-top: 1px solid var(--gray-2);
border-bottom: 1px solid var(--gray-2);

& > div {
${paintSkeleton}
width: calc((100vw - 2.4rem) * 0.6);
height: 24px;

border-radius: ${BORDER_RADIUS.xs};
Expand All @@ -153,7 +143,6 @@ const StyledLine = styled.div`

const StyledBox = styled.div`
${paintSkeleton}
width: calc(100vw - 2.4rem);
height: 120px;

border-radius: ${BORDER_RADIUS.md};
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/getRandomNumber.ts

This file was deleted.

9 changes: 9 additions & 0 deletions frontend/src/utils/getRandomResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const getRandomResponse = <T>(successResponse: T, failureResponse: T): T => {
const probability = Math.floor(Math.random() * 10) + 1;

if (probability <= 8) {
return failureResponse;
}

return successResponse;
};
Loading