forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyticsRefreshBar.tsx
More file actions
58 lines (52 loc) 路 1.59 KB
/
Copy pathAnalyticsRefreshBar.tsx
File metadata and controls
58 lines (52 loc) 路 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use client';
import { useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import { analyticsKeys } from '@/lib/analytics-queries';
export default function AnalyticsRefreshBar() {
const queryClient = useQueryClient();
const [isRefreshing, setIsRefreshing] = useState(false);
const [message, setMessage] = useState('Showing cached analytics data when available.');
async function handleRefresh() {
setIsRefreshing(true);
setMessage('Refreshing cached analytics data...');
await queryClient.invalidateQueries({ queryKey: analyticsKeys.root });
setIsRefreshing(false);
setMessage('Data refreshed successfully.');
}
return (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 16,
padding: 16,
marginBottom: 24,
borderRadius: 12,
background: '#e0f2fe',
border: '1px solid #7dd3fc',
}}
>
<div>
<strong style={{ display: 'block', marginBottom: 4 }}>React Query cache enabled</strong>
<span style={{ color: '#0f172a', fontSize: 14 }}>{message}</span>
</div>
<button
type="button"
onClick={handleRefresh}
disabled={isRefreshing}
style={{
border: 0,
borderRadius: 999,
padding: '10px 16px',
background: '#0284c7',
color: '#fff',
fontWeight: 600,
cursor: isRefreshing ? 'wait' : 'pointer',
}}
>
{isRefreshing ? 'Refreshing...' : 'Refresh data'}
</button>
</div>
);
}