-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 공유하기(링크, 카카오) 기능 구현 #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const initializeKakao = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Promise<void>(resolve => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (window.Kakao && window.Kakao.Link) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const script = document.createElement('script'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script.src = `https://developers.kakao.com/sdk/js/kakao.js`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script.async = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document.head.appendChild(script); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script.onload = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (window.Kakao) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Kakao.init(import.meta.env.VITE_KAKAO_MAP_API_KEY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Kakao SDK 초기화 로직 개선 필요 카카오 SDK 초기화 함수가 잘 구현되어 있지만, 몇 가지 개선할 점이 있습니다.
- if (window.Kakao && window.Kakao.Link) {
+ if (window.Kakao?.Link) {
resolve();
return;
}
script.onload = () => {
if (window.Kakao) {
- window.Kakao.init(import.meta.env.VITE_KAKAO_MAP_API_KEY);
+ try {
+ window.Kakao.init(import.meta.env.VITE_KAKAO_MAP_API_KEY);
+ console.log('카카오 SDK가 초기화되었습니다.');
+ } catch (error) {
+ console.error('카카오 SDK 초기화 실패:', error);
+ }
}
resolve();
};📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 3-3: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const shareToKakao = async (title: string, description: string, imageUrl: string, linkUrl: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await initializeKakao(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!window.Kakao?.Link?.sendDefault) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('카카오 SDK가 초기화되지 않았습니다.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.Kakao.Link.sendDefault({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| objectType: 'feed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imageUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mobileWebUrl: linkUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| webUrl: linkUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buttons: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: '자세히 보기', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mobileWebUrl: linkUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| webUrl: linkUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain공유 기능 구현이 잘 되었으나 검증 필요 카카오 공유 기능이 잘 구현되어 있습니다. 적절한 오류 처리와 함께 필요한 파라미터를 전달하고 있습니다. 다만, Maps API 키가 Link API에도 사용 가능한지 확인이 필요합니다. Maps API와 Share API의 키가 동일한 경우도 있지만, 다른 경우도 있을 수 있습니다: 🌐 Web query: 💡 Result: 카카오의 지도 서비스와 공유 기능을 사용하기 위해서는 각각 별도의 API 키가 필요합니다. 지도 관련 기능을 구현하려면 카카오 지도 API 키를, 공유 기능을 구현하려면 카카오 공유 API 키를 발급받아야 합니다. 이러한 API 키는 각 서비스의 개발자 사이트에서 신청할 수 있으며, 발급 과정에서 필요한 정보와 절차를 안내받을 수 있습니다. 카카오 공유 API 키 확인 필요 공유 기능 구현은 적절하지만, 카카오 지도 API 키(Maps API Key)와 공유 기능(Link API) 키는 별도입니다. 현재 프로젝트에 설정된 키가 공유용 키인지 반드시 검증해 주세요.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| export interface KakaoLinkOptions { | ||
| objectType: 'feed'; | ||
| content: { | ||
| title: string; | ||
| description: string; | ||
| imageUrl: string; | ||
| link: { | ||
| mobileWebUrl: string; | ||
| webUrl: string; | ||
| }; | ||
| }; | ||
| buttons: Array<{ | ||
| title: string; | ||
| link: { | ||
| mobileWebUrl: string; | ||
| webUrl: string; | ||
| }; | ||
| }>; | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| Kakao: { | ||
| init: (key: string) => void; | ||
| Link: { | ||
| sendDefault: (options: KakaoLinkOptions) => void; | ||
| }; | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
이벤트 데이터 안전한 전달 보장 필요
ShareEventModal에 새로운 props를 전달하여 카카오 공유 기능을 지원하고 있습니다. 하지만 event가 undefined일 경우에 대한 처리가 불완전합니다.
다음과 같이 기본값을 제공하여 안전성을 개선하세요:
{isModalOpen && ( <ShareEventModal closeModal={closeModal} eventName={title} - eventDescription={event?.result.description} - eventImageUrl={event?.result.bannerImageUrl} + eventDescription={event?.result.description || '이벤트 설명이 없습니다.'} + eventImageUrl={event?.result.bannerImageUrl || '기본 이미지 URL'} eventUrl={window.location.href} /> )}📝 Committable suggestion