feat/analytics #9
@ -0,0 +1,13 @@
|
|||||||
|
import type { Theme } from "@/contexts/ThemeContext";
|
||||||
|
|
||||||
|
import { getTelefuncContext } from "@/lib/getTelefuncContext";
|
||||||
|
import { CookieParser } from "@/services/CookieParser";
|
||||||
|
|
||||||
|
export async function onUpdateThemeCookie(value: Theme) {
|
||||||
|
const context = getTelefuncContext();
|
||||||
|
const { reply } = context;
|
||||||
|
|
||||||
|
CookieParser.set(reply, "theme", value, 365);
|
||||||
|
|
||||||
|
return { ok: true, message: "Updated theme cookie", value };
|
||||||
|
}
|
||||||
@ -1,6 +1,8 @@
|
|||||||
|
import { onUpdateThemeCookie } from "@/providers/ThemeProvider.telefunc";
|
||||||
import { ThemeContext, type Theme } from "@/contexts/ThemeContext";
|
import { ThemeContext, type Theme } from "@/contexts/ThemeContext";
|
||||||
import { usePageContext } from "vike-react/usePageContext";
|
import { usePageContext } from "vike-react/usePageContext";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
type ThemeProviderProps = {
|
type ThemeProviderProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -18,8 +20,9 @@ export function ThemeProvider(props: ThemeProviderProps) {
|
|||||||
rootElement.classList.toggle("light", theme === "light");
|
rootElement.classList.toggle("light", theme === "light");
|
||||||
|
|
||||||
if (cookies.consent.customization) {
|
if (cookies.consent.customization) {
|
||||||
console.log(`ThemeProvider: ${theme}`);
|
onUpdateThemeCookie(theme).catch(() => {
|
||||||
// TODO: update the theme in the cookies
|
toast.error("Erreur lors de la mise à jour du cookie de thème");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user