Skip to content

Commit

Permalink
fix: show alternative to copy button if site is not using https
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Dec 10, 2022
1 parent b1bfb09 commit 7e877ce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
16 changes: 16 additions & 0 deletions frontend/src/components/account/showShareLinkModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Stack, TextInput } from "@mantine/core";
import { ModalsContextProps } from "@mantine/modals/lib/context";

const showShareLinkModal = (modals: ModalsContextProps, shareId: string) => {
const link = `${window.location.origin}/share/${shareId}`;
return modals.openModal({
title: "Share link",
children: (
<Stack align="stretch">
<TextInput variant="filled" value={link} />
</Stack>
),
});
};

export default showShareLinkModal;
18 changes: 10 additions & 8 deletions frontend/src/components/upload/modals/showCompletedUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ const Body = ({ share }: { share: Share }) => {
variant="filled"
value={link}
rightSection={
<ActionIcon
onClick={() => {
clipboard.copy(link);
toast.success("Your link was copied to the keyboard.");
}}
>
<TbCopy />
</ActionIcon>
window.isSecureContext && (
<ActionIcon
onClick={() => {
clipboard.copy(link);
toast.success("Your link was copied to the keyboard.");
}}
>
<TbCopy />
</ActionIcon>
)
}
/>
<Text
Expand Down
17 changes: 11 additions & 6 deletions frontend/src/pages/account/shares.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { TbLink, TbTrash } from "react-icons/tb";
import showShareLinkModal from "../../components/account/showShareLinkModal";
import Meta from "../../components/Meta";
import useUser from "../../hooks/user.hook";
import shareService from "../../services/share.service";
Expand Down Expand Up @@ -83,12 +84,16 @@ const MyShares = () => {
variant="light"
size={25}
onClick={() => {
clipboard.copy(
`${window.location.origin}/share/${share.id}`
);
toast.success(
"Your link was copied to the keyboard."
);
if (window.isSecureContext) {
clipboard.copy(
`${window.location.origin}/share/${share.id}`
);
toast.success(
"Your link was copied to the keyboard."
);
} else {
showShareLinkModal(modals, share.id);
}
}}
>
<TbLink />
Expand Down

0 comments on commit 7e877ce

Please sign in to comment.