From 1f2c5b3eae82d8629f02c3d99a55decc52c2e76b Mon Sep 17 00:00:00 2001 From: ColinRgm Date: Tue, 10 Dec 2024 10:38:46 +0100 Subject: [PATCH 1/4] fix: add a debug alert to see if it works Closes: #202 --- .../src/app/ui/dashboard/SeeToken.tsx | 36 +++++++++---------- .../src/app/ui/dashboard/ShowToken.tsx | 22 ++++++------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx b/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx index 56ccbdc..446e783 100644 --- a/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx +++ b/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx @@ -1,23 +1,23 @@ -import { Button } from "@/components/ui/button"; -import React, { useState } from "react"; +import {Button} from "@/components/ui/button"; +import React, {useState} from "react"; import ShowToken from "@/app/ui/dashboard/ShowToken"; -export default function SeeToken({ ip }: { ip: string }) { - const [showToken, setShowToken] = useState(false); +export default function SeeToken({ip}: { ip: string }) { + const [showToken, setShowToken] = useState(false); - const toggleToken = () => { - setShowToken(!showToken); - }; + const toggleToken = () => { + setShowToken(!showToken); + }; - return ( -
- - {showToken && } -
- ); + return ( +
+ + {showToken && } +
+ ); } diff --git a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx index 2af1db0..3244168 100644 --- a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx +++ b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx @@ -1,16 +1,16 @@ import React from "react"; -import { copyToClipboard } from "@/lib/utils"; -import { useFetchToken } from "@/lib/data"; +import {copyToClipboard} from "@/lib/utils"; +import {useFetchToken} from "@/lib/data"; -export default function ShowToken({ ip }: { ip: string }) { - const newToken = useFetchToken(ip); - copyToClipboard(newToken); +export default function ShowToken({ip}: { ip: string }) { + const newToken = useFetchToken(ip); + copyToClipboard(newToken); - return ( -
- Token copié !
- {newToken} -
- ); + return ( +
+ Token copié !
+ {newToken} +
+ ); } From 04995507b935e1c3cf3746cda2829ce50000c67a Mon Sep 17 00:00:00 2001 From: ColinRgm Date: Tue, 10 Dec 2024 10:38:57 +0100 Subject: [PATCH 2/4] fix: add a debug alert to see if it works Closes: #202 --- nextjs-interface/src/lib/utils.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/nextjs-interface/src/lib/utils.ts b/nextjs-interface/src/lib/utils.ts index c021972..4008488 100644 --- a/nextjs-interface/src/lib/utils.ts +++ b/nextjs-interface/src/lib/utils.ts @@ -1,23 +1,24 @@ -import { type ClassValue, clsx } from "clsx"; -import { twMerge } from "tailwind-merge"; +import {type ClassValue, clsx} from "clsx"; +import {twMerge} from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)); + return twMerge(clsx(inputs)); } export const copyToClipboard = (text: string) => { - navigator.clipboard - .writeText(text) - .then(() => { - console.log("Token copié dans le clipboard"); - }) - .catch((err) => { - console.error("Copie du Token échoué : ", err); - }); + navigator.clipboard + .writeText(text) + .then(() => { + console.log("Token copié dans le clipboard"); + alert("Token copié") + }) + .catch((err) => { + console.error("Copie du Token échoué : ", err); + }); }; export function validateIp(ip: string): boolean { - const ipRegex = - /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/; - return ipRegex.test(ip); + const ipRegex = + /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/; + return ipRegex.test(ip); } From f27dd2a9b993c3abf3a87cdc28c9abf3a86849b0 Mon Sep 17 00:00:00 2001 From: ColinRgm Date: Tue, 10 Dec 2024 15:37:57 +0100 Subject: [PATCH 3/4] fix: use a hook to get the token when available Closes: #202 Closes: #194 --- .../src/app/ui/dashboard/ShowToken.tsx | 14 +++++++++--- nextjs-interface/src/lib/utils.ts | 22 +++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx index 3244168..56935bd 100644 --- a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx +++ b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx @@ -1,11 +1,17 @@ -import React from "react"; +import React, {useEffect} from "react"; import {copyToClipboard} from "@/lib/utils"; import {useFetchToken} from "@/lib/data"; export default function ShowToken({ip}: { ip: string }) { + const newToken = useFetchToken(ip); - copyToClipboard(newToken); + + useEffect(() => { + copyToClipboard(newToken); + }, + [newToken] + ); return (
@@ -13,4 +19,6 @@ export default function ShowToken({ip}: { ip: string }) { {newToken}
); -} + + +} \ No newline at end of file diff --git a/nextjs-interface/src/lib/utils.ts b/nextjs-interface/src/lib/utils.ts index 4008488..e8ab50e 100644 --- a/nextjs-interface/src/lib/utils.ts +++ b/nextjs-interface/src/lib/utils.ts @@ -5,20 +5,24 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } +// Fonction permettant la copie du Token export const copyToClipboard = (text: string) => { - navigator.clipboard - .writeText(text) - .then(() => { - console.log("Token copié dans le clipboard"); - alert("Token copié") - }) - .catch((err) => { - console.error("Copie du Token échoué : ", err); + + if (navigator.clipboard) { + navigator.clipboard.writeText(text).then(() => { + console.log("Token copié dans le presse-papiers"); + }).catch((err) => { + console.error("Erreur lors de la copie du token : ", err); }); + } else { + console.log("Clipboard inaccessible...") + } + }; + export function validateIp(ip: string): boolean { const ipRegex = /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/; return ipRegex.test(ip); -} +} \ No newline at end of file From 4d6e27a49f7f11b7d0daa36e1af73b95797564a3 Mon Sep 17 00:00:00 2001 From: ColinRgm Date: Tue, 10 Dec 2024 15:54:37 +0100 Subject: [PATCH 4/4] fix: reformat Closes: #202 Closes: #194 --- .../src/app/ui/dashboard/SeeToken.tsx | 36 +++++++++--------- .../src/app/ui/dashboard/ShowToken.tsx | 35 ++++++++--------- nextjs-interface/src/lib/utils.ts | 38 +++++++++---------- 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx b/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx index 446e783..56ccbdc 100644 --- a/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx +++ b/nextjs-interface/src/app/ui/dashboard/SeeToken.tsx @@ -1,23 +1,23 @@ -import {Button} from "@/components/ui/button"; -import React, {useState} from "react"; +import { Button } from "@/components/ui/button"; +import React, { useState } from "react"; import ShowToken from "@/app/ui/dashboard/ShowToken"; -export default function SeeToken({ip}: { ip: string }) { - const [showToken, setShowToken] = useState(false); +export default function SeeToken({ ip }: { ip: string }) { + const [showToken, setShowToken] = useState(false); - const toggleToken = () => { - setShowToken(!showToken); - }; + const toggleToken = () => { + setShowToken(!showToken); + }; - return ( -
- - {showToken && } -
- ); + return ( +
+ + {showToken && } +
+ ); } diff --git a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx index 56935bd..15d5654 100644 --- a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx +++ b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx @@ -1,24 +1,19 @@ -import React, {useEffect} from "react"; +import React, { useEffect } from "react"; -import {copyToClipboard} from "@/lib/utils"; -import {useFetchToken} from "@/lib/data"; +import { copyToClipboard } from "@/lib/utils"; +import { useFetchToken } from "@/lib/data"; -export default function ShowToken({ip}: { ip: string }) { +export default function ShowToken({ ip }: { ip: string }) { + const newToken = useFetchToken(ip); - const newToken = useFetchToken(ip); + useEffect(() => { + copyToClipboard(newToken); + }, [newToken]); - useEffect(() => { - copyToClipboard(newToken); - }, - [newToken] - ); - - return ( -
- Token copié !
- {newToken} -
- ); - - -} \ No newline at end of file + return ( +
+ Token copié !
+ {newToken} +
+ ); +} diff --git a/nextjs-interface/src/lib/utils.ts b/nextjs-interface/src/lib/utils.ts index e8ab50e..17376b4 100644 --- a/nextjs-interface/src/lib/utils.ts +++ b/nextjs-interface/src/lib/utils.ts @@ -1,28 +1,28 @@ -import {type ClassValue, clsx} from "clsx"; -import {twMerge} from "tailwind-merge"; +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)); + return twMerge(clsx(inputs)); } // Fonction permettant la copie du Token export const copyToClipboard = (text: string) => { - - if (navigator.clipboard) { - navigator.clipboard.writeText(text).then(() => { - console.log("Token copié dans le presse-papiers"); - }).catch((err) => { - console.error("Erreur lors de la copie du token : ", err); - }); - } else { - console.log("Clipboard inaccessible...") - } - + if (navigator.clipboard) { + navigator.clipboard + .writeText(text) + .then(() => { + console.log("Token copié dans le presse-papiers"); + }) + .catch((err) => { + console.error("Erreur lors de la copie du token : ", err); + }); + } else { + console.log("Clipboard inaccessible..."); + } }; - export function validateIp(ip: string): boolean { - const ipRegex = - /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/; - return ipRegex.test(ip); -} \ No newline at end of file + const ipRegex = + /^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/; + return ipRegex.test(ip); +}