mirror of
https://github.com/Mail-0/Zero.git
synced 2026-06-28 14:56:48 +00:00
fix
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
const COPIED_OTP_CODES_KEY = 'copiedOtpCodes';
|
||||
|
||||
export function useCopiedOtpCodes() {
|
||||
const [copiedCodes, setCopiedCodes] = useState<Set<string>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const stored = localStorage.getItem(COPIED_OTP_CODES_KEY);
|
||||
if (stored) {
|
||||
setCopiedCodes(new Set(JSON.parse(stored)));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load copied OTP codes:', error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
localStorage.setItem(COPIED_OTP_CODES_KEY, JSON.stringify([...copiedCodes]));
|
||||
} catch (error) {
|
||||
console.error('Failed to save copied OTP codes:', error);
|
||||
}
|
||||
}, [copiedCodes]);
|
||||
|
||||
const markAsCopied = useCallback((codeId: string) => {
|
||||
setCopiedCodes((prev) => new Set([...prev, codeId]));
|
||||
}, []);
|
||||
|
||||
const isCodeCopied = useCallback(
|
||||
(codeId: string) => {
|
||||
return copiedCodes.has(codeId);
|
||||
},
|
||||
[copiedCodes],
|
||||
);
|
||||
|
||||
const clearAll = useCallback(() => {
|
||||
setCopiedCodes(new Set());
|
||||
}, []);
|
||||
|
||||
return {
|
||||
markAsCopied,
|
||||
isCodeCopied,
|
||||
clearAll,
|
||||
copiedCodes,
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useCopiedOtpCodes } from '@/hooks/use-copied-otp-codes';
|
||||
import { useQuery, useMutation } from '@tanstack/react-query';
|
||||
import { useCopyToClipboard } from './use-copy-to-clipboard';
|
||||
import { useTRPC } from '@/providers/query-provider';
|
||||
@@ -22,7 +21,6 @@ export interface OTPEmail {
|
||||
|
||||
export function useOTPEmails(connectionId: string) {
|
||||
const trpc = useTRPC();
|
||||
const { markAsCopied, isCodeCopied } = useCopiedOtpCodes();
|
||||
const { copyToClipboard } = useCopyToClipboard();
|
||||
const [copiedCodes, setCopiedCodes] = useState<Set<string>>(new Set());
|
||||
|
||||
@@ -77,7 +75,6 @@ export function useOTPEmails(connectionId: string) {
|
||||
const handleCopyCode = useCallback(
|
||||
async (otp: OTPEmail) => {
|
||||
await copyToClipboard(otp?.code || '', otp.id);
|
||||
markAsCopied(otp.id);
|
||||
setCopiedCodes((prev) => new Set([...prev, otp.id]));
|
||||
|
||||
if (!otp.isCopied) {
|
||||
@@ -88,7 +85,7 @@ export function useOTPEmails(connectionId: string) {
|
||||
description: `${otp.service} code copied to clipboard`,
|
||||
});
|
||||
},
|
||||
[copyToClipboard, markAsCopied, markAsCopiedMutation],
|
||||
[copyToClipboard, markAsCopiedMutation],
|
||||
);
|
||||
|
||||
const handleDeleteOTP = useCallback(
|
||||
@@ -127,7 +124,7 @@ export function useOTPEmails(connectionId: string) {
|
||||
handleDeleteOTP,
|
||||
handleClearExpired,
|
||||
hasExpiredOTPs,
|
||||
isCodeCopied: (otpId: string) => copiedCodes.has(otpId) || isCodeCopied(otpId),
|
||||
isCodeCopied: (otpId: string) => copiedCodes.has(otpId),
|
||||
isDeletingOTP: deleteMutation.isPending,
|
||||
isClearingExpired: deleteExpiredMutation.isPending,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user