@@ -19,13 +19,27 @@ import ExceptLayout from '@components/except/exceptLayout/ExceptLayout';
1919import { getCookie } from 'cookies-next' ;
2020
2121const ResultPage = ( ) => {
22- const cardRef = useRef < HTMLDivElement > ( null ) ;
22+ const cardRef = useRef < HTMLButtonElement > ( null ) ;
2323 const router = useRouter ( ) ;
2424 const queryClient = useQueryClient ( ) ;
2525 const userNickname = getCookie ( 'userNickname' ) ;
2626
2727 const resultData = queryClient . getQueryData < TestResponse > ( [ 'test-result' ] ) ;
2828
29+ const handleDownload = useCallback ( async ( ) => {
30+ if ( ! cardRef . current || ! resultData ) return ;
31+
32+ try {
33+ const dataUrl = await toPng ( cardRef . current , { cacheBust : true } ) ;
34+ const link = document . createElement ( 'a' ) ;
35+ link . download = `${ resultData . code } .png` ;
36+ link . href = dataUrl ;
37+ link . click ( ) ;
38+ } catch ( error ) {
39+ console . error ( error ) ;
40+ }
41+ } , [ resultData ] ) ;
42+
2943 if ( ! resultData ) {
3044 return < ExceptLayout type = "testError" /> ;
3145 }
@@ -44,19 +58,6 @@ https://www.gototemplestay.com/test`,
4458 }
4559 } ;
4660
47- const handleDownload = useCallback ( async ( ) => {
48- if ( ! cardRef . current ) return ;
49- try {
50- const dataUrl = await toPng ( cardRef . current , { cacheBust : true } ) ;
51- const link = document . createElement ( 'a' ) ;
52- link . download = `${ resultData . code } .png` ;
53- link . href = dataUrl ;
54- link . click ( ) ;
55- } catch ( error ) {
56- console . error ( error ) ;
57- }
58- } , [ resultData . code ] ) ;
59-
6061 return (
6162 < div className = { styles . page } >
6263 < TestHeader onCloseClick = { ( ) => router . push ( '/' ) } />
@@ -65,9 +66,10 @@ https://www.gototemplestay.com/test`,
6566 < h3 className = { styles . subtitle } > { resultData . tagline } </ h3 >
6667
6768 < >
68- < div ref = { cardRef } onClick = { handleDownload } style = { { cursor : 'pointer' } } >
69+ < button ref = { cardRef } onClick = { handleDownload } >
6970 < ResultCard color = "GREEN" type = { resultData . code } />
70- </ div >
71+ </ button >
72+
7173 < span className = { styles . saveText } > 이미지를 꾹 눌러서 저장해보세요!</ span >
7274 </ >
7375
@@ -82,6 +84,7 @@ https://www.gototemplestay.com/test`,
8284 </ section >
8385
8486 < h2 className = { styles . mateTitle } > 나의 템플메이트는?</ h2 >
87+
8588 < section className = { styles . mateSection } >
8689 < div className = { styles . bestMate } >
8790 < Image src = { bestMate . image } alt = { `${ bestMate . name } 이미지` } width = { 144 } height = { 144 } />
0 commit comments