feat: 服务状态增加刷新按钮

并优化Loading态样式,增加过渡动画
pull/49/head
moonrailgun 3 years ago
parent 344b109aac
commit 32e7dbedf9

@ -15,12 +15,34 @@ export function buildCachedRequest<R, F extends (...args: any) => Promise<R>>(
name: string, name: string,
fn: F, fn: F,
options?: FetchQueryOptions options?: FetchQueryOptions
): F { ): F & {
return ((...args: any) => { /**
* name
*/
refetch: () => Promise<void>;
/**
* name
*/
clearCache: () => void;
} {
const req = ((...args: any) => {
return queryClient.fetchQuery( return queryClient.fetchQuery(
[name, JSON.stringify(args)], [name, JSON.stringify(args)],
() => fn(...args), () => fn(...args),
options options
); );
}) as any; }) as any;
const refetch = () => {
return queryClient.refetchQueries([name]);
};
const clearCache = () => {
queryClient.removeQueries([name]);
};
req.refetch = refetch;
req.clearCache = clearCache;
return req;
} }

@ -1,13 +1,24 @@
import { useEffect } from 'react';
import { fetchAvailableServices } from '../../model/common'; import { fetchAvailableServices } from '../../model/common';
import { useAsync } from '../useAsync'; import { useAsyncFn } from '../useAsyncFn';
import { useMemoizedFn } from '../useMemoizedFn';
/** /**
* hooks * hooks
*/ */
export function useAvailableServices() { export function useAvailableServices() {
const { loading, value: availableServices } = useAsync(() => const [{ loading, value: availableServices }, fetch] = useAsyncFn(() =>
fetchAvailableServices() fetchAvailableServices()
); );
return { loading, availableServices }; useEffect(() => {
fetch();
}, []);
const refetch = useMemoizedFn(async () => {
fetchAvailableServices.clearCache();
fetch();
});
return { loading, availableServices, refetch };
} }

@ -209,6 +209,7 @@
"kb55c8dba": "Invite Member", "kb55c8dba": "Invite Member",
"kb5a17e73": "Leave group", "kb5a17e73": "Leave group",
"kb6f1c83f": "What do you want to call you?", "kb6f1c83f": "What do you want to call you?",
"kb76d94e0": "Refresh",
"kb7a57f24": "Plugin Registry Service", "kb7a57f24": "Plugin Registry Service",
"kb8185132": "Or", "kb8185132": "Or",
"kb96b79c5": "Allow management of invitation links", "kb96b79c5": "Allow management of invitation links",

@ -209,6 +209,7 @@
"kb55c8dba": "邀请成员", "kb55c8dba": "邀请成员",
"kb5a17e73": "退出群组", "kb5a17e73": "退出群组",
"kb6f1c83f": "想要让大家如何称呼你", "kb6f1c83f": "想要让大家如何称呼你",
"kb76d94e0": "刷新",
"kb7a57f24": "插件中心服务", "kb7a57f24": "插件中心服务",
"kb8185132": "或", "kb8185132": "或",
"kb96b79c5": "允许管理邀请链接", "kb96b79c5": "允许管理邀请链接",

@ -12,11 +12,17 @@ export const Loading: React.FC<LoadingProps> = React.memo((props) => {
return ( return (
<div className={clsx('relative', className)} style={style}> <div className={clsx('relative', className)} style={style}>
{spinning && ( <div
<div className="absolute inset-0 z-10 bg-white bg-opacity-20 flex justify-center items-center"> className={clsx(
<LoadingSpinner /> 'absolute inset-0 z-10 bg-white bg-opacity-20 flex justify-center items-center transition-opacity duration-100',
</div> {
)} 'opacity-0 pointer-events-none': !spinning,
'opacity-100': spinning,
}
)}
>
<LoadingSpinner />
</div>
{props.children} {props.children}
</div> </div>

@ -1,8 +1,9 @@
import { LoadingSpinner } from '@/components/LoadingSpinner';
import { pluginInspectServices } from '@/plugin/common'; import { pluginInspectServices } from '@/plugin/common';
import { Icon } from '@/components/Icon'; import { Icon } from 'tailchat-design';
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { t, useAvailableServices } from 'tailchat-shared'; import { t, useAvailableServices } from 'tailchat-shared';
import { Button } from 'antd';
import { Loading } from '@/components/Loading';
/** /**
* *
@ -71,28 +72,34 @@ export const SettingsStatus: React.FC = React.memo(() => {
[] []
); // 需要检查服务状态的列表 ); // 需要检查服务状态的列表
const { loading, availableServices } = useAvailableServices(); const { loading, availableServices, refetch } = useAvailableServices();
if (loading) {
return <LoadingSpinner />;
}
return ( return (
<div> <div>
{inspectServices.map((service) => ( <Button
<div key={service.name} className="flex items-center"> className="mb-2"
<span className="mr-1">{service.label}:</span> type="primary"
{availableServices?.includes(service.name) ? ( loading={loading}
<span title={t('当前服务可用')}> onClick={refetch}
<Icon icon="emojione:white-heavy-check-mark" /> >
</span> {t('刷新')}
) : ( </Button>
<span title={t('服务异常')}> <Loading spinning={loading}>
<Icon icon="emojione:cross-mark-button" /> {inspectServices.map((service) => (
</span> <div key={service.name} className="flex items-center">
)} <span className="mr-1">{service.label}:</span>
</div> {availableServices?.includes(service.name) ? (
))} <span title={t('当前服务可用')}>
<Icon icon="emojione:white-heavy-check-mark" />
</span>
) : (
<span title={t('服务异常')}>
<Icon icon="emojione:cross-mark-button" />
</span>
)}
</div>
))}
</Loading>
</div> </div>
); );
}); });

Loading…
Cancel
Save