@@ -15,32 +15,14 @@ const PLATFORM_VERSIONS = publicRuntimeConfig.PLATFORM_VERSIONS;
15
15
const PLATFORM_LATEST_VERSIONS = publicRuntimeConfig . PLATFORM_LATEST_VERSIONS ;
16
16
const PLATFORMS = publicRuntimeConfig . PLATFORMS ;
17
17
18
- export function VersionContextProvider ( { children } ) {
19
- const [ initialized , setInitialized ] = useState ( false ) ;
20
-
21
- const [ version , setVersionState ] = useState ( DEFAULT_VERSION ) ;
22
- const [ platform , setPlatformState ] = useState ( DEFAULT_PLATFORM ) ;
23
- // const [isOpen, setIsOpen] = useState(false);
24
- const router = useRouter ( ) ;
25
-
26
- const initialize = useCallback (
27
- ( { newVersion, newPlatform, functionName = null , currMenuItem = null } ) => {
28
- if ( initialized ) return [ version , platform ] ;
29
-
30
- setVersionAndPlatform ( {
31
- newVersion,
32
- newPlatform,
33
- functionName,
34
- currMenuItem,
35
- updateURL : true ,
36
- } ) ;
37
-
38
- setInitialized ( true ) ;
39
-
40
- return [ newVersion , newPlatform ] ;
41
- } ,
42
- [ initialized , version , platform ] ,
18
+ export function VersionContextProvider ( props ) {
19
+ const [ platform , setPlatformState ] = useState ( ( ) =>
20
+ getCleanedPlatform ( props . platformFromStaticLoad ) ,
21
+ ) ;
22
+ const [ version , setVersionState ] = useState ( ( ) =>
23
+ getCleanedVersion ( props . versionFromStaticLoad , platform ) ,
43
24
) ;
25
+ const router = useRouter ( ) ;
44
26
45
27
const setVersionAndPlatform = useCallback (
46
28
( {
@@ -63,12 +45,10 @@ export function VersionContextProvider({ children }) {
63
45
return ;
64
46
}
65
47
66
- const cleanedVersion = isLatestVersion ( newVersion , newPlatform )
67
- ? DEFAULT_VERSION
68
- : newVersion ;
69
- setVersionState ( cleanedVersion ) ;
48
+ const cleanedVersion = getCleanedVersion ( newVersion , newPlatform ) ;
49
+ const cleanedPlatform = getCleanedPlatform ( newPlatform ) ;
70
50
71
- const cleanedPlatform = newPlatform ?? DEFAULT_PLATFORM ;
51
+ setVersionState ( cleanedVersion ) ;
72
52
setPlatformState ( cleanedPlatform ) ;
73
53
74
54
if ( updateURL ) {
@@ -96,15 +76,14 @@ export function VersionContextProvider({ children }) {
96
76
value = { {
97
77
version,
98
78
platform,
99
- initialize,
100
79
setVersionAndPlatform,
101
80
goToLatest,
102
81
goToOpenSource,
103
82
// isOpen,
104
83
// setIsOpen
105
84
} }
106
85
>
107
- { children }
86
+ { props . children }
108
87
</ Context . Provider >
109
88
) ;
110
89
}
@@ -219,8 +198,8 @@ export function getVersionAndPlatformFromPathPart(pathPart) {
219
198
export function versionAndPlatformAreCompatible ( version , platform ) {
220
199
if ( version == DEFAULT_VERSION ) return true ;
221
200
222
- if ( platform == DEFAULT_PLATFORM && VERSIONS_LIST . indexOf ( version ) >= 0 ) {
223
- return true ;
201
+ if ( platform == DEFAULT_PLATFORM ) {
202
+ return VERSIONS_LIST . indexOf ( version ) >= 0 ;
224
203
}
225
204
226
205
return PLATFORM_VERSIONS [ platform ] . indexOf ( version ) >= 0 ;
@@ -252,3 +231,11 @@ export function getBestNumericVersion(version, platform) {
252
231
}
253
232
}
254
233
}
234
+
235
+ function getCleanedVersion ( version , platform ) {
236
+ return isLatestVersion ( version , platform ) ? DEFAULT_VERSION : version ;
237
+ }
238
+
239
+ function getCleanedPlatform ( platform ) {
240
+ return platform ?? DEFAULT_PLATFORM ;
241
+ }
0 commit comments