-
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.
- Loading branch information
1 parent
d9f0256
commit 09d88bd
Showing
6 changed files
with
134 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './cheer-bottom-sheet'; | ||
export * from './cheer-item'; | ||
export * from './cheer-progress'; |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
'use client'; | ||
|
||
import { RefetchOptions } from '@tanstack/react-query'; | ||
import { useState } from 'react'; | ||
|
||
import { DetailCheerItemSelected } from '@/features/record-detail'; | ||
import { useCheer } from '@/features/record-detail/apis'; | ||
|
||
import { useBottomSheet } from './use-bottom-sheet'; | ||
|
||
const initialCheerList = [ | ||
{ | ||
emoji: '🔥', | ||
comment: '오늘도 힘내요!', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '🦭', | ||
comment: '물개세요?', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '🏊', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '👏', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '🏊♂️', | ||
comment: '진정한 수영인으로 인정합니다', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '🏊♂️', | ||
comment: '다음에 같이 수영해요', | ||
isSelected: false, | ||
}, | ||
{ | ||
emoji: '😲', | ||
comment: '대단해요!', | ||
isSelected: false, | ||
}, | ||
]; | ||
|
||
type UseCheerBottomSheet = { | ||
memoryId: number; | ||
onRefetch: (options?: RefetchOptions) => Promise<unknown>; | ||
}; | ||
export const useCheerBottomSheet = ({ | ||
memoryId, | ||
onRefetch, | ||
}: UseCheerBottomSheet) => { | ||
const { mutate: mutateCheer } = useCheer(); | ||
const [cheerList, setCheerList] = useState(initialCheerList); | ||
const [selectedCheerItem, setSelectedCheerItem] = | ||
useState<DetailCheerItemSelected>(); | ||
|
||
const { | ||
isOpen: isOpenBottomSheet, | ||
open: openBottomSheet, | ||
close: closeBottomSheet, | ||
} = useBottomSheet(); | ||
|
||
const handleClickCheerItem = (index: number) => { | ||
setCheerList((prev) => | ||
prev.map((item, idx) => | ||
idx === index | ||
? { ...item, isSelected: !item.isSelected } | ||
: { ...item, isSelected: false }, | ||
), | ||
); | ||
}; | ||
|
||
const handleClickSendCheer = () => { | ||
const selectedCheerItem = cheerList.find(({ isSelected }) => isSelected); | ||
if (!selectedCheerItem) return; | ||
|
||
mutateCheer( | ||
{ | ||
emoji: selectedCheerItem.emoji, | ||
comment: selectedCheerItem.comment, | ||
memoryId, | ||
}, | ||
{ | ||
onSuccess: ({ status, code, message }) => { | ||
if (status === 400 || code === 'REACTION_4') { | ||
alert(message); | ||
return; | ||
} | ||
|
||
setSelectedCheerItem(selectedCheerItem); | ||
closeBottomSheet(); | ||
void onRefetch?.(); | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
const handleChangeSelectedItem = (isOpen: boolean) => { | ||
if (isOpen) return; | ||
setSelectedCheerItem(undefined); | ||
}; | ||
|
||
return { | ||
cheerList, | ||
selectedCheerItem, | ||
handleClickCheerItem, | ||
handleClickSendCheer, | ||
handleChangeSelectedItem, | ||
isOpenBottomSheet, | ||
openBottomSheet, | ||
closeBottomSheet, | ||
}; | ||
}; |