Skip to content

Commit

Permalink
feat: kakao share at setting
Browse files Browse the repository at this point in the history
  • Loading branch information
bepyan committed Aug 23, 2024
1 parent f5f7894 commit 87ed94e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
28 changes: 6 additions & 22 deletions src/components/editor/elements/share-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PopoverContent,
PopoverTrigger,
} from "~/components/ui/popover";
import { kakaoShareInvi } from "~/lib/kakao-share";

type Props = {
element: InferEditorElement<"share">;
Expand Down Expand Up @@ -43,28 +44,11 @@ export default function ShareElement({ element }: Props) {
};

const handleKakaoShare = () => {
window.Kakao.Share.sendDefault({
objectType: "feed",
content: {
imageUrl: editor.config.invitationThumbnail,
imageWidth: 600,
imageHeight: 450,
title: editor.config.invitationTitle,
description: editor.config.invitationDesc,
link: {
mobileWebUrl: link,
webUrl: link,
},
},
buttons: [
{
title: "초대장 열기",
link: {
mobileWebUrl: link,
webUrl: link,
},
},
],
kakaoShareInvi({
link,
title: editor.config.invitationTitle,
description: editor.config.invitationDesc,
imageUrl: editor.config.invitationThumbnail,
});
};

Expand Down
16 changes: 15 additions & 1 deletion src/components/editor/sidebar/sidebar-settings-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ImageDropzone from "~/components/editor/ui/image-dropzone";
import { EditorInput } from "~/components/editor/ui/input";
import { Accordion } from "~/components/ui/accordion";
import { Button } from "~/components/ui/button";
import { KakaoIcon } from "~/components/ui/icons";
import {
SheetDescription,
SheetHeader,
Expand All @@ -21,6 +22,7 @@ import {
updateInvitation,
} from "~/lib/db/schema/invitations.query";
import { uploadImage } from "~/lib/image";
import { kakaoShareInvi } from "~/lib/kakao-share";

type Props = {};

Expand Down Expand Up @@ -193,6 +195,15 @@ function SEOSection() {
return uploadImageMutation.isPending || updateThumbnailMutation.isPending;
}, [uploadImageMutation.isPending, updateThumbnailMutation.isPending]);

const handleShareKakao = () => {
kakaoShareInvi({
link: `https://${editor.config.invitationSubdomain}.invi.my`,
title: editor.config.invitationTitle,
description: editor.config.invitationDesc,
imageUrl: editor.config.invitationThumbnail,
});
};

return (
<div className="grid w-full grid-cols-9 gap-2 border-y p-6">
<div className="col-span-9 flex flex-col">
Expand Down Expand Up @@ -274,7 +285,10 @@ function SEOSection() {
</div>
<div className="col-span-9 flex items-center gap-2">
<Button size="icon" variant="secondary" onClick={handleCopyLink}>
<LinkIcon size={16} />
<LinkIcon className="size-4" />
</Button>
<Button size="icon" variant="secondary" onClick={handleShareKakao}>
<KakaoIcon className="size-4" />
</Button>
<div className="ml-auto flex gap-2">
<Button
Expand Down
30 changes: 30 additions & 0 deletions src/lib/kakao-share.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type kakaoShareFeedProps = {
link: string;
title: string;
description: string;
imageUrl: string;
};

export function kakaoShareInvi({ link, ...props }: kakaoShareFeedProps) {
window.Kakao.Share.sendDefault({
objectType: "feed",
content: {
...props,
imageWidth: 600,
imageHeight: 450,
link: {
mobileWebUrl: link,
webUrl: link,
},
},
buttons: [
{
title: "초대장 열기",
link: {
mobileWebUrl: link,
webUrl: link,
},
},
],
});
}

0 comments on commit 87ed94e

Please sign in to comment.