* refactor: reorganize settings page with tabbed interface * feat: revamp API key management with new list view and confirmation modals * refactor: update tab styling * refactor: tweak UI/UX for managing API keys * refactor: only show update button when change has been made * refactor: only show update button when content of display name has been updated * feat: store tab state in params * refactor: remove focus state from tabs * refactor: tweak styling on mobile select * refactor: simplify settings pages * feat: open upgrade modal if upgrade=pro is in params * feat: add scroll to api key list on mobile * chore: add translations --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk>
37 lines
975 B
TypeScript
37 lines
975 B
TypeScript
import { useState } from "react";
|
|
|
|
export function useClipboard({ timeout = 500 } = {}) {
|
|
const [error, setError] = useState<string | Error | null | undefined>(null);
|
|
const [copied, setCopied] = useState<boolean>(false);
|
|
const [copyTimeout, setCopyTimeout] = useState<number | undefined>(undefined);
|
|
|
|
const handleCopyResult = (hasError: boolean) => {
|
|
clearTimeout(copyTimeout);
|
|
|
|
setCopyTimeout(
|
|
setTimeout(() => setCopied(false), timeout) as unknown as number,
|
|
);
|
|
|
|
setCopied(hasError);
|
|
};
|
|
|
|
const copy = (value: string) => {
|
|
if ("clipboard" in navigator) {
|
|
navigator.clipboard
|
|
.writeText(value)
|
|
.then(() => handleCopyResult(true))
|
|
.catch((err) => setError(err));
|
|
} else {
|
|
setError(new Error("Error: navigator.clipboard is not supported"));
|
|
}
|
|
};
|
|
|
|
const reset = () => {
|
|
setError(null);
|
|
setCopied(false);
|
|
clearTimeout(copyTimeout);
|
|
};
|
|
|
|
return { copy, reset, error, copied };
|
|
}
|