Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/features/map/collaboration/ShareCollabButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { useState } from 'react';
import { useRouter } from 'next/navigation';
import styled from '@emotion/styled';
import { HugeiconsIcon } from '@hugeicons/react';
import { UserAdd01Icon, CheckmarkCircle01Icon } from '@hugeicons/core-free-icons';
Expand Down Expand Up @@ -43,20 +44,27 @@ const Btn = styled.button<{ $copied: boolean }>`

export function ShareCollabButton() {
const { isLoggedIn } = useAuth();
const router = useRouter();
const [copied, setCopied] = useState(false);

if (!isLoggedIn) return null;

function handleShare() {
const roomId = crypto.randomUUID();
// ์ด๋ฏธ ๋ฐฉ์— ์žˆ์œผ๋ฉด ํ˜„์žฌ URL ์žฌ์‚ฌ์šฉ, ์•„๋‹ˆ๋ฉด ์ƒˆ ๋ฐฉ ์ƒ์„ฑ ํ›„ URL ๊ต์ฒด
const params = new URLSearchParams(window.location.search);
const existingRoom = params.get('room');
const roomId = existingRoom ?? crypto.randomUUID();
const url = `${window.location.origin}/map?room=${roomId}`;

if (!existingRoom) {
router.replace(`/map?room=${roomId}`);
}

navigator.clipboard.writeText(url).then(() => {
setCopied(true);
toast.success('์นœ๊ตฌ ์ดˆ๋Œ€ ๋งํฌ๊ฐ€ ๋ณต์‚ฌ๋์–ด์š”!', { description: '๋งํฌ๋ฅผ ๋ถ™์—ฌ๋„ฃ์–ด ์นœ๊ตฌ์—๊ฒŒ ๊ณต์œ ํ•˜์„ธ์š”.' });
toast.success('์นœ๊ตฌ ์ดˆ๋Œ€ ๋งํฌ๊ฐ€ ๋ณต์‚ฌ๋์–ด์š”!', { description: '์ด ๋งํฌ๋Š” 72์‹œ๊ฐ„ ๋™์•ˆ ์œ ์ง€๋ผ์š”. ๋ถ™์—ฌ๋„ฃ์–ด ์นœ๊ตฌ์—๊ฒŒ ๊ณต์œ ํ•˜์„ธ์š”.' });
setTimeout(() => setCopied(false), 2500);
}).catch(() => {
// fallback: select text manually isn't possible here, just show the URL
toast.info('๋งํฌ ๋ณต์‚ฌ ์‹คํŒจ', { description: url });
});
}
Expand Down
Loading