-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: userId localStorage에 저장 * Feat: 선택된 날짜로 날짜 선택 바텀시트 초기화 * Feat: 로그인 api 연동 최종 * Feat: 로그인 api 연동 최최종 * Fix: 통계 userId localStorage로부터 받아옴 * Refactor: loginApi 호출 수정 * Fix: 상세 userId localStorage로부터 받아옴 * Fix: 태그 userId localStorage로부터 받아옴 * Fix: diaryList userId localStorage로부터 받아옴 * Fix: home userId localStoage로부터 받아옴 * Feat: 사용자 이름 서버로부터 받아옴 * Feat: localStorage에 userId가 없을 때 예외 처리 추가 * Refactor: 안쓰는 userId 변수 제거 * Style: console.log 제거
- Loading branch information
1 parent
09ae6d4
commit c3496fe
Showing
22 changed files
with
194 additions
and
161 deletions.
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
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,13 +1,14 @@ | ||
import { HTTP_URL } from '.'; | ||
import { getUserId } from '../utils/user'; | ||
|
||
export const getCalendarData = async (month: string) => { | ||
const res = await fetch(`${HTTP_URL}/chat/chat?memberId=1&month=${month}`); | ||
const res = await fetch(`${HTTP_URL}/chat/chat?memberId=${getUserId()}&month=${month}`); | ||
const data = await res.json(); | ||
return data; | ||
}; | ||
|
||
export const getDiaryStreakDate = async (memberId: number) => { | ||
const res = await fetch(`${HTTP_URL}/diary/streak?memberId=${memberId}`); | ||
export const getDiaryStreakDate = async () => { | ||
const res = await fetch(`${HTTP_URL}/diary/streak?memberId=${getUserId()}`); | ||
const data = await res.json(); | ||
return data; | ||
}; |
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,7 @@ | ||
import { HTTP_URL } from '.'; | ||
|
||
export const login = async (code: string) => { | ||
const res = await fetch(`${HTTP_URL}/kakao/login?code=${code}`); | ||
const data = await res.json(); | ||
return data; | ||
}; |
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
130 changes: 69 additions & 61 deletions
130
src/components/common/BottomSheets/DateSelect/DatePicker.tsx
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,69 +1,77 @@ | ||
import { useState, useRef, useEffect } from "react"; | ||
import { useState, useRef, useEffect } from 'react'; | ||
import styles from './DatePicker.module.scss'; | ||
|
||
interface ScrollPickerProps { | ||
list: (string | number)[]; | ||
onSelectedChange?: (selected: string | number) => void; | ||
list: (string | number)[]; | ||
onSelectedChange?: (selected: string | number) => void; | ||
prevSelected?: number; | ||
} | ||
|
||
const DatePicker = ({ list, onSelectedChange }: ScrollPickerProps) => { | ||
const SCROLL_DEBOUNCE_TIME = 100; // 스크롤 이벤트의 디바운스 시간을 설정합니다 | ||
|
||
const newList = ["", ...list, ""]; | ||
const ref = useRef<HTMLUListElement>(null); | ||
const [selected, setSelected] = useState(1); | ||
const itemRefs = useRef<(HTMLLIElement | null)[]>([]); | ||
const timerRef = useRef<NodeJS.Timeout | null>(null); | ||
const ITEM_HEIGHT = 44; | ||
|
||
const handleScroll = () => { | ||
if (ref.current) { | ||
// 스크롤 이벤트가 발생할 때마다 이전에 설정된 디바운스 타이머를 초기화합니다. | ||
clearTimeout(timerRef.current!); | ||
|
||
// 스크롤 위치가 맨 앞의 빈 문자열을 가리키지 않게합니다. | ||
if (ref.current.scrollTop < ITEM_HEIGHT) { | ||
ref.current.scrollTop = ITEM_HEIGHT; | ||
} | ||
|
||
// 일정시간이 지난 후에 스크롤 위치를 계산 및 이동합니다. | ||
timerRef.current = setTimeout(() => { | ||
const index = Math.floor( | ||
(ref.current!.scrollTop + ITEM_HEIGHT / 2) / ITEM_HEIGHT, | ||
); | ||
|
||
// 맨 앞, 뒤 값일 경우 무시 | ||
if (list[index] !== "") { | ||
setSelected(index); | ||
itemRefs.current[index]?.scrollIntoView({ | ||
behavior: "smooth", | ||
block: "center", | ||
}); | ||
onSelectedChange && onSelectedChange(newList[index]); | ||
} | ||
}, SCROLL_DEBOUNCE_TIME); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (ref.current) { | ||
ref.current.scrollTop = selected * ITEM_HEIGHT; | ||
const DatePicker = ({ | ||
list, | ||
onSelectedChange, | ||
prevSelected, | ||
}: ScrollPickerProps) => { | ||
const SCROLL_DEBOUNCE_TIME = 100; // 스크롤 이벤트의 디바운스 시간을 설정합니다 | ||
|
||
const newList = ['', ...list, '']; | ||
const ref = useRef<HTMLUListElement>(null); | ||
const [selected, setSelected] = useState(1); | ||
const itemRefs = useRef<(HTMLLIElement | null)[]>([]); | ||
const timerRef = useRef<NodeJS.Timeout | null>(null); | ||
const ITEM_HEIGHT = 44; | ||
|
||
const handleScroll = () => { | ||
if (ref.current) { | ||
// 스크롤 이벤트가 발생할 때마다 이전에 설정된 디바운스 타이머를 초기화합니다. | ||
clearTimeout(timerRef.current!); | ||
|
||
// 스크롤 위치가 맨 앞의 빈 문자열을 가리키지 않게합니다. | ||
if (ref.current.scrollTop < ITEM_HEIGHT) { | ||
ref.current.scrollTop = ITEM_HEIGHT; | ||
} | ||
|
||
// 일정시간이 지난 후에 스크롤 위치를 계산 및 이동합니다. | ||
timerRef.current = setTimeout(() => { | ||
const index = Math.floor( | ||
(ref.current!.scrollTop + ITEM_HEIGHT / 2) / ITEM_HEIGHT, | ||
); | ||
|
||
// 맨 앞, 뒤 값일 경우 무시 | ||
if (list[index] !== '') { | ||
setSelected(index); | ||
itemRefs.current[index]?.scrollIntoView({ | ||
behavior: 'smooth', | ||
block: 'center', | ||
}); | ||
onSelectedChange && onSelectedChange(newList[index]); | ||
} | ||
}, []); | ||
}, SCROLL_DEBOUNCE_TIME); | ||
} | ||
}; | ||
|
||
return ( | ||
<ul className={styles.List} ref={ref} onScroll={handleScroll}> | ||
<div className={styles.ListCenter}></div> | ||
{newList.map((item, index) => ( | ||
<li className={`${styles.Date} ${(index === selected) ? styles.Selected : styles.Unselected}`} | ||
key={index} | ||
ref={(el) => (itemRefs.current[index] = el)} | ||
> | ||
{item} | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
useEffect(() => { | ||
if (ref.current && prevSelected) { | ||
ref.current.scrollTop = selected * ITEM_HEIGHT * prevSelected; | ||
} | ||
}, []); | ||
|
||
return ( | ||
<ul className={styles.List} ref={ref} onScroll={handleScroll}> | ||
<div className={styles.ListCenter}></div> | ||
{newList.map((item, index) => ( | ||
<li | ||
className={`${styles.Date} ${ | ||
index === selected ? styles.Selected : styles.Unselected | ||
}`} | ||
key={index} | ||
ref={(el) => (itemRefs.current[index] = el)} | ||
> | ||
{item} | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default DatePicker; | ||
export default DatePicker; |
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
Oops, something went wrong.