mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-11-05 07:20:13 +01:00
feat: Adding the possibility of copying the link by clicking text and icons (#171)
This commit is contained in:
parent
932496a121
commit
348852cfa4
@ -1,9 +1,7 @@
|
|||||||
import { ActionIcon, Button, Stack, TextInput } from "@mantine/core";
|
import { Button, Stack } from "@mantine/core";
|
||||||
import { useClipboard } from "@mantine/hooks";
|
|
||||||
import { useModals } from "@mantine/modals";
|
import { useModals } from "@mantine/modals";
|
||||||
import { ModalsContextProps } from "@mantine/modals/lib/context";
|
import { ModalsContextProps } from "@mantine/modals/lib/context";
|
||||||
import { TbCopy } from "react-icons/tb";
|
import CopyTextField from "../../upload/CopyTextField";
|
||||||
import toast from "../../../utils/toast.util";
|
|
||||||
|
|
||||||
const showCompletedReverseShareModal = (
|
const showCompletedReverseShareModal = (
|
||||||
modals: ModalsContextProps,
|
modals: ModalsContextProps,
|
||||||
@ -26,28 +24,11 @@ const Body = ({
|
|||||||
link: string;
|
link: string;
|
||||||
getReverseShares: () => void;
|
getReverseShares: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const clipboard = useClipboard({ timeout: 500 });
|
|
||||||
const modals = useModals();
|
const modals = useModals();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack align="stretch">
|
<Stack align="stretch">
|
||||||
<TextInput
|
<CopyTextField link={link} />
|
||||||
readOnly
|
|
||||||
variant="filled"
|
|
||||||
value={link}
|
|
||||||
rightSection={
|
|
||||||
window.isSecureContext && (
|
|
||||||
<ActionIcon
|
|
||||||
onClick={() => {
|
|
||||||
clipboard.copy(link);
|
|
||||||
toast.success("Your link was copied to the keyboard.");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TbCopy />
|
|
||||||
</ActionIcon>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
48
frontend/src/components/upload/CopyTextField.tsx
Normal file
48
frontend/src/components/upload/CopyTextField.tsx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { useRef, useState } from "react";
|
||||||
|
import toast from "../../utils/toast.util";
|
||||||
|
import { ActionIcon, TextInput } from "@mantine/core";
|
||||||
|
import { TbCheck, TbCopy } from "react-icons/tb";
|
||||||
|
import { useClipboard } from "@mantine/hooks";
|
||||||
|
|
||||||
|
function CopyTextField(props: { link: string }) {
|
||||||
|
const clipboard = useClipboard({ timeout: 500 });
|
||||||
|
const [checkState, setCheckState] = useState(false);
|
||||||
|
const [textClicked, setTextClicked] = useState(false);
|
||||||
|
const timerRef = useRef<number | ReturnType<typeof setTimeout> | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
const copyLink = () => {
|
||||||
|
clipboard.copy(props.link);
|
||||||
|
toast.success("Your link was copied to the keyboard.");
|
||||||
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
|
timerRef.current = setTimeout(() => {
|
||||||
|
setCheckState(false);
|
||||||
|
}, 1500);
|
||||||
|
setCheckState(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TextInput
|
||||||
|
readOnly
|
||||||
|
label="Link"
|
||||||
|
variant="filled"
|
||||||
|
value={props.link}
|
||||||
|
onClick={() => {
|
||||||
|
if (!textClicked) {
|
||||||
|
copyLink();
|
||||||
|
setTextClicked(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
rightSection={
|
||||||
|
window.isSecureContext && (
|
||||||
|
<ActionIcon onClick={copyLink}>
|
||||||
|
{checkState ? <TbCheck /> : <TbCopy />}
|
||||||
|
</ActionIcon>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CopyTextField;
|
@ -1,12 +1,10 @@
|
|||||||
import { ActionIcon, Button, Stack, Text, TextInput } from "@mantine/core";
|
import { Button, Stack, Text } from "@mantine/core";
|
||||||
import { useClipboard } from "@mantine/hooks";
|
|
||||||
import { useModals } from "@mantine/modals";
|
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 { Share } from "../../../types/share.type";
|
import { Share } from "../../../types/share.type";
|
||||||
import toast from "../../../utils/toast.util";
|
import CopyTextField from "../CopyTextField";
|
||||||
|
|
||||||
const showCompletedUploadModal = (
|
const showCompletedUploadModal = (
|
||||||
modals: ModalsContextProps,
|
modals: ModalsContextProps,
|
||||||
@ -23,30 +21,14 @@ const showCompletedUploadModal = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
|
||||||
const clipboard = useClipboard({ timeout: 500 });
|
|
||||||
const modals = useModals();
|
const modals = useModals();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const link = `${appUrl}/share/${share.id}`;
|
const link = `${appUrl}/share/${share.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack align="stretch">
|
<Stack align="stretch">
|
||||||
<TextInput
|
<CopyTextField link={link} />
|
||||||
readOnly
|
|
||||||
variant="filled"
|
|
||||||
value={link}
|
|
||||||
rightSection={
|
|
||||||
window.isSecureContext && (
|
|
||||||
<ActionIcon
|
|
||||||
onClick={() => {
|
|
||||||
clipboard.copy(link);
|
|
||||||
toast.success("Your link was copied to the keyboard.");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TbCopy />
|
|
||||||
</ActionIcon>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Text
|
<Text
|
||||||
size="xs"
|
size="xs"
|
||||||
sx={(theme) => ({
|
sx={(theme) => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user