@@ -17,6 +17,10 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
17
17
} ) => {
18
18
const templateRef = useRef < HTMLDivElement > ( null ) ;
19
19
const [ openToast , setOpenToast ] = useState ( false ) ;
20
+ const [ toastMessage , setToastMessage ] = useState ( {
21
+ title : '' ,
22
+ description : '' ,
23
+ } ) ;
20
24
21
25
const captureTemplate = async ( ) => {
22
26
if ( ! templateRef . current ) return null ;
@@ -49,8 +53,6 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
49
53
} ;
50
54
51
55
const handleClickShare = async ( ) => {
52
- if ( ! navigator . share ) return ;
53
-
54
56
try {
55
57
const imageUrl = await captureTemplate ( ) ;
56
58
@@ -68,22 +70,31 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
68
70
files : [ file ] ,
69
71
} ;
70
72
71
- if ( navigator . canShare ( shareData ) ) {
72
- await navigator . share ( shareData ) ;
73
- } else {
74
- await navigator . clipboard . writeText ( window . location . href ) ;
75
- setOpenToast ( true ) ;
76
- }
73
+ await navigator . share ( shareData ) ;
77
74
}
78
75
} catch {
79
- await navigator . clipboard . writeText ( window . location . href ) ;
80
- setOpenToast ( true ) ;
76
+ navigator . clipboard
77
+ . writeText ( window . location . href )
78
+ . then ( ( ) => {
79
+ setToastMessage ( {
80
+ title : '링크가 복사되었어요!' ,
81
+ description : '현재 페이지의 URL이 클립보드에 복사되었어요.' ,
82
+ } ) ;
83
+ setOpenToast ( true ) ;
84
+ } )
85
+ . catch ( ( ) => {
86
+ setToastMessage ( {
87
+ title : '공유하기를 지원하지 않는 환경입니다' ,
88
+ description : '다른 브라우저에서 시도해보세요.' ,
89
+ } ) ;
90
+ setOpenToast ( true ) ;
91
+ } ) ;
81
92
}
82
93
} ;
83
94
84
95
return (
85
96
< AppScreen >
86
- < Toast . Provider swipeDirection = "down" >
97
+ < Toast . Provider swipeDirection = "right" duration = { 3000 } >
87
98
< div className = "flex min-h-dvh flex-col py-6" >
88
99
< AppBar progress = { 100 } />
89
100
< div className = "mt-6 flex flex-1 flex-col items-center justify-evenly" >
@@ -110,13 +121,13 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
110
121
onOpenChange = { setOpenToast }
111
122
>
112
123
< Toast . Title className = "mb-1 font-medium text-gray-900" >
113
- 링크가 복사되었어요!
124
+ { toastMessage . title }
114
125
</ Toast . Title >
115
126
< Toast . Description className = "text-sm text-gray-500" >
116
- 현재 페이지의 URL이 클립보드에 복사되었어요.
127
+ { toastMessage . description }
117
128
</ Toast . Description >
118
129
</ Toast . Root >
119
- < Toast . Viewport className = "fixed top -0 left-1/2 z-50 m-0 flex w-96 -translate-x-1/2 justify-center p-6 outline-none" />
130
+ < Toast . Viewport className = "fixed right -0 bottom-0 z-50 m-0 flex w-96 justify-center p-6 outline-none" />
120
131
</ div >
121
132
</ Suspense >
122
133
</ div >
0 commit comments