@c-rex/contexts 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config-provider.tsx +20 -11
package/package.json
CHANGED
package/src/config-provider.tsx
CHANGED
|
@@ -7,28 +7,35 @@ import { getConfigs } from '@c-rex/utils/next-cookies'
|
|
|
7
7
|
import React, { createContext, useContext, useEffect, useState } from 'react'
|
|
8
8
|
|
|
9
9
|
type AppConfigContextType = {
|
|
10
|
-
configs: ConfigInterface
|
|
11
|
-
availableLanguagesAndCountries: LanguageAndCountries[]
|
|
12
|
-
loading: boolean
|
|
13
10
|
error: Error | null
|
|
14
11
|
uiLang: string | null
|
|
12
|
+
configs: ConfigInterface
|
|
13
|
+
loading: boolean
|
|
14
|
+
packageID: string | null
|
|
15
15
|
contentLang: string | null
|
|
16
|
+
articleLang: string | null
|
|
16
17
|
availableVersions: SidebarAvailableVersionsInterface[] | null
|
|
18
|
+
availableLanguagesAndCountries: LanguageAndCountries[]
|
|
17
19
|
setUiLang: (lang: string | null) => void
|
|
18
20
|
setContentLang: (lang: string | null) => void
|
|
19
21
|
setAvailableVersions: (versions: SidebarAvailableVersionsInterface[] | null) => void
|
|
22
|
+
setLoading: (loading: boolean) => void,
|
|
23
|
+
setPackageID: (id: string | null) => void
|
|
24
|
+
setArticleLang: (lang: string | null) => void
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
const AppConfigContext = createContext<AppConfigContextType | undefined>(undefined)
|
|
23
28
|
|
|
24
29
|
export const AppConfigProvider = ({ children }: { children: React.ReactNode }) => {
|
|
30
|
+
const [error, setError] = useState<Error | null>(null)
|
|
31
|
+
const [uiLang, setUiLang] = useState<string | null>(null)
|
|
25
32
|
const [configs, setConfigs] = useState<ConfigInterface | null>(null)
|
|
26
|
-
const [availableLanguagesAndCountries, setAvailableLanguagesAndCountries] = useState<LanguageAndCountries[] | null>(null)
|
|
27
|
-
const [availableVersions, setAvailableVersions] = useState<SidebarAvailableVersionsInterface[] | null>(null)
|
|
28
33
|
const [loading, setLoading] = useState(true)
|
|
29
|
-
const [
|
|
34
|
+
const [packageID, setPackageID] = useState<string | null>(null)
|
|
35
|
+
const [articleLang, setArticleLang] = useState<string | null>(null)
|
|
30
36
|
const [contentLang, setContentLang] = useState<string | null>(null)
|
|
31
|
-
const [
|
|
37
|
+
const [availableVersions, setAvailableVersions] = useState<SidebarAvailableVersionsInterface[] | null>(null)
|
|
38
|
+
const [availableLanguagesAndCountries, setAvailableLanguagesAndCountries] = useState<LanguageAndCountries[] | null>(null)
|
|
32
39
|
|
|
33
40
|
const manageUILanguage = async (configs: ConfigInterface): Promise<void> => {
|
|
34
41
|
let locale = getFromCookieString(document.cookie, UI_LANG_KEY)
|
|
@@ -64,8 +71,6 @@ export const AppConfigProvider = ({ children }: { children: React.ReactNode }) =
|
|
|
64
71
|
try {
|
|
65
72
|
const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);
|
|
66
73
|
|
|
67
|
-
console.log(hasToken)
|
|
68
|
-
|
|
69
74
|
if (hasToken.value === null) {
|
|
70
75
|
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
|
|
71
76
|
method: 'POST',
|
|
@@ -89,7 +94,6 @@ export const AppConfigProvider = ({ children }: { children: React.ReactNode }) =
|
|
|
89
94
|
|
|
90
95
|
useEffect(() => {
|
|
91
96
|
const load = async () => {
|
|
92
|
-
console.log('load')
|
|
93
97
|
try {
|
|
94
98
|
setLoading(true)
|
|
95
99
|
|
|
@@ -131,10 +135,15 @@ export const AppConfigProvider = ({ children }: { children: React.ReactNode }) =
|
|
|
131
135
|
error,
|
|
132
136
|
uiLang,
|
|
133
137
|
contentLang,
|
|
138
|
+
availableVersions,
|
|
139
|
+
packageID,
|
|
140
|
+
articleLang,
|
|
141
|
+
setArticleLang,
|
|
134
142
|
setUiLang,
|
|
135
143
|
setContentLang,
|
|
136
|
-
availableVersions,
|
|
137
144
|
setAvailableVersions,
|
|
145
|
+
setLoading,
|
|
146
|
+
setPackageID
|
|
138
147
|
}}
|
|
139
148
|
>
|
|
140
149
|
{loading ? loadingComp : children}
|