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

[Feature] - 데모데이 피드백 반영(리버) #444

Merged
merged 20 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2c7830b
feat(PlaceDetailCard): 여행기 사진 없을 경우 noImage이 아닌 아무것도 안나오도록 수정
0jenn0 Sep 20, 2024
b74deda
test(PlaceDetailCard): 이미지 없는 경우 테스트의 args 수정
0jenn0 Sep 20, 2024
7139021
feat(getDaysAndNights): 여행일자 텍스트 생성 util 함수 구현
0jenn0 Sep 22, 2024
45fbdb4
refactor(TravelogueDetailPage,TravelPlanDetailPage): 여행 일자 계산 util 함수 사용
0jenn0 Sep 22, 2024
767d056
feat(useInitialTripTitle): 여행기,여행계획 제목 초기값 생성 커스텀 훅 구현
0jenn0 Sep 22, 2024
d6eaf39
feat(TravelogueRegisterPage,useTravelPlanForm): 여행기,여행계획 변환시 제목 defau…
0jenn0 Sep 22, 2024
39d8f45
feat(usePreviousPage): 뒤로가기를 관리하는 훅 구현
0jenn0 Sep 22, 2024
cdda624
chore(useInitialTripTitle): Trip을 Travel로 수정
0jenn0 Sep 24, 2024
62d5aa7
feat(TravelogueRegisterPage): 제목 input에 placeholder 추가
0jenn0 Sep 24, 2024
62be1b9
fix(useInitialTravelTitle): 전환시에만 default title을 반환하도록 수정
0jenn0 Sep 24, 2024
a73e181
fix(interceptor): 리다이렉트 중이 아닐 때 alert,리다리렉트하도록 수정
0jenn0 Sep 25, 2024
58ac69d
feat(queryKey): search 쿼리키에 searchType 추가
0jenn0 Sep 25, 2024
6fafcd6
feat(useInfiniteSearchTravelogue): 여행기 검색 param에 searchType 추가
0jenn0 Sep 25, 2024
49e292d
style(Tab): 텍스트 세로 가운데 정렬 및 theme 사용 리팩토링
0jenn0 Sep 25, 2024
0010fd3
refactor(TravelogueList): 검색 결과 부분을 컴포넌트로 분리
0jenn0 Sep 25, 2024
c666cab
feat(SearchPage): 검색 타입 Tab 추가
0jenn0 Sep 25, 2024
eb6278c
feat(getInitialTravelTitle): 제목 초기값에서 사용자 닉네임 삭제
0jenn0 Sep 25, 2024
ef79495
refactor(usePreviousPage): type에서 interface로 수정
0jenn0 Sep 25, 2024
55dbc7f
refactor(usePreviousPage): 필요없는 state 삭제 및 그 전 페이지만 저장하도록 수정
0jenn0 Sep 25, 2024
59c9621
Merge branch 'develop/fe' into feature/fe/#422
0jenn0 Sep 26, 2024
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
8 changes: 3 additions & 5 deletions frontend/src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLocation, useNavigate } from "react-router-dom";

import usePreviousPage from "@hooks/usePreviousPage";
import useUser from "@hooks/useUser";

import { ROUTE_PATHS_MAP } from "@constants/route";
Expand Down Expand Up @@ -44,6 +45,7 @@ const Header = ({
};

const handleClickMyPage = () => navigate(ROUTE_PATHS_MAP.my);
const goBack = usePreviousPage();

return (
<Drawer>
Expand All @@ -52,11 +54,7 @@ const Header = ({
<IconButton
color={isLogoUsed ? theme.colors.primary : PRIMITIVE_COLORS.black}
iconType={isLogoUsed ? "korean-logo" : "back-icon"}
onClick={
isLogoUsed
? () => navigate(ROUTE_PATHS_MAP.root)
: () => navigate(ROUTE_PATHS_MAP.back)
}
onClick={isLogoUsed ? () => navigate(ROUTE_PATHS_MAP.root) : () => goBack()}
Copy link
Contributor

Choose a reason for hiding this comment

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

이전 페이지가 마이페이지고 현재 페이지가 로그인 페이지라면 goBack을 통해 뒤로가기 버튼을 눌러도 마이 페이지로 가는 것이 아닌 루트 페이지로 이동하는 방식이군여 좋습니다 ! !

/>
</S.LeftWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ROUTE_PATHS_MAP } from "@constants/route";

import { extractLastPath } from "@utils/extractId";
import getDateRange from "@utils/getDateRange";
import getDaysAndNights from "@utils/getDaysAndNights";
import { isUUID } from "@utils/uuid";

import theme from "@styles/theme";
Expand All @@ -36,10 +37,7 @@ const TravelPlanDetailPage = () => {

const navigate = useNavigate();

const daysAndNights =
data?.days.length && data?.days.length > 1
? `${data?.days.length - 1}박 ${data?.days.length}일`
: "당일치기";
const daysAndNights = getDaysAndNights(data?.days);

Choose a reason for hiding this comment

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

util로 분리한 거 좋네요


const { mutate: mutateDeleteTravelPlan, isPending: isDeletingPending } = useDeleteTravelPlan();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ERROR_MESSAGE_MAP } from "@constants/errorMessage";
import { ROUTE_PATHS_MAP } from "@constants/route";

import { extractID } from "@utils/extractId";
import getDaysAndNights from "@utils/getDaysAndNights";

import theme from "@styles/theme";
import { SEMANTIC_COLORS } from "@styles/tokens";
Expand All @@ -42,10 +43,7 @@ const TravelogueDetailPage = () => {

const navigate = useNavigate();

const daysAndNights =
data?.days.length && data?.days.length > 1
? `${data?.days.length - 1}박 ${data?.days.length}일`
: "당일치기";
const daysAndNights = getDaysAndNights(data?.days);
Copy link
Contributor

Choose a reason for hiding this comment

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

반복되는 로직 분리해주셔서 감사합니다 :)


const { onTransformTravelDetail } = useTravelTransformDetailContext();
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const WithNoImage: Story = {
args: {
index: 1,
title: "제주도 3박 4일 여행기",
imageUrls: [""],
imageUrls: [],
description: "여행지 설명",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ const PlaceDetailCard: React.FC<PlaceDetailCardProps> = ({

const renderImage = () => {
if (imageUrls.length === 0) {
return (
<S.ImageWrapper>
<FallbackImage />
</S.ImageWrapper>
);
return null;
}

if (imageUrls.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import { useTravelogueDays } from "@hooks/pages/useTravelogueDays";
import { useDragScroll } from "@hooks/useDragScroll";
import useInitialTripTitle from "@hooks/useInitialTripTitle";
import useLeadingDebounce from "@hooks/useLeadingDebounce";
import useTagSelection from "@hooks/useTagSelection";
import useUser from "@hooks/useUser";
Expand All @@ -38,7 +39,6 @@

const { transformDetail } = useTravelTransformDetailContext();

const [title, setTitle] = useState("");
const [thumbnail, setThumbnail] = useState("");

const handleChangeTitle = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -66,6 +66,10 @@
onDeleteImageUrls,
} = useTravelogueDays(transformDetail?.days ?? []);

const initialTitle = useInitialTripTitle({ days: transformDetail?.days, type: "travelogue" });

const [title, setTitle] = useState(initialTitle);

const thumbnailFileInputRef = useRef<HTMLInputElement>(null);

const handleButtonClick = () => {
Expand Down Expand Up @@ -137,7 +141,7 @@
return () => {
saveTransformDetail(null);
};
}, [user?.accessToken, navigate]);

Check warning on line 144 in frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx

View workflow job for this annotation

GitHub Actions / frontend-ci

React Hook useEffect has a missing dependency: 'saveTransformDetail'. Either include it or remove the dependency array

return (
<>
Expand Down
25 changes: 14 additions & 11 deletions frontend/src/hooks/pages/useTravelPlanForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ import { useState } from "react";
import { TravelTransformPlaces } from "@type/domain/travelTransform";

import { useTravelPlanDays } from "@hooks/pages/useTravelPlanDays";
import useInitialTripTitle from "@hooks/useInitialTripTitle";

import { FORM_VALIDATIONS_MAP } from "@constants/formValidation";

const useTravelPlanForm = (transformDays: TravelTransformPlaces[]) => {
const [title, setTitle] = useState("");

const onChangeTitle = (inputValue: string) => {
const trimmedTitle = inputValue.slice(
FORM_VALIDATIONS_MAP.title.minLength,
FORM_VALIDATIONS_MAP.title.maxLength,
);

setTitle(trimmedTitle);
};

const [startDate, setStartDate] = useState<Date | null>(null);

const onSelectCalendar = (date: Date, handleCloseCalendar: () => void) => {
Expand All @@ -36,6 +26,19 @@ const useTravelPlanForm = (transformDays: TravelTransformPlaces[]) => {
onChangeContent,
} = useTravelPlanDays(transformDays);

const initialTitle = useInitialTripTitle({ days: travelPlanDays, type: "travelPlan" });

const [title, setTitle] = useState(initialTitle);

const onChangeTitle = (inputValue: string) => {
const trimmedTitle = inputValue.slice(
FORM_VALIDATIONS_MAP.title.minLength,
FORM_VALIDATIONS_MAP.title.maxLength,
);

setTitle(trimmedTitle);
};

return {
state: {
title,
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/hooks/useInitialTripTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useMemo } from "react";

import type { TravelTransformPlaces } from "@type/domain/travelTransform";

import { useUserProfile } from "@queries/useUserProfile";

import getDaysAndNights from "@utils/getDaysAndNights";

type TripRecordType = "travelogue" | "travelPlan";

type useInitialTripTitleProps = {
days: TravelTransformPlaces[] | undefined;
type: TripRecordType;
};

const useInitialTripTitle = ({ days, type }: useInitialTripTitleProps) => {

Choose a reason for hiding this comment

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

사소한거지만 travel이라는 용어를 계속 사용해왔어서 그런지 통일하면 좋겠네요

Copy link
Author

Choose a reason for hiding this comment

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

그렇네요~~ 반영했습니다!

const { data, status } = useUserProfile();

return useMemo(() => {
const daysAndNights = getDaysAndNights(days);

const userPrefix = status === "success" ? `${data?.nickname}의 ` : "";
const tripType = type === "travelogue" ? "여행기" : "여행 계획";

return `${userPrefix}${daysAndNights} ${tripType}`;
}, [days, data, status, type]);
};

export default useInitialTripTitle;
38 changes: 38 additions & 0 deletions frontend/src/hooks/usePreviousPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";

import { ROUTE_PATHS_MAP } from "@constants/route";

type PreviousPages = {
Copy link
Contributor

Choose a reason for hiding this comment

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

image

type 말고 interface를 사용해볼 수 있을거 같아요 :)

Copy link
Author

Choose a reason for hiding this comment

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

수정했습니다!

[key: string]: string;
};

const usePreviousPage = () => {
Copy link
Contributor

@jinyoung234 jinyoung234 Sep 24, 2024

Choose a reason for hiding this comment

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

image

궁금증 1 - previousPages의 경우 마이페이지, 로그인 페이지를 제외하곤 객체 내 하나의 프로퍼티만 들어오는데 혹시 이유를 알 수 있을까요 .. ? 혼자 찾아볼 땐 이유를 알기가 어렵네요 ㅜㅜㅜ...

궁금증 2 - useState로 관리하는 이유가 있을까요 ?! 위 사진 case에서 새로고침을 하니까 previousPages 데이터 내 프로퍼티가 하나만 존재하는 걸로 바뀌어서여(요건 그냥 localStorage에 데이터를 저장하고 useState에서 데이터를 받아오는 형태로 하면 어떨까 싶기도 합니다)

궁금증 3 - 의존성 배열에 pathname만 변경해도 충분하지 않을까 싶긴 한데 location 객체를 의존성 배열에 추가한 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

지니랑 얘기한대로 state 불필요, 그전 페이지만 저장만으로 충분하다 생각해서 그렇게 수정했습니다!

const navigate = useNavigate();
const location = useLocation();
const [previousPages, setPreviousPages] = useState<PreviousPages>({});

useEffect(() => {
setPreviousPages((prev) => ({
...prev,
[location.pathname]: document.referrer,
}));
}, [location]);

const goBack = () => {
const previousPage = previousPages[location.pathname];
const currentPage = location.pathname;
const isPreviousPageMy = previousPage?.includes(ROUTE_PATHS_MAP.my);
const isCurrentPageLogin = currentPage.includes(ROUTE_PATHS_MAP.login);

if (isPreviousPageMy && isCurrentPageLogin) {
navigate(ROUTE_PATHS_MAP.root);
} else {
navigate(ROUTE_PATHS_MAP.back);
}
};
Comment on lines +12 to +20

Choose a reason for hiding this comment

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

개인적으로 얘를 좀 더 재사용성 높게 수정하면 좋을 거 같습니다 우리 계속 고민하던 부분이 이전 페이지가 등록 페이지인 경우 두 번 뒤로 가고 이런 고민들을 했어서 그런 것도 사용할 수 있는 방향이면 좋겠네요

Copy link
Author

Choose a reason for hiding this comment

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

그런 부분은 이제 이 훅에 분기처리 추가해나가면되지 않을까용??

Choose a reason for hiding this comment

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

이해했습니다


return goBack;
};

export default usePreviousPage;
6 changes: 6 additions & 0 deletions frontend/src/utils/getDaysAndNights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { TravelTransformPlaces } from "@type/domain/travelTransform";

const getDaysAndNights = (days: TravelTransformPlaces[] | undefined) =>
days?.length && days?.length > 1 ? `${days.length - 1}박 ${days.length}일` : "당일치기";

export default getDaysAndNights;
Loading