@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import { Check, Copy, Link2, X } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export interface ShareDialogProps {
|
||||
@@ -41,49 +40,9 @@ export function ShareDialog({
|
||||
onCopyShareLink,
|
||||
}: ShareDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const [overviewCopied, setOverviewCopied] = useState(false);
|
||||
const closeLabel = t("common.close");
|
||||
const copyLabel = shareCopied ? t("share.copied") : t("share.copyLink");
|
||||
const overviewCopyLabel = overviewCopied ? t("share.copied") : t("share.copyOverviewLink");
|
||||
const overviewLink = shareLink ? `${shareLink}/overview` : null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!shareLink) {
|
||||
setOverviewCopied(false);
|
||||
}
|
||||
}, [shareLink]);
|
||||
|
||||
const copyOverviewLink = async () => {
|
||||
if (!overviewLink) return;
|
||||
|
||||
const markCopied = () => {
|
||||
setOverviewCopied(true);
|
||||
setTimeout(() => setOverviewCopied(false), 2000);
|
||||
};
|
||||
|
||||
if (navigator.clipboard?.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(overviewLink);
|
||||
markCopied();
|
||||
return;
|
||||
} catch {
|
||||
// Fall back to textarea-based copy.
|
||||
}
|
||||
}
|
||||
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = overviewLink;
|
||||
textarea.style.position = "fixed";
|
||||
textarea.style.opacity = "0";
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand("copy");
|
||||
markCopied();
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
};
|
||||
const getPersonLabel = (person: string) => (person === "all" ? t("share.allPeople") : person);
|
||||
|
||||
// ESC is handled by the global handler in App.tsx to avoid double history.back()
|
||||
|
||||
@@ -152,34 +111,13 @@ export function ShareDialog({
|
||||
{shareCopied ? <Check size={18} aria-hidden="true" /> : <Copy size={18} aria-hidden="true" />}
|
||||
</button>
|
||||
</div>
|
||||
<p className="share-link-label">{t("share.overviewLink")}</p>
|
||||
<div className="share-link-box">
|
||||
<input
|
||||
type="text"
|
||||
value={overviewLink ?? ""}
|
||||
readOnly
|
||||
className="share-link-input"
|
||||
onClick={(e) => (e.target as HTMLInputElement).select()}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="btn-copy icon-only tooltip-trigger"
|
||||
onClick={copyOverviewLink}
|
||||
aria-label={overviewCopyLabel}
|
||||
data-tooltip={overviewCopyLabel}
|
||||
>
|
||||
{overviewCopied ? <Check size={18} aria-hidden="true" /> : <Copy size={18} aria-hidden="true" />}
|
||||
</button>
|
||||
</div>
|
||||
{shareCopied && <span className="share-copied-hint">{t("share.copied")}</span>}
|
||||
{overviewCopied && <span className="share-copied-hint">{t("share.copied")}</span>}
|
||||
<div className="share-dialog-footer">
|
||||
<button
|
||||
className="ghost"
|
||||
onClick={() => {
|
||||
onShareLinkChange(null);
|
||||
onShareCopiedChange(false);
|
||||
setOverviewCopied(false);
|
||||
}}
|
||||
>
|
||||
{t("share.generateAnother")}
|
||||
@@ -201,7 +139,7 @@ export function ShareDialog({
|
||||
>
|
||||
{sharePeople.map((person) => (
|
||||
<option key={person} value={person}>
|
||||
{person}
|
||||
{getPersonLabel(person)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user