storing and pulling cookieconsent from localStorage

This commit is contained in:
Antoine M 2024-05-14 17:02:59 +02:00
parent 5acb6ca59b
commit 3cacc87a8f

View File

@ -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,