generated from mantinedev/next-pages-template
-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add buttons to reset certain cache queries
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Button, Group, MultiSelect, Stack, Title } from '@mantine/core'; | ||
import { useState } from 'react'; | ||
import { notifications } from '@mantine/notifications'; | ||
import { IconTrash } from '@tabler/icons'; | ||
import { queryClient } from '../../../tools/server/configurations/tanstack/queryClient.tool'; | ||
|
||
const data = [ | ||
{ value: 'ping', label: 'Ping queries' }, | ||
{ value: 'repository-icons', label: 'Remote/Local icons' }, | ||
{ value: 'calendar/medias', label: 'Medais from the Calendar' }, | ||
{ value: 'weather', label: 'Weather data' }, | ||
]; | ||
|
||
export function CacheButtons() { | ||
const [value, setValue] = useState<string[]>([]); | ||
return ( | ||
<Stack spacing="xs"> | ||
<Title order={4}>Cache cleaning</Title> | ||
<MultiSelect | ||
value={value} | ||
searchable | ||
onChange={setValue} | ||
data={data} | ||
label="Select the cache(s) to clear" | ||
/> | ||
<Group> | ||
<Button | ||
color="red" | ||
variant="light" | ||
onClick={() => | ||
queryClient.invalidateQueries(value).then(() => | ||
notifications.show({ | ||
title: 'Cache cleared', | ||
message: `Cache for ${value.join(', ')} has been cleared`, | ||
color: 'teal', | ||
icon: <IconTrash />, | ||
autoClose: 5000, | ||
}) | ||
) | ||
} | ||
> | ||
Clear selected queries | ||
</Button> | ||
<Button | ||
onClick={() => | ||
queryClient.invalidateQueries().then(() => | ||
notifications.show({ | ||
title: 'Cache cleared', | ||
message: 'All cache has been cleared', | ||
color: 'teal', | ||
icon: <IconTrash />, | ||
autoClose: 5000, | ||
}) | ||
) | ||
} | ||
> | ||
Clear all cache | ||
</Button> | ||
</Group> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters