-
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
[FE] swipe 기능을 ref를 받아 쓰도록 개선한다 #959
Changes from all commits
25d93b9
cc4cda9
25409dd
97ad282
37ca760
0d49c5d
10e937c
5196255
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,17 +35,17 @@ export const deleteToken = async () => { | |
}; | ||
|
||
export const postReissueAccessToken = async () => { | ||
return await fetch(`${BASE_URL}${ENDPOINT.USER_ACCESS_TOKEN_REISSUE}`, { | ||
method: 'POST', | ||
return await fetcher.post({ | ||
url: `${BASE_URL}${ENDPOINT.USER_ACCESS_TOKEN_REISSUE}`, | ||
credentials: 'include', | ||
headers: { 'Content-Type': 'application/json' }, | ||
// 쿠키전달이기때문에 body가 비어있는 post | ||
}); | ||
}; | ||
|
||
export const postSignUp = async ({ name, email, password }: { name: string; email: string; password: string }) => { | ||
return await fetch(`${BASE_URL}${ENDPOINT.REGISTER}`, { | ||
method: 'POST', | ||
body: JSON.stringify({ name, email, password }), | ||
return await fetcher.post({ | ||
url: `${BASE_URL}${ENDPOINT.REGISTER}`, | ||
body: { name, email, password }, | ||
credentials: 'include', | ||
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. 반영했습니다. |
||
}); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ const DepositAndRent = () => { | |
<FormField.Label label="보증금 / 월세 (만원)" /> | ||
<FormStyled.FieldBox> | ||
<FormField.Input | ||
inputMode="decimal" | ||
width="medium" | ||
onChange={deposit.onChange} | ||
name="deposit" | ||
|
@@ -21,6 +22,7 @@ const DepositAndRent = () => { | |
/> | ||
<FormStyled.FlexLabel label=" / " /> | ||
<FormField.Input | ||
inputMode="decimal" | ||
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. 이런 속성이 있는지는 처음 알았네요 제이드 덕분에 배우고 갑니다!! |
||
width="medium" | ||
placeholder="" | ||
onChange={rent.onChange} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const MaintenanceFee = () => { | |
<FormField.Label label="관리비" htmlFor="maintenanceFee" /> | ||
<FormStyled.FieldBox> | ||
<Input | ||
inputMode="decimal" | ||
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. 👍👍👍 |
||
width="medium" | ||
placeholder="" | ||
onChange={maintenanceFee.onChange} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
import { createContext, ReactNode, useContext, useState } from 'react'; | ||
import { createContext, ReactNode, RefObject, useContext, useRef, useState } from 'react'; | ||
|
||
import { ERROR_MESSAGE } from '@/constants/messages/errorMessage'; | ||
import { DefaultChecklistTabsNames, DRAG_THRESHOLD_PIXEL } from '@/constants/tabs'; | ||
import useMouseDrag from '@/hooks/useMouseDrag'; | ||
|
||
interface ContextProps { | ||
currentTabId: number; | ||
setCurrentTabId: React.Dispatch<React.SetStateAction<number>>; | ||
useDragForTab: () => RefObject<HTMLElement>; | ||
} | ||
|
||
const defaultContext: ContextProps = { | ||
currentTabId: 0, | ||
setCurrentTabId: () => {}, | ||
}; | ||
|
||
const TabContext = createContext<ContextProps>(defaultContext); | ||
const TabContext = createContext<ContextProps | null>(null); | ||
|
||
interface Props { | ||
children: ReactNode; | ||
defaultTab: number; | ||
} | ||
|
||
const remainOp = (a: number, b: number) => (((a % b) + b + 1) % b) - 1; // 나머지연산자. -1부터 시작하므로 +1 -1 | ||
|
||
export const TabProvider = ({ children, defaultTab = 0 }: Props) => { | ||
const [currentTabId, setCurrentTabId] = useState<number>(defaultTab); | ||
|
||
return <TabContext.Provider value={{ currentTabId, setCurrentTabId }}>{children}</TabContext.Provider>; | ||
// 드래그로 탭이동을 위한 훅을 리턴에 제공 | ||
const useDragForTab = (dragThreshold: number = DRAG_THRESHOLD_PIXEL) => { | ||
const ref = useRef<HTMLElement>(null); | ||
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. TabContext에 넣으니까 응집성 있고 좋네요!!👍 |
||
useMouseDrag(ref, (S, E) => { | ||
const TAB_COUNT = DefaultChecklistTabsNames.length; | ||
|
||
setCurrentTabId(tabId => { | ||
const isLeftDrag = E.x - S.x > dragThreshold; | ||
const isRightDrag = S.x - E.x > dragThreshold; | ||
if (isLeftDrag) return remainOp(tabId - 1, TAB_COUNT); | ||
if (isRightDrag) return remainOp(tabId + 1, TAB_COUNT); | ||
return tabId; | ||
}); | ||
}); | ||
|
||
return ref; | ||
}; | ||
|
||
return <TabContext.Provider value={{ currentTabId, setCurrentTabId, useDragForTab }}>{children}</TabContext.Provider>; | ||
}; | ||
|
||
export const useTabContext = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ export const DefaultChecklistTabsNames: Tab[] = [ | |
name: '보안', | ||
}, | ||
]; | ||
|
||
export const DRAG_THRESHOLD_PIXEL = 100; |
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.
fetcher 내부에 이미
credentials: 'include',
이 포함되어 있어서 불필요한 코드인거 같네요~!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.
반영했습니다.