mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-13 11:54:57 -05:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useStore } from '@nanostores/react';
|
|
import { toast } from 'features/toast/toast';
|
|
import { useCallback } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useEnableInvocationCacheMutation, useGetInvocationCacheStatusQuery } from 'services/api/endpoints/appInfo';
|
|
import { $isConnected } from 'services/events/stores';
|
|
|
|
export const useEnableInvocationCache = () => {
|
|
const { t } = useTranslation();
|
|
const { data: cacheStatus } = useGetInvocationCacheStatusQuery();
|
|
const isConnected = useStore($isConnected);
|
|
const [_trigger, { isLoading }] = useEnableInvocationCacheMutation({
|
|
fixedCacheKey: 'enableInvocationCache',
|
|
});
|
|
|
|
const trigger = useCallback(async () => {
|
|
try {
|
|
await _trigger().unwrap();
|
|
toast({
|
|
id: 'INVOCATION_CACHE_ENABLE_SUCCEEDED',
|
|
title: t('invocationCache.enableSucceeded'),
|
|
status: 'success',
|
|
});
|
|
} catch {
|
|
toast({
|
|
id: 'INVOCATION_CACHE_ENABLE_FAILED',
|
|
title: t('invocationCache.enableFailed'),
|
|
status: 'error',
|
|
});
|
|
}
|
|
}, [_trigger, t]);
|
|
|
|
return {
|
|
trigger,
|
|
isLoading,
|
|
isDisabled: cacheStatus?.enabled || !isConnected || cacheStatus?.max_size === 0,
|
|
};
|
|
};
|