Skip to content

Commit 9562560

Browse files
authoredFeb 12, 2025··
feat: URL 복사 실패 시 사용자 피드백을 위한 토스트 메시지 추가 (#66)
1 parent 91f549d commit 9562560

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed
 

‎src/pages/TimetableSharingActivity.tsx

+25-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
1717
}) => {
1818
const templateRef = useRef<HTMLDivElement>(null);
1919
const [openToast, setOpenToast] = useState(false);
20+
const [toastMessage, setToastMessage] = useState({
21+
title: '',
22+
description: '',
23+
});
2024

2125
const captureTemplate = async () => {
2226
if (!templateRef.current) return null;
@@ -49,8 +53,6 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
4953
};
5054

5155
const handleClickShare = async () => {
52-
if (!navigator.share) return;
53-
5456
try {
5557
const imageUrl = await captureTemplate();
5658

@@ -68,22 +70,31 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
6870
files: [file],
6971
};
7072

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);
7774
}
7875
} 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+
});
8192
}
8293
};
8394

8495
return (
8596
<AppScreen>
86-
<Toast.Provider swipeDirection="down">
97+
<Toast.Provider swipeDirection="right" duration={3000}>
8798
<div className="flex min-h-dvh flex-col py-6">
8899
<AppBar progress={100} />
89100
<div className="mt-6 flex flex-1 flex-col items-center justify-evenly">
@@ -110,13 +121,13 @@ const TimetableSharingActivity: ActivityComponentType<TimetableSharingParams> =
110121
onOpenChange={setOpenToast}
111122
>
112123
<Toast.Title className="mb-1 font-medium text-gray-900">
113-
링크가 복사되었어요!
124+
{toastMessage.title}
114125
</Toast.Title>
115126
<Toast.Description className="text-sm text-gray-500">
116-
현재 페이지의 URL이 클립보드에 복사되었어요.
127+
{toastMessage.description}
117128
</Toast.Description>
118129
</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" />
120131
</div>
121132
</Suspense>
122133
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.