Handle cases where share is not available

This commit is contained in:
Nicolas Mowen 2024-09-12 08:20:23 -06:00
parent a09cc787fb
commit 4cbabdcc39
3 changed files with 19 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import { DeleteClipType, Export } from "@/types/export";
import { MdEditSquare } from "react-icons/md"; import { MdEditSquare } from "react-icons/md";
import { baseUrl } from "@/api/baseUrl"; import { baseUrl } from "@/api/baseUrl";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { shareOrCopy } from "@/utils/browserUtil";
type ExportProps = { type ExportProps = {
className: string; className: string;
@ -151,10 +152,10 @@ export default function ExportCard({
<Chip <Chip
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500" className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
onClick={() => onClick={() =>
navigator.share({ shareOrCopy(
url: `${baseUrl}exports?id=${exportedRecording.id}`, `${baseUrl}exports?id=${exportedRecording.id}`,
title: exportedRecording.name.replaceAll("_", " "), exportedRecording.name.replaceAll("_", " "),
}) )
} }
> >
<FaShareAlt className="size-4 text-white" /> <FaShareAlt className="size-4 text-white" />

View File

@ -36,6 +36,7 @@ import {
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { baseUrl } from "@/api/baseUrl"; import { baseUrl } from "@/api/baseUrl";
import { shareOrCopy } from "@/utils/browserUtil";
type ReviewDetailDialogProps = { type ReviewDetailDialogProps = {
review?: ReviewSegment; review?: ReviewSegment;
@ -143,9 +144,7 @@ export default function ReviewDetailDialog({
variant="secondary" variant="secondary"
size="sm" size="sm"
onClick={() => onClick={() =>
navigator.share({ shareOrCopy(`${baseUrl}review?id=${review.id}`)
url: `${baseUrl}review?id=${review.id}`,
})
} }
> >
<FaShareAlt className="size-4" /> <FaShareAlt className="size-4" />

View File

@ -0,0 +1,12 @@
import copy from "copy-to-clipboard";
export function shareOrCopy(url: string, title?: string) {
if (window.isSecureContext && "share" in navigator) {
navigator.share({
url: url,
title: title,
});
} else {
copy(url);
}
}