Add cache clean on closed.

This commit is contained in:
Paulo Gustavo Veiga 2022-04-06 15:14:44 -03:00
parent 31dc83d30b
commit c31fd338ec
2 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import React, { ErrorInfo } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import { useQuery } from 'react-query';
import { useQuery, useQueryClient } from 'react-query';
import { useSelector } from 'react-redux';
import Client, { ChangeHistory } from '../../../../classes/client';
import { activeInstance } from '../../../../redux/clientSlice';
@ -22,16 +22,20 @@ const HistoryDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElemen
const intl = useIntl();
const client: Client = useSelector(activeInstance);
const { data } = useQuery<unknown, ErrorInfo, ChangeHistory[]>('history', () => {
const { data } = useQuery<unknown, ErrorInfo, ChangeHistory[]>(`history-${mapId}`, () => {
return client.fetchHistory(mapId);
});
const changeHistory: ChangeHistory[] = data ? data : [];
const handleOnClose = (): void => {
onClose();
// Invalidate cache ...
const queryClient = useQueryClient();
queryClient.invalidateQueries(`history-${mapId}`);
};
const handleOnClick = (event, vid): void => {
const handleOnClick = (event, vid: number): void => {
event.preventDefault();
client.revertHistory(mapId, vid).then(() => {
handleOnClose();

View File

@ -84,6 +84,10 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
const handleOnClose = (): void => {
onClose();
// Invalidate cache ...
const queryClient = useQueryClient();
queryClient.invalidateQueries(`perm-${mapId}`);
};
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
@ -109,8 +113,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
deleteMutation.mutate(email);
};
const { isLoading, data: permissions = [] } = useQuery<unknown, ErrorInfo, Permission[]>(
`perm-${mapId}`,
const { isLoading, data: permissions = [] } = useQuery<unknown, ErrorInfo, Permission[]>(`perm-${mapId}`,
() => {
return client.fetchMapPermissions(mapId);
}