Files
NapCatQQ/napcat.webui/src/components/hitokoto.tsx
时瑾 06f6a542f5 refactor: 优化eslint配置,提升代码质量 (#1341)
* feat: 统一并标准化eslint

* lint: napcat.webui

* lint: napcat.webui

* lint: napcat.core

* build: fix

* lint: napcat.webui

* refactor: 重构eslint

* Update README.md
2025-11-03 16:30:45 +08:00

79 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Button } from '@heroui/button';
import { Tooltip } from '@heroui/tooltip';
import { useRequest } from 'ahooks';
import toast from 'react-hot-toast';
import { IoCopy, IoRefresh } from 'react-icons/io5';
import { request } from '@/utils/request';
import PageLoading from './page_loading';
export default function Hitokoto () {
const {
data: dataOri,
error,
loading,
run,
} = useRequest(() => request.get<IHitokoto>('https://hitokoto.152710.xyz/'), {
pollingInterval: 10000,
throttleWait: 1000,
});
const data = dataOri?.data;
const onCopy = () => {
try {
const text = `${data?.hitokoto} —— ${data?.from} ${data?.from_who}`;
navigator.clipboard.writeText(text);
toast.success('复制成功');
} catch (_error) {
toast.error('复制失败, 请手动复制');
}
};
return (
<div>
<div className='relative'>
{loading && <PageLoading />}
{error
? (
<div className='text-primary-400'>{error.message}</div>
)
: (
<>
<div>{data?.hitokoto}</div>
<div className='text-right'>
<span className='text-default-400'>{data?.from}</span>{' '}
{data?.from_who}
</div>
</>
)}
</div>
<div className='flex gap-2'>
<Tooltip content='刷新' placement='top'>
<Button
onPress={run}
size='sm'
isLoading={loading}
isIconOnly
radius='full'
color='primary'
variant='flat'
>
<IoRefresh />
</Button>
</Tooltip>
<Tooltip content='复制' placement='top'>
<Button
onPress={onCopy}
size='sm'
isIconOnly
radius='full'
color='success'
variant='flat'
>
<IoCopy />
</Button>
</Tooltip>
</div>
</div>
);
}