Query: disable delete button when pending

This commit is contained in:
vchikalkin 2024-04-10 15:55:40 +03:00
parent d8679958c6
commit 830723fafe
2 changed files with 17 additions and 10 deletions

View File

@ -7,7 +7,7 @@ import { Button, Collapse } from 'ui/elements';
import { Flex } from 'ui/grid';
type QueryProps = {
readonly handleDeleteQuery: () => void;
readonly handleDeleteQuery: () => Promise<void>;
readonly queryKey: string;
};
@ -29,12 +29,23 @@ export const Query = memo(({ handleDeleteQuery, queryKey }: QueryProps) => {
});
const [activeKey, setActiveKey] = useState<string | undefined>(undefined);
const [deletePending, setDeletePending] = useState(false);
const content = (
<>
<StyledPre>{JSON.stringify(data, null, 2)}</StyledPre>
<Flex justifyContent="flex-end">
<Button type="primary" danger onClick={handleDeleteQuery}>
<Button
type="primary"
danger
disabled={deletePending}
onClick={() => {
setDeletePending(true);
handleDeleteQuery().finally(() => {
setDeletePending(false);
});
}}
>
Удалить
</Button>
</Flex>

View File

@ -14,16 +14,12 @@ export const QueryList = memo(({ queries }: QueryListProps) => {
);
function deleteQuery(queryKey: string) {
cacheApi.deleteQuery(queryKey).then(() => setDeletedQueries([...deletedQueries, queryKey]));
return cacheApi
.deleteQuery(queryKey)
.then(() => setDeletedQueries([...deletedQueries, queryKey]));
}
return activeQueries.map((queryKey) => (
<Query
key={queryKey}
queryKey={queryKey}
handleDeleteQuery={() => {
deleteQuery(queryKey);
}}
/>
<Query key={queryKey} queryKey={queryKey} handleDeleteQuery={() => deleteQuery(queryKey)} />
));
});