11'use client' ;
22
3- import { activeCodinationAtom , closetAtom , closetCodinationAtom , panelAtom } from '@/atoms/chatAtoms' ;
4- import { useAtom , useSetAtom } from 'jotai' ;
5- import { Button } from '@/components/ui/button' ;
63import { Plus } from 'lucide-react' ;
74import CodinationCard from '@/components/chat/codination/CodinationCard' ;
85import { useCodination } from '@/hooks/useCodination' ;
9- import { useVirtualFitting } from '@/hooks/useVirtualFitting' ;
10- import { userAtom } from '@/atoms/authAtoms' ;
116
127export default function CodinationPanel ( ) {
13- const setPanel = useSetAtom ( panelAtom ) ;
14- const setActiveCodination = useSetAtom ( activeCodinationAtom ) ;
15- const [ closetCodination , setClosetCodination ] = useAtom ( closetCodinationAtom ) ;
16- const [ activeCodination ] = useAtom ( activeCodinationAtom ) ;
17- const [ user ] = useAtom ( userAtom ) ;
18-
19- // 스토리지 훅 사용
20- const { codinations, updateCodination } = useCodination ( ) ;
21- const { executeVirtualFitting } = useVirtualFitting ( {
22- codinationId : closetCodination ?. id || activeCodination ?. id || '' ,
23- } ) ;
24- // 상의와 하의가 모두 선택되었는지 확인
25- const hasUpperAndLower =
26- closetCodination &&
27- closetCodination . cloths . some ( ( cloth ) => cloth . url . includes ( 'TOP' ) ) &&
28- closetCodination . cloths . some ( ( cloth ) => cloth . url . includes ( 'BOTTOM' ) ) ;
29-
30- const isDisabled = ! closetCodination || closetCodination . cloths . length === 0 || ! hasUpperAndLower ;
31-
32- const handleAddNewCodination = ( ) => {
33- setPanel ( 'closet' ) ;
34- setActiveCodination ( null ) ;
35- setClosetCodination ( null ) ;
36- } ;
37-
38- const handleSubmitFitting = async ( ) => {
39- if ( isDisabled || ! closetCodination ) return ;
40-
41- // 사용자 프로필의 모델 이미지 체크
42- if ( user ?. userId ) {
43- try {
44- const { loadUserProfile } = await import ( '@/lib/indexedDB' ) ;
45- const userProfile = await loadUserProfile ( user . userId ) ;
46- if ( ! userProfile ?. modelImage ) {
47- // 세팅 패널 모달 띄우기
48- setPanel ( 'settings' ) ;
49- return ;
50- }
51- } catch ( error ) {
52- console . error ( '사용자 프로필 로드 실패:' , error ) ;
53- // 세팅 패널 모달 띄우기
54- setPanel ( 'settings' ) ;
55- return ;
56- }
57- }
58-
59- // 가상피팅 실행
60- const success = await executeVirtualFitting ( closetCodination . cloths ) ;
61-
62- if ( success ) {
63- // 즉시 fitting 패널로 이동
64- setPanel ( 'fitting' ) ;
65- setActiveCodination ( closetCodination ) ;
66- setClosetCodination ( null ) ;
67-
68- // 코디네이션 업데이트
69- await updateCodination ( closetCodination ) ;
70- }
71- } ;
8+ const { codinations } = useCodination ( ) ;
729
7310 if ( codinations . length === 0 )
7411 return (
@@ -79,25 +16,7 @@ export default function CodinationPanel() {
7916 </ div >
8017 < h3 className = "text-xl font-semibold mb-3" > 아직 코디가 없습니다</ h3 >
8118 < p className = "mb-6 max-w-md" > AI와 대화하여 가상피팅에 사용할 옷 조합들을 추가해보세요</ p >
82- < Button
83- onClick = { handleAddNewCodination }
84- className = "bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-500 text-white px-6 py-3"
85- >
86- < Plus className = "w-4 h-4 mr-2" />
87- 코디 추가하기
88- </ Button >
8919 </ div >
90- { closetCodination && closetCodination . cloths . length > 0 && (
91- < div className = "p-4 border-t border-slate-200 dark:border-slate-700" >
92- < button
93- className = { `w-full cursor-pointer h-12 btn bg-navy dark:bg-blue-600 text-lg text-white disabled:bg-blue-50 dark:disabled:bg-slate-600` }
94- disabled = { isDisabled }
95- onClick = { handleSubmitFitting }
96- >
97- 가상피팅하기
98- </ button >
99- </ div >
100- ) }
10120 </ div >
10221 ) ;
10322
@@ -106,23 +25,10 @@ export default function CodinationPanel() {
10625 < div className = "flex-1 overflow-y-auto" >
10726 < div className = "flex flex-col gap-4 p-4" >
10827 { codinations . map ( ( codination , key ) => (
109- < CodinationCard codination = { codination } key = { key } > </ CodinationCard >
28+ < CodinationCard codination = { codination } key = { key } / >
11029 ) ) }
11130 </ div >
11231 </ div >
113- { closetCodination && closetCodination . cloths . length > 0 && (
114- < div className = "p-4 border-t border-slate-200 dark:border-slate-700" >
115- < button
116- className = { `w-full cursor-pointer h-12 btn ${
117- closetCodination . fitting_image ? 'bg-green-600 hover:bg-green-700' : 'bg-navy'
118- } text-lg text-white disabled:bg-blue-50`}
119- disabled = { isDisabled }
120- onClick = { handleSubmitFitting }
121- >
122- { closetCodination . fitting_image ? '피팅 결과 보기' : '가상피팅하기' }
123- </ button >
124- </ div >
125- ) }
12632 </ div >
12733 ) ;
12834}
0 commit comments