feat/analytics #9

Merged
GauthierWebDev merged 29 commits from feat/analytics into main 2025-04-18 15:05:51 +00:00
2 changed files with 18 additions and 2 deletions
Showing only changes of commit 542d16227f - Show all commits

View File

@ -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 };
}

View File

@ -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]);