Skip to content

Commit

Permalink
fix: added use-effect to reset copy-state and removed type-any
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 authored and birme committed Sep 22, 2024
1 parent be787bc commit 36c5331
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/components/landing-page/create-production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,27 @@ export const CreateProduction = () => {
}
}, [createdProductionId, dispatch, reset]);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleCopyProdUrlsToClipboard = (input: any) => {
useEffect(() => {
let timeout: number | null = null;
if (copiedUrl) {
timeout = window.setTimeout(() => {
setCopiedUrl(false);
}, 1500);
}
return () => {
if (timeout !== null) {
window.clearTimeout(timeout);
}
};
}, [copiedUrl]);

const handleCopyProdUrlsToClipboard = (input: string[]) => {
if (input !== null) {
navigator.clipboard
.writeText(input)
.writeText(input.join("\n"))
.then(() => {
let timeout: number | null = null;
setCopiedUrl(true);
console.log("Text copied to clipboard");

timeout = window.setTimeout(() => {
setCopiedUrl(false);
}, 1500);

return () => {
if (timeout !== null) {
window.clearTimeout(timeout);
}
};
})
.catch((err) => {
console.error("Failed to copy text: ", err);
Expand Down Expand Up @@ -229,12 +231,12 @@ export const CreateProduction = () => {
</PrimaryButton>
</ButtonWrapper>
</FlexContainer>
{createdProductionId !== null && production && (
{createdProductionId !== null && (
<>
<ProductionConfirmation>
The production ID is: {createdProductionId.toString()}
</ProductionConfirmation>
{!productionFetchError && (
{!productionFetchError && production && (
<CopyToClipboardWrapper>
<PrimaryButton
type="button"
Expand Down

0 comments on commit 36c5331

Please sign in to comment.