Adding copy to keyboard when clicking the link
This commit is contained in:
@@ -5,6 +5,7 @@ import { ModalsContextProps } from "@mantine/modals/lib/context";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { TbCopy } from "react-icons/tb";
|
import { TbCopy } from "react-icons/tb";
|
||||||
|
import { useState } from "react";
|
||||||
import { Share } from "../../../types/share.type";
|
import { Share } from "../../../types/share.type";
|
||||||
import toast from "../../../utils/toast.util";
|
import toast from "../../../utils/toast.util";
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
|||||||
const clipboard = useClipboard({ timeout: 500 });
|
const clipboard = useClipboard({ timeout: 500 });
|
||||||
const modals = useModals();
|
const modals = useModals();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const [linkClicked, setLinkClicked] = useState(false);
|
||||||
|
|
||||||
const link = `${appUrl}/share/${share.id}`;
|
const link = `${appUrl}/share/${share.id}`;
|
||||||
return (
|
return (
|
||||||
@@ -34,6 +36,12 @@ const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
|||||||
readOnly
|
readOnly
|
||||||
variant="filled"
|
variant="filled"
|
||||||
value={link}
|
value={link}
|
||||||
|
onClick={() => {
|
||||||
|
if (linkClicked) return;
|
||||||
|
clipboard.copy(link);
|
||||||
|
toast.success("Your link was copied to the keyboard.");
|
||||||
|
setLinkClicked(true);
|
||||||
|
}}
|
||||||
rightSection={
|
rightSection={
|
||||||
window.isSecureContext && (
|
window.isSecureContext && (
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
|
|||||||
Reference in New Issue
Block a user