forked from TanStack/tanstack.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedirectVersionBanner.tsx
More file actions
64 lines (58 loc) · 2.1 KB
/
RedirectVersionBanner.tsx
File metadata and controls
64 lines (58 loc) · 2.1 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
59
60
61
62
63
64
import { useLocalStorage } from '~/utils/useLocalStorage'
import { useClientOnlyRender } from '~/utils/useClientOnlyRender'
import { Link, useMatches } from '@tanstack/react-router'
export function RedirectVersionBanner(props: {
version: string
latestVersion: string
}) {
const { version, latestVersion } = props
const matches = useMatches()
const activeMatch = matches[matches.length - 1]
// After user clicks hide, do not show modal for a month, and then remind users that there is a new version!
const [showModal, setShowModal] = useLocalStorage(
'showRedirectToLatestModal',
true,
1000 * 60 * 24 * 30
)
if (!useClientOnlyRender()) {
return null
}
if (![latestVersion, 'latest'].includes(version) && showModal) {
return (
<div className="p-4 bg-white/70 text-black dark:bg-gray-500/40 dark:text-white shadow-xl shadow-black/20 flex items-center justify-center gap-2.5 lg:gap-4 fixed top-4 left-1/2 bottom-auto backdrop-blur-sm z-20 -translate-x-1/2 rounded-3xl lg:rounded-full overflow-hidden w-[80%] lg:w-auto">
<p className="block">
You are currently reading <strong>{version}</strong> docs. Redirect to{' '}
<Link
to={activeMatch.fullPath}
params={{
version: 'latest',
}}
className="font-bold underline"
>
latest
</Link>{' '}
version?
</p>
<div className="flex gap-2 flex-col lg:flex-row items-center">
<Link
to={activeMatch.fullPath}
params={{
version: 'latest',
}}
replace
className="bg-black dark:bg-white dark:text-black text-white w-full lg:w-auto py-1 px-2 rounded-md uppercase font-black text-xs"
>
Latest
</Link>
<button
onClick={() => setShowModal(false)}
className="bg-black dark:bg-white dark:text-black text-white w-full lg:w-auto py-1 px-2 rounded-md uppercase font-black text-xs"
>
Hide
</button>
</div>
</div>
)
}
return null
}