Adding a check when link is clicked, and now also on the text
This commit is contained in:
@@ -4,10 +4,11 @@ import { useModals } from "@mantine/modals";
|
|||||||
import { ModalsContextProps } from "@mantine/modals/lib/context";
|
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, TbChecks } from "react-icons/tb";
|
||||||
import { useState } from "react";
|
import { useState, useRef } 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";
|
||||||
|
import {TIMEOUT} from "dns";
|
||||||
|
|
||||||
const showCompletedUploadModal = (
|
const showCompletedUploadModal = (
|
||||||
modals: ModalsContextProps,
|
modals: ModalsContextProps,
|
||||||
@@ -23,13 +24,34 @@ const showCompletedUploadModal = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
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 [linkClicked, setLinkClicked] = useState(false);
|
||||||
|
const [checkState, setCheckState] = useState(false);
|
||||||
|
const timerRef = useRef<number | ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||||
|
|
||||||
const link = `${appUrl}/share/${share.id}`;
|
const link = `${appUrl}/share/${share.id}`;
|
||||||
|
|
||||||
|
const copyLink = () => {
|
||||||
|
clipboard.copy(link);
|
||||||
|
toast.success("Your link was copied to the keyboard.");
|
||||||
|
|
||||||
|
if (timerRef.current) {
|
||||||
|
clearTimeout(timerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
timerRef.current = setTimeout(() => {
|
||||||
|
setCheckState(false);
|
||||||
|
}, 1500);
|
||||||
|
|
||||||
|
setLinkClicked(true);
|
||||||
|
setCheckState(true);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack align="stretch">
|
<Stack align="stretch">
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -37,22 +59,13 @@ const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
|||||||
variant="filled"
|
variant="filled"
|
||||||
style={{ borderColor: "green" }}
|
style={{ borderColor: "green" }}
|
||||||
value={link}
|
value={link}
|
||||||
onClick={() => {
|
onClick={copyLink}
|
||||||
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
|
||||||
onClick={() => {
|
onClick={copyLink}
|
||||||
clipboard.copy(link);
|
|
||||||
toast.success("Your link was copied to the keyboard.");
|
|
||||||
setLinkClicked(true);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<TbCopy />
|
{ checkState ? <TbChecks /> : <TbCopy /> }
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user