-
Notifications
You must be signed in to change notification settings - Fork 5
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] - 여행기 & 여행 계획 등록/수정 페이지 리팩터링 #520
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ab97029
refactor(useTravelogueDays): 여행기 등록 페이지 default export로 변경
jinyoung234 49a501a
refactor(useTravelogueForm): 여행기 form에 대한 책임을 useTravelogueForm으로 분리
jinyoung234 1e6eec1
refactor(useMultiImageUpload): 다중 이미지 업로드 로직에 대한 리팩터링
jinyoung234 3ddfe8d
refactor(TravelogueRegisterPage): 페이지 리팩터링
jinyoung234 d23a62d
refactor(ThumbnailUpload): fileRef와 click 핸들러를 내부에서 관리하는 것으로 변경
jinyoung234 a5a7ec8
refactor: 인증된 사용자가 아닌 경우 redirect 시키는 hook 분리
jinyoung234 7745cd3
refactor: useToggle 훅을 통해 open, close 하도록 변경
jinyoung234 5d0a22f
refactor(travelTransform): TravelTransformPlace의 타입을 유틸리티 타입으로 개선
jinyoung234 cf84ef5
refactor(TravelogueRegisterPage): useTravelogueForm 형태 변경
jinyoung234 ee784f0
refactor(TravelogueEditPage): 여행기 수정 페이지 리팩터링
jinyoung234 c8ebee0
refactor(TravelPlanRegisterPage): 여행 계획 등록에 대한 책임 분리
jinyoung234 9045bc3
refactor(TravelPlanRegisterPage): 여행 계획 수정 페이지 리팩터링
jinyoung234 b44f89f
refactor: useTravelPlanFormState, useTravelogueFormState 폴더구조 변경
jinyoung234 52dca65
fix(useTravelogueFormState): ci 문제 해결
jinyoung234 6b28065
refactor: on prefix를 handle prefix로 변경
jinyoung234 5defe1c
refactor(ThumbnailUpload): 불필요한 제네릭 제거
jinyoung234 02fc25f
refactor(travelTransform): import 시 type 추가
jinyoung234 6e85fd3
refactor(ThumbnailUpload): 불필요한 props 개행 제거
jinyoung234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { InputHTMLAttributes, useState } from "react"; | ||
import { InputHTMLAttributes, useRef, useState } from "react"; | ||
|
||
import { PRIMITIVE_COLORS } from "@styles/tokens"; | ||
|
||
|
@@ -11,22 +11,25 @@ import * as S from "./ThumbnailUpload.styled"; | |
interface ThumbnailUploadProps extends InputHTMLAttributes<HTMLInputElement> { | ||
id?: string; | ||
previewUrls: string[]; | ||
fileInputRef: React.RefObject<HTMLInputElement>; | ||
|
||
onChangeImage: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
onClickButton: () => void; | ||
|
||
onDeleteButton?: () => void; | ||
} | ||
|
||
const ThumbnailUpload = ({ | ||
id, | ||
previewUrls, | ||
fileInputRef, | ||
onChangeImage, | ||
onClickButton, | ||
onDeleteButton, | ||
}: ThumbnailUploadProps) => { | ||
const [isShowEditButton, setIsShowEditButton] = useState<boolean>(false); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
const thumbnailFileInputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handleButtonClick = () => { | ||
thumbnailFileInputRef.current?.click(); | ||
}; | ||
|
||
const handleMouseOver = () => { | ||
if (!isLoading) setIsShowEditButton(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이런 리팩토링은 어떨까요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 제가 작업했던 부분은 아니라 리팩터링 사항에 반영해놓을게요 :) |
||
|
@@ -56,7 +59,7 @@ const ThumbnailUpload = ({ | |
const HiddenInput = ( | ||
<S.ThumbnailUploadHiddenInput | ||
id={id} | ||
ref={fileInputRef} | ||
ref={thumbnailFileInputRef} | ||
type="file" | ||
accept="image/*" | ||
onChange={handleChangeImage} | ||
|
@@ -79,7 +82,11 @@ const ThumbnailUpload = ({ | |
|
||
{!image ? ( | ||
<> | ||
<S.ThumbnailUploadButton type="button" onClick={onClickButton} aria-label="이미지 업로드"> | ||
<S.ThumbnailUploadButton | ||
type="button" | ||
onClick={handleButtonClick} | ||
aria-label="이미지 업로드" | ||
> | ||
<PictureIcon /> | ||
<p>썸네일 업로드</p> | ||
</S.ThumbnailUploadButton> | ||
|
@@ -91,7 +98,7 @@ const ThumbnailUpload = ({ | |
onMouseLeave={handleMouseLeave} | ||
> | ||
{isShowEditButton && ( | ||
<S.ThumbnailUploadEditButton onClick={onClickButton}> | ||
<S.ThumbnailUploadEditButton onClick={handleButtonClick}> | ||
썸네일 수정하기 | ||
</S.ThumbnailUploadEditButton> | ||
)} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
frontend/src/components/pages/travelPlanEdit/hooks/useTravelPlanEdit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
|
||
import { TravelPlanPayload } from "@type/domain/travelPlan"; | ||
|
||
import { usePutTravelPlan } from "@queries/usePutTravelPlan"; | ||
|
||
import useLeadingDebounce from "@hooks/useLeadingDebounce"; | ||
|
||
import { DEBOUNCED_TIME } from "@constants/debouncedTime"; | ||
import { ERROR_MESSAGE_MAP } from "@constants/errorMessage"; | ||
import { ROUTE_PATHS_MAP } from "@constants/route"; | ||
|
||
const useTravelPlanEdit = (payload: TravelPlanPayload, handleCloseBottomSheet: () => void) => { | ||
const { | ||
mutate: mutateTravelPlanEdit, | ||
isPaused, | ||
isPending: isPuttingTravelPlanPending, | ||
} = usePutTravelPlan(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const { id = "" } = useParams(); | ||
|
||
const handleEditTravelPlan = () => { | ||
mutateTravelPlanEdit( | ||
{ | ||
travelPlan: payload, | ||
id: Number(id), | ||
}, | ||
{ | ||
onSuccess: () => { | ||
handleCloseBottomSheet(); | ||
navigate(ROUTE_PATHS_MAP.travelPlan(id)); | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
const onEditTravelPlan = useLeadingDebounce(() => { | ||
if (isPaused) alert(ERROR_MESSAGE_MAP.network); | ||
handleEditTravelPlan(); | ||
}, DEBOUNCED_TIME); | ||
|
||
return { onEditTravelPlan, isPuttingTravelPlanPending }; | ||
}; | ||
|
||
export default useTravelPlanEdit; |
30 changes: 30 additions & 0 deletions
30
frontend/src/components/pages/travelPlanEdit/hooks/useTravelPlanInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
import { useGetTravelPlan } from "@queries/useGetTravelPlan"; | ||
|
||
import useTravelPlanFormState from "@hooks/pages/useTravelPlanFormState/useTravelPlanFormState"; | ||
|
||
type UseTravelPlanInitialization = Pick< | ||
ReturnType<typeof useTravelPlanFormState>["handler"], | ||
"onChangeTitle" | "onInitializeStartDate" | "onChangeTravelPlanDays" | ||
>; | ||
|
||
export const useTravelPlanInitialization = ({ | ||
onChangeTitle, | ||
onInitializeStartDate, | ||
onChangeTravelPlanDays, | ||
}: UseTravelPlanInitialization) => { | ||
const { id = "" } = useParams(); | ||
|
||
const { data, status, error, isLoading } = useGetTravelPlan(id); | ||
useEffect(() => { | ||
if (data) { | ||
onChangeTitle(data.title); | ||
onInitializeStartDate(data.startDate); | ||
onChangeTravelPlanDays(data.days); | ||
} | ||
}, [data, onChangeTitle, onChangeTravelPlanDays, onInitializeStartDate]); | ||
|
||
return { status, error, isLoading }; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으로 궁금한건데 boolean을 기입하지 않아도 충분히 타입 추론이 될텐데 넣어주는 이유가 있나요? 저는 잘 안 넣는 편인데 단지 지니의 생각이 궁금해서 질문을 남겨봅니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 작업했던 부분이 아니라 boolean이 적혀있는지도 몰랐네요,,,, 빼도 동일하게 동작해서 빼놓을게요!