From c31fd338eca375952d60d032959d3cba77b9bdee Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 6 Apr 2022 15:14:44 -0300 Subject: [PATCH] Add cache clean on closed. --- .../action-dispatcher/history-dialog/index.tsx | 10 +++++++--- .../maps-page/action-dispatcher/share-dialog/index.tsx | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx index 7d30ed36..dfbd4540 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx @@ -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('history', () => { + const { data } = useQuery(`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(); diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx index 8b903f1f..246bcf70 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx @@ -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): void => { @@ -109,8 +113,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement deleteMutation.mutate(email); }; - const { isLoading, data: permissions = [] } = useQuery( - `perm-${mapId}`, + const { isLoading, data: permissions = [] } = useQuery(`perm-${mapId}`, () => { return client.fetchMapPermissions(mapId); }