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

[FE] Refactor/#593 모아보기와 단일조회페이지 분리 및 리팩토링 #607

Merged
merged 17 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fa19478
refactor: isNotTabBoxShow에 따라 스와이퍼 버튼 위치 조정
semnil5202 Oct 18, 2023
4dd35e4
design: banner TabBox 라인 삭제
semnil5202 Oct 18, 2023
16b09a5
refactor: 모아보기 기능 SelectedTopic 페이지에서 분리
semnil5202 Oct 18, 2023
036b1b5
refactor: resizeMap 로직 훅으로 분리 및 재사용
semnil5202 Oct 18, 2023
66ef511
refactor: 네비게이션 하이라이트 기능 훅으로 분리 및 재사용
semnil5202 Oct 18, 2023
8b9f3de
refactor: tag 관련 로직 훅으로 분리 및 재사용
semnil5202 Oct 18, 2023
85bd580
refactor: 토스트 ui 변경
semnil5202 Oct 19, 2023
bc5fa28
refactor: seetogether 페이지 분리
semnil5202 Oct 19, 2023
295569b
fix: 모아보기 페이지에서 모아보기 삭제 시 발생하던 오류 수정
semnil5202 Oct 19, 2023
f9c4bb8
refactor: 불필요한 import 제거
semnil5202 Oct 19, 2023
5c1553e
refactor: 네비게이션 하이라이트 topics에서 무효화 및 로그인 페이지 오류 수정
semnil5202 Oct 19, 2023
183bb11
fix: 회원일때는 url 상태로 토픽 조회 하도록 변경하여 새로고침 오류 수정
semnil5202 Oct 19, 2023
9322c58
fix: 모아보기를 모두 비운 후 핀이 남아있는 오류 수정
semnil5202 Oct 19, 2023
9062508
fix: 모아보기 상태에서 토픽 이미지 수정이 선택한 토픽으로 되지 않는 오류 수정
semnil5202 Oct 19, 2023
8df9e14
chore: swiper 제거 후 npm 배포 버전으로 import
semnil5202 Oct 19, 2023
01c6e88
refactor: search 페이지 서스펜스 제거
semnil5202 Oct 19, 2023
12c0312
Merge branch 'develop-FE' of https://github.com/woowacourse-teams/202…
semnil5202 Oct 19, 2023
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
17 changes: 16 additions & 1 deletion frontend/src/components/AddSeeTogether/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { deleteApi } from '../../apis/deleteApi';
import { getApi } from '../../apis/getApi';
import { postApi } from '../../apis/postApi';
import { SeeTogetherContext } from '../../context/SeeTogetherContext';
import useNavigator from '../../hooks/useNavigator';
import useToast from '../../hooks/useToast';
import { TopicCardProps } from '../../types/Topic';

interface AddSeeTogetherProps {
parentType: 'topicCard' | 'topicInfo';
isInAtlas: boolean;
id: number;
children: React.ReactNode;
Expand All @@ -17,6 +19,7 @@ interface AddSeeTogetherProps {
}

function AddSeeTogether({
parentType,
isInAtlas,
id,
children,
Expand All @@ -26,6 +29,7 @@ function AddSeeTogether({
const { showToast } = useToast();
const { seeTogetherTopics, setSeeTogetherTopics } =
useContext(SeeTogetherContext);
const { routePage } = useNavigator();

const accessToken = localStorage.getItem('userToken');

Expand All @@ -34,7 +38,7 @@ function AddSeeTogether({

try {
if (seeTogetherTopics && seeTogetherTopics.length === 7) {
showToast('warning', '모아보기는 7개까지만 가능합니다.');
showToast('error', '모아보기는 7개까지만 가능합니다.');
return;
}

Expand Down Expand Up @@ -69,11 +73,22 @@ function AddSeeTogether({
onClickAtlas();

showToast('info', '해당 지도를 모아보기에서 제외했습니다.');

if (parentType === 'topicInfo') routePageAfterSuccessToDelete(topics);
} catch {
showToast('error', '로그인 후 사용해주세요.');
}
};

const routePageAfterSuccessToDelete = (topics: TopicCardProps[]) => {
if (topics.length === 0) {
routePage(`/`);
return;
}

routePage(`/see-together/${topics.map((topic) => topic.id).join(',')}`);
};

const onChangeIsInAtlas = (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Banner() {
height={400}
$simpleTab
$tabBoxPosition="bottom"
$isNotTabBoxShow
swipeable
swiper
autoplay
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/components/PinPreview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { KeyboardEvent, useContext, useEffect, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { styled } from 'styled-components';

import { TagContext } from '../../context/TagContext';
Expand All @@ -11,12 +12,13 @@ import Text from '../common/Text';

export interface PinPreviewProps {
idx: number;
pinId: number;
topicId: string;
urlTopicId: string;
pinTitle: string;
pinLocation: string;
pinInformation: string;
setSelectedPinId: React.Dispatch<React.SetStateAction<number | null>>;
pinId: number;
topicId: string;
setIsEditPinDetail: React.Dispatch<React.SetStateAction<boolean>>;
}

Expand All @@ -28,8 +30,10 @@ function PinPreview({
setSelectedPinId,
pinId,
topicId,
urlTopicId,
setIsEditPinDetail,
}: PinPreviewProps) {
const { pathname } = useLocation();
const { routePage } = useNavigator();
const { tags, setTags } = useContext(TagContext);
const [announceText, setAnnounceText] = useState<string>('토픽 핀 선택');
Expand Down Expand Up @@ -63,7 +67,12 @@ function PinPreview({
setSelectedPinId(pinId);
setIsEditPinDetail(false);

routePage(`/topics/${topicId}?pinDetail=${pinId}`);
if (pathname.split('/')[1] === 'topics') {
routePage(`/topics/${urlTopicId}?pinDetail=${pinId}`);
return;
}

routePage(`/see-together/${urlTopicId}?pinDetail=${pinId}`);
};

const onInputKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/PinsOfTopic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PinPreview from '../PinPreview';
import TopicInfo from '../TopicInfo';

interface PinsOfTopicProps {
urlTopicId?: string;
topicId: string;
topicDetail: TopicDetailProps;
setSelectedPinId: React.Dispatch<React.SetStateAction<number | null>>;
Expand All @@ -13,6 +14,7 @@ interface PinsOfTopicProps {
}

function PinsOfTopic({
urlTopicId,
topicId,
topicDetail,
setSelectedPinId,
Expand All @@ -38,13 +40,14 @@ function PinsOfTopic({
{topicDetail.pins.map((pin, idx) => (
<li key={pin.id}>
<PinPreview
urlTopicId={urlTopicId || topicId}
idx={idx}
pinId={Number(pin.id)}
topicId={topicId}
pinTitle={pin.name}
pinLocation={pin.address}
pinInformation={pin.description}
setSelectedPinId={setSelectedPinId}
pinId={Number(pin.id)}
topicId={topicId}
setIsEditPinDetail={setIsEditPinDetail}
/>
</li>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/TopicCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function TopicCard({
{cardType === 'default' && getTopicsFromServer && (
<ButtonWrapper>
<AddSeeTogether
parentType="topicCard"
isInAtlas={isInAtlas}
onClickAtlas={onClickIsInAtlas}
id={id}
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/components/TopicInfo/UpdatedTopicInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import useDelete from '../../apiHooks/useDelete';
import useGet from '../../apiHooks/useGet';
import usePost from '../../apiHooks/usePost';
import usePut from '../../apiHooks/usePut';
import { putApi } from '../../apis/putApi';
import { DEFAULT_TOPIC_IMAGE } from '../../constants';
import useCompressImage from '../../hooks/useCompressImage';
import useFormValues from '../../hooks/useFormValues';
import useToast from '../../hooks/useToast';
import { TopicAuthorInfo } from '../../types/Topic';
import Button from '../common/Button';
import Flex from '../common/Flex';
import Image from '../common/Image';
import Space from '../common/Space';
import InputContainer from '../InputContainer';
import Text from '../common/Text';
import useCompressImage from '../../hooks/useCompressImage';
import Image from '../common/Image';
import { DEFAULT_TOPIC_IMAGE } from '../../constants';
import { putApi } from '../../apis/putApi';
import InputContainer from '../InputContainer';

interface UpdatedTopicInfoProp {
id: number;
Expand Down Expand Up @@ -85,7 +85,7 @@ function UpdatedTopicInfo({
// await updateTopicPermissionMembers();
// }

showToast('info', '지도를 수정하였습니다.');
showToast('info', `${name} 지도를 수정하였습니다.`);
setIsUpdate(false);
setTopicsFromServer();
} catch {}
Expand Down Expand Up @@ -147,10 +147,15 @@ function UpdatedTopicInfo({
const compressedFile = await compressImage(file);
formData.append('image', compressedFile);

await putApi(`/topics/images/${id}`, formData);
try {
await putApi(`/topics/images/${id}`, formData);
} catch {
showToast('error', '사용할 수 없는 이미지입니다.');
}

const updatedImageUrl = URL.createObjectURL(compressedFile);
setChangedImages(updatedImageUrl);
showToast('info', '지도 이미지를 수정하였습니다.');
};

return (
Expand All @@ -166,7 +171,7 @@ function UpdatedTopicInfo({
<TopicImage
height="168px"
width="100%"
src={changedImages ? changedImages : image}
src={changedImages || image}
alt="사진 이미지"
$objectFit="cover"
onError={(e: React.SyntheticEvent<HTMLImageElement, Event>) => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/TopicInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function TopicInfo({
};

const onChangeIsInAtlas = () => {
showToast('warning', '비회원은 홈에서만 모아보기에 담을 수 있습니다.');
showToast('error', '비회원은 홈에서만 모아보기에 담을 수 있습니다.');
return false;
};

Expand Down Expand Up @@ -155,6 +155,7 @@ function TopicInfo({

<ButtonsWrapper>
<AddSeeTogether
parentType="topicInfo"
isInAtlas={isInAtlas}
onClickAtlas={onChangeIsInAtlas}
id={Number(topicId)}
Expand Down
38 changes: 28 additions & 10 deletions frontend/src/components/common/Swiper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,16 @@ function Swiper({

{swiper && (
<>
<SwiperButtonLeftWrapper $tabBoxHeight={$tabBoxHeight}>
<SwiperButtonLeftWrapper
$tabBoxHeight={$tabBoxHeight}
$isNotTabBoxShow={$isNotTabBoxShow}
>
<SwiperLeftBtnSVG onClick={decreasePos} cursor="pointer" />
</SwiperButtonLeftWrapper>
<SwiperButtonRightWrapper $tabBoxHeight={$tabBoxHeight}>
<SwiperButtonRightWrapper
$tabBoxHeight={$tabBoxHeight}
$isNotTabBoxShow={$isNotTabBoxShow}
>
<SwiperRightBtnSVG onClick={increasePos} cursor="pointer" />
</SwiperButtonRightWrapper>
</>
Expand Down Expand Up @@ -332,24 +338,36 @@ const TabBox = styled.button<{
`}
`;

const SwiperButtonLeftWrapper = styled.div<{ $tabBoxHeight: number }>`
const SwiperButtonLeftWrapper = styled.div<{
$tabBoxHeight: number;
$isNotTabBoxShow: boolean;
}>`
position: absolute;
top: ${({ $tabBoxHeight }) => `calc(50% + ${$tabBoxHeight}px / 2)`};
top: ${({ $tabBoxHeight, $isNotTabBoxShow }) =>
$isNotTabBoxShow ? `50%` : `calc(50% + ${$tabBoxHeight}px / 2)`};
left: 1%;
transform: ${({ $tabBoxHeight }) =>
`translateY(calc(-50% - ${$tabBoxHeight}px))`};
transform: ${({ $tabBoxHeight, $isNotTabBoxShow }) =>
$isNotTabBoxShow
? `translateY(-50%)`
: `translateY(calc(-50% - ${$tabBoxHeight}px))`};

@media (max-width: 744px) {
display: none;
}
`;

const SwiperButtonRightWrapper = styled.div<{ $tabBoxHeight: number }>`
const SwiperButtonRightWrapper = styled.div<{
$tabBoxHeight: number;
$isNotTabBoxShow: boolean;
}>`
position: absolute;
top: ${({ $tabBoxHeight }) => `calc(50% + ${$tabBoxHeight}px / 2)`};
top: ${({ $tabBoxHeight, $isNotTabBoxShow }) =>
$isNotTabBoxShow ? `50%` : `calc(50% + ${$tabBoxHeight}px / 2)`};
right: 1%;
transform: ${({ $tabBoxHeight }) =>
`translateY(calc(-50% - ${$tabBoxHeight}px))`};
transform: ${({ $tabBoxHeight, $isNotTabBoxShow }) =>
$isNotTabBoxShow
? `translateY(-50%)`
: `translateY(calc(-50% - ${$tabBoxHeight}px))`};

@media (max-width: 744px) {
display: none;
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/context/MarkerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useLocation, useParams } from 'react-router-dom';

import { pinColors, pinImageMap } from '../constants/pinImage';
import useNavigator from '../hooks/useNavigator';
Expand Down Expand Up @@ -41,6 +41,7 @@ function MarkerProvider({ children }: Props): JSX.Element {
const { coordinates, clickedCoordinate } = useContext(CoordinatesContext);
const { topicId } = useParams<{ topicId: string }>();
const { routePage } = useNavigator();
const { pathname } = useLocation();

const createMarker = (
coordinate: Coordinate,
Expand Down Expand Up @@ -87,7 +88,12 @@ function MarkerProvider({ children }: Props): JSX.Element {

newMarkers.forEach((marker: Marker) => {
marker.on('click', () => {
routePage(`/topics/${topicId}?pinDetail=${marker.id}`);
if (pathname.split('/')[1] === 'topics') {
routePage(`/topics/${topicId}?pinDetail=${marker.id}`);
return;
}

routePage(`/see-together/${topicId}?pinDetail=${marker.id}`);
});
});
setMarkers(newMarkers);
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/context/SeeTogetherContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
useState,
} from 'react';

import { TopicCardProps } from '../types/Topic';

interface SeeTogetherContextProps {
seeTogetherTopics: number[] | null;
setSeeTogetherTopics: Dispatch<SetStateAction<number[] | []>>;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useNavigator.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

분리 확인요 👍

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const useNavigator = () => {
home: () => routePage('/'),
seeTogether: () =>
routePage(
`/topics/${
`/see-together/${
seeTogetherTopics?.length === 0 ? -1 : seeTogetherTopics?.join(',')
}`,
),
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/hooks/useResizeMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from 'react';

import useMapStore from '../store/mapInstance';

const getAvailableWidth = (sidebarWidth: number = 372) =>
window.innerWidth - sidebarWidth;

const getAvailableHeight = () => window.innerHeight;

const useResizeMap = () => {
const { mapInstance } = useMapStore((state) => state);

const resizeMap = () => {
if (!mapInstance) return;

mapInstance.resize(getAvailableWidth(372), getAvailableHeight());
};

useEffect(() => {
if (window.innerWidth > 1180) resizeMap();
}, [getAvailableWidth(372)]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 의존성에 getAvailableWidth가 어떤 의민지 잘 모르겠습니다 😓

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 페이지에서 콘텐츠를 보여줄 수 있는 가로 사이즈를 의미합니다.


return { resizeMap };
};

export default useResizeMap;
Loading
Loading