storing and pulling cookieconsent from localStorage
This commit is contained in:
parent
5acb6ca59b
commit
3cacc87a8f
|
|
@ -4,7 +4,9 @@ import CountriesJSON from "../data/countries/countries.json";
|
||||||
export const UserContext = createContext();
|
export const UserContext = createContext();
|
||||||
|
|
||||||
export function UserContextProvider({ children }) {
|
export function UserContextProvider({ children }) {
|
||||||
const [hasConsentedCookies, setHasConsentedCookies] = useState(false);
|
const [hasConsentedCookies, setHasConsentedCookies] = useState(
|
||||||
|
localStorage.getItem("userCookiesConsent") || false
|
||||||
|
);
|
||||||
|
|
||||||
const localLanguage = localStorage.getItem("userLanguage") || "FR";
|
const localLanguage = localStorage.getItem("userLanguage") || "FR";
|
||||||
const localCountry = JSON.parse(localStorage.getItem("userCountry")) || {
|
const localCountry = JSON.parse(localStorage.getItem("userCountry")) || {
|
||||||
|
|
@ -53,16 +55,21 @@ export function UserContextProvider({ children }) {
|
||||||
setProfile(newProfile);
|
setProfile(newProfile);
|
||||||
localStorage.setItem("userProfile", newProfile);
|
localStorage.setItem("userProfile", newProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function acceptCookies() {
|
||||||
|
setHasConsentedCookies(true);
|
||||||
|
localStorage.setItem("userCookiesConsent", true);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<UserContext.Provider
|
<UserContext.Provider
|
||||||
value={{
|
value={{
|
||||||
language,
|
language,
|
||||||
screensTranslations,
|
screensTranslations,
|
||||||
changeUserLanguage,
|
changeUserLanguage,
|
||||||
// changeLanguage,
|
|
||||||
country,
|
country,
|
||||||
hasConsentedCookies,
|
hasConsentedCookies,
|
||||||
setHasConsentedCookies,
|
setHasConsentedCookies,
|
||||||
|
acceptCookies,
|
||||||
setLanguage,
|
setLanguage,
|
||||||
changeCountry,
|
changeCountry,
|
||||||
profile,
|
profile,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user