-
Notifications
You must be signed in to change notification settings - Fork 6
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
페이지 기능: 카카오 공유하기 기능 추가 #178
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9154faf
feat: useKakaoShare 커스텀훅 제작
bottlewook 0458477
feat: 카카오 공유하기 기능 완성
bottlewook 5e39374
assets: 카카오 로그인 사진 등록
bottlewook 4ce73e2
chore: useEffect 삭제
bottlewook 790457a
feat: KakaoLoginButton 컴포넌트 제작
bottlewook df1e423
feat: 카카오 로그인 인가코드 로직 제작
bottlewook e5c793b
feat: query clear 추가
bottlewook 0f93897
chore: 경로 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/components/shared/kakao-share-button/KakaoShareButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-disable jsx-a11y/control-has-associated-label */ | ||
|
||
import Script from 'next/script'; | ||
|
||
import Share from '@/components/icons/Share'; | ||
import useKakaoShare from '@hooks/useKakaoShare'; | ||
|
||
function KakaoShareButton() { | ||
const containerId = useKakaoShare('#kakao-link-btn', process.env.NEXT_PUBLIC_KAKAO_APP_JS_KEY!); | ||
|
||
return ( | ||
<> | ||
<button id={containerId} style={{ cursor: 'pointer' }}> | ||
<Share /> | ||
</button> | ||
<Script | ||
strategy="afterInteractive" | ||
type="text/javascript" | ||
src={`https://t1.kakaocdn.net/kakao_js_sdk/${process.env.NEXT_PUBLIC_KAKAO_LOGIN_VERSION}/kakao.min.js`} | ||
/> | ||
</> | ||
); | ||
} | ||
export default KakaoShareButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import { useCallback, useEffect } from 'react'; | ||
|
||
declare global { | ||
interface Window { | ||
Kakao: any | ||
} | ||
} | ||
|
||
function useKakaoShare(containerId: string, key: string) { | ||
const createShareButton = useCallback(() => { | ||
// kakao sdk script이 정상적으로 불러와졌으면 window.Kakao로 접근이 가능합니다 | ||
if (window.Kakao) { | ||
const kakao = window.Kakao; | ||
// 중복 initialization 방지 | ||
if (!kakao.isInitialized()) { | ||
// 두번째 step 에서 가져온 javascript key 를 이용하여 initialize | ||
kakao.init(key); | ||
} | ||
kakao.Share.createDefaultButton({ | ||
// Render 부분 id=kakao-link-btn 을 찾아 그부분에 렌더링을 합니다 | ||
container: containerId, | ||
objectType: 'feed', | ||
content: { | ||
title: 'Washfit', | ||
description: '안전한 세차용품 정보 제공 플랫폼', | ||
imageUrl: | ||
'https://tago.kr/images/sub/TG300-D02_img01.png', | ||
link: { | ||
webUrl: 'https://dev.washfit.site/', | ||
mobileWebUrl: 'https://dev.washfit.site/', | ||
}, | ||
}, | ||
social: { | ||
likeCount: 77, | ||
commentCount: 55, | ||
sharedCount: 333, | ||
}, | ||
buttons: [ | ||
// 카카오톡 웹에서 보기 | ||
{ | ||
title: '웹으로 보기', | ||
link: { | ||
mobileWebUrl: 'https://dev.washfit.site/', | ||
webUrl: 'https://dev.washfit.site/', | ||
}, | ||
}, | ||
// 카카오톡 모바일에서 보기 | ||
{ | ||
title: '앱으로 보기', | ||
link: { | ||
mobileWebUrl: 'https://dev.washfit.site/', | ||
webUrl: 'https://dev.washfit.site/', | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
}, [containerId, key]); | ||
|
||
useEffect(() => { | ||
createShareButton(); | ||
}, [createShareButton]); | ||
|
||
// #kakao-link-btn과 같은 id에서 '#'제거 과정 | ||
const id = containerId.substring(1); | ||
return id; | ||
} | ||
|
||
export default useKakaoShare; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.