Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Replace toast notification with checkmark icon on copy in share app

anandbaburajan990a6476ddca
diff --git a/web/apps/share/src/components/file-share/CopyableField.tsx b/web/apps/share/src/components/file-share/CopyableField.tsx
index 29d8ec535c..542b703094 100644
--- a/web/apps/share/src/components/file-share/CopyableField.tsx
+++ b/web/apps/share/src/components/file-share/CopyableField.tsx
@@ -1,6 +1,7 @@
+import CheckIcon from "@mui/icons-material/Check";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import { Box, IconButton, Typography } from "@mui/material";
-import React from "react";
+import React, { useState } from "react";
interface CopyableFieldProps {
label: string;
@@ -17,6 +18,16 @@ export const CopyableField: React.FC<CopyableFieldProps> = ({
multiline = false,
maskValue = false,
}) => {
+ const [copied, setCopied] = useState(false);
+
+ const handleCopy = () => {
+ onCopy(value);
+ setCopied(true);
+ setTimeout(() => {
+ setCopied(false);
+ }, 2000);
+ };
+
return (
<Box>
<Typography
@@ -51,19 +62,37 @@ export const CopyableField: React.FC<CopyableFieldProps> = ({
{maskValue ? "**********************" : value}
</Typography>
</Box>
- <IconButton
- onClick={() => onCopy(value)}
- sx={{
- position: "absolute",
- top: multiline ? 8 : "50%",
- right: 8,
- transform: multiline ? "none" : "translateY(-50%)",
- color: "#757575",
- "&:hover": { bgcolor: "rgba(0, 0, 0, 0.04)" },
- }}
- >
- <ContentCopyIcon fontSize="small" />
- </IconButton>
+ {copied ? (
+ <Box
+ sx={{
+ position: "absolute",
+ top: multiline ? 8 : "50%",
+ right: 8,
+ transform: multiline ? "none" : "translateY(-50%)",
+ color: "#4caf50",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ p: 1,
+ }}
+ >
+ <CheckIcon fontSize="small" />
+ </Box>
+ ) : (
+ <IconButton
+ onClick={handleCopy}
+ sx={{
+ position: "absolute",
+ top: multiline ? 8 : "50%",
+ right: 8,
+ transform: multiline ? "none" : "translateY(-50%)",
+ color: "#757575",
+ "&:hover": { bgcolor: "rgba(0, 0, 0, 0.04)" },
+ }}
+ >
+ <ContentCopyIcon fontSize="small" />
+ </IconButton>
+ )}
</Box>
</Box>
);
diff --git a/web/apps/share/src/hooks/useFileShare.ts b/web/apps/share/src/hooks/useFileShare.ts
index a7d61f1243..03e68db523 100644
--- a/web/apps/share/src/hooks/useFileShare.ts
+++ b/web/apps/share/src/hooks/useFileShare.ts
@@ -109,10 +109,6 @@ export const useFileShare = (): UseFileShareResult => {
const handleCopyContent = async (content: string) => {
try {
await navigator.clipboard.writeText(content);
- setNotificationAttributes({
- color: "secondary",
- title: "Copied to clipboard",
- });
} catch {
setNotificationAttributes({
color: "critical",