1
- import { Link , Outlet , useLocation , useSearchParams } from "@remix-run/react" ;
2
- import { json } from "@remix-run/node" ;
3
- import type { LoaderArgs } from "@remix-run/node" ;
4
- import { DefaultErrorBoundary } from "~/components/DefaultErrorBoundary" ;
5
- import { DefaultCatchBoundary } from "~/components/DefaultCatchBoundary" ;
6
- import { fetchRepoFile } from "~/utils/documents.server" ;
7
- import { useLocalStorage } from "~/utils/useLocalStorage" ;
8
- import { useClientOnlyRender } from "~/utils/useClientOnlyRender" ;
9
- import { repo , getBranch , latestVersion } from "~/routes/query" ;
1
+ import { Link , Outlet , useLocation , useSearchParams } from '@remix-run/react'
2
+ import { json } from '@remix-run/node'
3
+ import type { LoaderArgs } from '@remix-run/node'
4
+ import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary'
5
+ import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
6
+ import { fetchRepoFile } from '~/utils/documents.server'
7
+ import { repo , getBranch , latestVersion } from '~/routes/query'
8
+ import { RedirectVersionBanner } from '~/components/RedirectVersionBanner'
10
9
11
10
export const loader = async ( context : LoaderArgs ) => {
12
- const branch = getBranch ( context . params . version ) ;
13
- const config = await fetchRepoFile ( repo , branch , `docs/config.json` ) ;
11
+ const branch = getBranch ( context . params . version )
12
+ const config = await fetchRepoFile ( repo , branch , `docs/config.json` )
14
13
15
14
if ( ! config ) {
16
- throw new Error ( " Repo docs/config.json not found!" ) ;
15
+ throw new Error ( ' Repo docs/config.json not found!' )
17
16
}
18
17
19
- return json ( JSON . parse ( config ) ) ;
20
- } ;
18
+ return json ( JSON . parse ( config ) )
19
+ }
21
20
22
- export const ErrorBoundary = DefaultErrorBoundary ;
23
- export const CatchBoundary = DefaultCatchBoundary ;
21
+ export const ErrorBoundary = DefaultErrorBoundary
22
+ export const CatchBoundary = DefaultCatchBoundary
24
23
25
24
export default function RouteVersionParam ( ) {
26
- // After user clicks hide, do not show modal for a month, and then remind users that there is a new version!
27
- const [ showModal , setShowModal ] = useLocalStorage (
28
- "showRedirectToLatestModal" ,
29
- true ,
30
- 1000 * 60 * 24 * 30
31
- ) ;
32
- const location = useLocation ( ) ;
33
- const [ params ] = useSearchParams ( ) ;
34
-
35
- const showV3Redirect = params . get ( "from" ) === "reactQueryV3" ;
36
- const original = params . get ( "original" ) ;
25
+ const location = useLocation ( )
26
+ const [ params ] = useSearchParams ( )
37
27
38
- const version = location . pathname . match ( / \/ q u e r y \/ v ( \d ) / ) ?. [ 1 ] || "999" ;
39
- const isLowerVersion = Number ( version ) < Number ( latestVersion [ 1 ] ) ;
40
- const redirectTarget = location . pathname . replace ( `v${ version } ` , "latest" ) ;
28
+ const showV3Redirect = params . get ( 'from' ) === 'reactQueryV3'
29
+ const original = params . get ( 'original' )
41
30
42
- if ( ! useClientOnlyRender ( ) ) {
43
- return null ;
44
- }
31
+ const version = location . pathname . match ( / \/ q u e r y \/ v ( \d ) / ) ?. [ 1 ] || '999'
45
32
46
33
return (
47
34
< >
48
35
{ showV3Redirect ? (
49
36
< div className = "p-4 bg-blue-500 text-white flex items-center justify-center gap-4" >
50
37
< div >
51
- Looking for the{ " " }
38
+ Looking for the{ ' ' }
52
39
< a
53
- href = { original || " /query/latest" }
40
+ href = { original || ' /query/latest' }
54
41
className = "font-bold underline"
55
42
>
56
43
React Query v3 documentation
@@ -66,32 +53,11 @@ export default function RouteVersionParam() {
66
53
</ Link >
67
54
</ div >
68
55
) : null }
69
- { isLowerVersion && showModal ? (
70
- < div className = "p-4 bg-blue-500 text-white flex items-center justify-center gap-4" >
71
- < div >
72
- You are currently reading < strong > v{ version } </ strong > docs. Redirect
73
- to{ " " }
74
- < a href = { redirectTarget } className = "font-bold underline" >
75
- latest
76
- </ a > { " " }
77
- version?
78
- </ div >
79
- < Link
80
- to = { redirectTarget }
81
- replace
82
- className = "bg-white text-black py-1 px-2 rounded-md uppercase font-black text-xs"
83
- >
84
- Latest
85
- </ Link >
86
- < button
87
- onClick = { ( ) => setShowModal ( false ) }
88
- className = "bg-white text-black py-1 px-2 rounded-md uppercase font-black text-xs"
89
- >
90
- Hide
91
- </ button >
92
- </ div >
93
- ) : null }
56
+ < RedirectVersionBanner
57
+ currentVersion = { version }
58
+ latestVersion = { latestVersion }
59
+ />
94
60
< Outlet />
95
61
</ >
96
- ) ;
62
+ )
97
63
}
0 commit comments