mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-02 20:32:39 +02:00
Initial formatting using biome
This commit is contained in:
parent
4c8ff48155
commit
758603b275
156 changed files with 23825 additions and 29508 deletions
|
|
@ -1,58 +1,58 @@
|
|||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface UseApiKeyReturn {
|
||||
apiKey: string | null
|
||||
isLoading: boolean
|
||||
copied: boolean
|
||||
copyToClipboard: () => Promise<void>
|
||||
apiKey: string | null;
|
||||
isLoading: boolean;
|
||||
copied: boolean;
|
||||
copyToClipboard: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function useApiKey(): UseApiKeyReturn {
|
||||
const [apiKey, setApiKey] = useState<string | null>(null)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [apiKey, setApiKey] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Load API key from localStorage
|
||||
const loadApiKey = () => {
|
||||
try {
|
||||
const token = localStorage.getItem('surfsense_bearer_token')
|
||||
setApiKey(token)
|
||||
} catch (error) {
|
||||
console.error('Error loading API key:', error)
|
||||
toast.error('Failed to load API key')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
// Load API key from localStorage
|
||||
const loadApiKey = () => {
|
||||
try {
|
||||
const token = localStorage.getItem("surfsense_bearer_token");
|
||||
setApiKey(token);
|
||||
} catch (error) {
|
||||
console.error("Error loading API key:", error);
|
||||
toast.error("Failed to load API key");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Add a small delay to simulate loading
|
||||
const timer = setTimeout(loadApiKey, 500)
|
||||
return () => clearTimeout(timer)
|
||||
}, [])
|
||||
// Add a small delay to simulate loading
|
||||
const timer = setTimeout(loadApiKey, 500);
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
|
||||
const copyToClipboard = useCallback(async () => {
|
||||
if (!apiKey) return
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(apiKey)
|
||||
setCopied(true)
|
||||
toast.success('API key copied to clipboard')
|
||||
|
||||
setTimeout(() => {
|
||||
setCopied(false)
|
||||
}, 2000)
|
||||
} catch (err) {
|
||||
console.error('Failed to copy:', err)
|
||||
toast.error('Failed to copy API key')
|
||||
}
|
||||
}, [apiKey])
|
||||
const copyToClipboard = useCallback(async () => {
|
||||
if (!apiKey) return;
|
||||
|
||||
return {
|
||||
apiKey,
|
||||
isLoading,
|
||||
copied,
|
||||
copyToClipboard
|
||||
}
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(apiKey);
|
||||
setCopied(true);
|
||||
toast.success("API key copied to clipboard");
|
||||
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 2000);
|
||||
} catch (err) {
|
||||
console.error("Failed to copy:", err);
|
||||
toast.error("Failed to copy API key");
|
||||
}
|
||||
}, [apiKey]);
|
||||
|
||||
return {
|
||||
apiKey,
|
||||
isLoading,
|
||||
copied,
|
||||
copyToClipboard,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue