Skip to content

Commit 7df3d63

Browse files
authored
Merge pull request #66 from cskime/feature/#34
[#34] Emoji picker 추가, 공유하기 개발
2 parents 48c102c + 023ba26 commit 7df3d63

File tree

8 files changed

+154
-15
lines changed

8 files changed

+154
-15
lines changed

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@
4141
<div id="popover"></div>
4242
<div id="modal"></div>
4343
<script type="module" src="/src/main.jsx"></script>
44+
45+
<!-- Kakao JavaScript SDK -->
46+
<script
47+
src="https://t1.kakaocdn.net/kakao_js_sdk/2.7.6/kakao.min.js"
48+
integrity="sha384-WAtVcQYcmTO/N+C1N+1m6Gp8qxh+3NlnP7X1U7qP6P5dQY/MsRBNTh+e1ahJrkEm"
49+
crossorigin="anonymous"
50+
></script>
4451
</body>
4552
</html>

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"axios": "^1.11.0",
14+
"emoji-picker-react": "^4.13.2",
1415
"react": "^19.1.1",
1516
"react-dom": "^19.1.1",
1617
"react-quill-new": "^3.6.0",

src/features/rolling-paper/components/rolling-paper-header.jsx

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import EmojiPicker from "emoji-picker-react";
12
import styled from "styled-components";
23
import addImage from "../../../assets/ic-face-smile-add.svg";
34
import shareImage from "../../../assets/ic-share.svg";
45
import { OutlinedButton } from "../../../components/button/button";
56
import BUTTON_SIZE from "../../../components/button/button-size";
67
import Colors from "../../../components/color/colors";
8+
import Popover from "../../../components/popover/popover";
9+
import POPOVER_ALIGNMENT from "../../../components/popover/popover-alignment";
10+
import Toast from "../../../components/toast/toast";
711
import { useMedia } from "../../../hooks/use-media";
12+
import { useToast } from "../../../hooks/use-toast";
13+
import { shareRollingPaper } from "../../../libs/kakao/kakao-service";
814
import { media } from "../../../utils/media";
915
import RollingPaperReactions from "./rolling-paper-reactions";
1016
import RollingPaperSenders from "./rolling-paper-senders";
17+
import RollingPaperSharePopover from "./rolling-paper-share-popover";
1118

1219
const RecipientName = styled.h2`
1320
margin: 0;
@@ -100,22 +107,37 @@ const StyledRollingPaperHeader = styled.div`
100107
}
101108
`;
102109

103-
function RollingPaperHeader({ recipientName, messages, reactions }) {
110+
function RollingPaperHeader({
111+
recipientId,
112+
recipientName,
113+
messages,
114+
reactions,
115+
}) {
116+
const { showsToast, setShowsToast } = useToast();
104117
const { isDesktop, isMobile } = useMedia();
105118

119+
const name = <RecipientName>{`To. ${recipientName}`}</RecipientName>;
120+
121+
const handleShareKakao = () => {
122+
shareRollingPaper({
123+
recipientId,
124+
recipientName,
125+
});
126+
};
127+
128+
const handleShareUrl = () => {
129+
const url = window.location.href;
130+
navigator.clipboard.writeText(url);
131+
setShowsToast(true);
132+
};
133+
106134
return (
107135
<StyledRollingPaperHeader>
108136
{isMobile && (
109-
<RollingPaperHeaderContent>
110-
<RecipientName>{`To. ${recipientName}`}</RecipientName>
111-
</RollingPaperHeaderContent>
137+
<RollingPaperHeaderContent>{name}</RollingPaperHeaderContent>
112138
)}
113139
<RollingPaperHeaderContent>
114-
{isMobile || (
115-
<div>
116-
<RecipientName>{`To. ${recipientName}`}</RecipientName>
117-
</div>
118-
)}
140+
{isMobile || <div>{name}</div>}
119141
<HeaderTrailing>
120142
<DividedContainer>
121143
{isDesktop && (
@@ -126,15 +148,40 @@ function RollingPaperHeader({ recipientName, messages, reactions }) {
126148
<RollingPaperReactions reactions={reactions.slice(0, 8)} />
127149
</DividedContainer>
128150
<DividedContainer>
129-
<AddButton
130-
size={BUTTON_SIZE.small}
131-
title={isMobile ? null : "추가"}
132-
icon={addImage}
133-
/>
134-
<ShareButton size={BUTTON_SIZE.small} icon={shareImage} />
151+
<Popover
152+
id="emoji-picker-popover"
153+
alignment={POPOVER_ALIGNMENT.right}
154+
action={
155+
<AddButton
156+
size={BUTTON_SIZE.small}
157+
title={isMobile ? null : "추가"}
158+
icon={addImage}
159+
/>
160+
}
161+
>
162+
<EmojiPicker />
163+
</Popover>
164+
<Popover
165+
id="share-popover"
166+
alignment={POPOVER_ALIGNMENT.right}
167+
action={
168+
<ShareButton size={BUTTON_SIZE.small} icon={shareImage} />
169+
}
170+
>
171+
<RollingPaperSharePopover
172+
onShareKakao={handleShareKakao}
173+
onShareUrl={handleShareUrl}
174+
/>
175+
</Popover>
135176
</DividedContainer>
136177
</HeaderTrailing>
137178
</RollingPaperHeaderContent>
179+
{showsToast && (
180+
<Toast
181+
message="URL이 복사 되었습니다."
182+
onDismiss={() => setShowsToast(false)}
183+
/>
184+
)}
138185
</StyledRollingPaperHeader>
139186
);
140187
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import styled from "styled-components";
2+
import Colors from "../../../components/color/colors";
3+
4+
const ShareOption = styled.li`
5+
padding: 12px 16px;
6+
font-size: 16px;
7+
font-weight: 400;
8+
line-height: 26px;
9+
background-color: white;
10+
cursor: pointer;
11+
12+
&:hover {
13+
background-color: ${Colors.gray(100)};
14+
}
15+
`;
16+
17+
const StyledRollingPaperSharePopover = styled.ul`
18+
display: flex;
19+
flex-direction: column;
20+
padding: 10px 0;
21+
background-color: white;
22+
width: 140px;
23+
list-style: none;
24+
margin: 0;
25+
`;
26+
27+
function RollingPaperSharePopover({ onShareKakao, onShareUrl }) {
28+
return (
29+
<StyledRollingPaperSharePopover>
30+
<ShareOption onClick={onShareKakao}>카카오톡 공유</ShareOption>
31+
<ShareOption onClick={onShareUrl}>URL 공유</ShareOption>
32+
</StyledRollingPaperSharePopover>
33+
);
34+
}
35+
36+
export default RollingPaperSharePopover;

src/libs/kakao/kakao-service.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function initKakaoSDK() {
2+
window.Kakao.init(import.meta.env.VITE_KAKAO_JAVASCRIPT_KEY);
3+
window.Kakao.isInitialized();
4+
}
5+
6+
function shareRollingPaper({ recipientId, recipientName }) {
7+
if (!recipientId || !recipientName) return;
8+
9+
const appIdString = import.meta.env.VITE_KAKAO_MESSAGE_TEMPLATE_ID;
10+
const appId = Number(appIdString);
11+
if (!appId) return;
12+
13+
window.Kakao.Share.sendCustom({
14+
templateId: appId,
15+
templateArgs: {
16+
recipientId,
17+
recipientName,
18+
},
19+
});
20+
}
21+
22+
export { initKakaoSDK, shareRollingPaper };

src/main.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
33
import App from "./app";
4+
import { initKakaoSDK } from "./libs/kakao/kakao-service";
5+
6+
initKakaoSDK();
47

58
const root = createRoot(document.getElementById("root"));
69

src/pages/messages-page.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function MessagesPage() {
1717
{recipient && (
1818
<>
1919
<RollingPaperHeader
20+
recipientId={recipient.id}
2021
recipientName={recipient.name}
2122
messages={recipient.recentMessages}
2223
reactions={recipient.topReactions}

0 commit comments

Comments
 (0)