1- import { useMemo } from "react" ;
1+ import { useMemo , useState , useEffect } from "react" ;
2+ import { usePathname } from "next/navigation" ;
23import { Box , Divider , Tooltip , Typography } from "@mui/material" ;
34import { useSettings } from "../../hooks/use-settings" ;
45import sponsorsData from "../../data/sponsors.json" ;
@@ -38,12 +39,17 @@ const selectRandomSponsor = (sponsors) => {
3839} ;
3940
4041const activeSponsors = getActiveSponsors ( ) ;
41- const selectedSponsor = selectRandomSponsor ( activeSponsors ) ;
4242
4343export const CippSponsor = ( ) => {
44+ const pathname = usePathname ( ) ;
45+ const [ selectedSponsor , setSelectedSponsor ] = useState ( ( ) => selectRandomSponsor ( activeSponsors ) ) ;
4446 const currentSettings = useSettings ( ) ;
4547 const theme = currentSettings ?. currentTheme ?. value ;
4648
49+ useEffect ( ( ) => {
50+ setSelectedSponsor ( selectRandomSponsor ( activeSponsors ) ) ;
51+ } , [ pathname ] ) ;
52+
4753 // Get the appropriate image based on current theme
4854 const randomimg = useMemo ( ( ) => {
4955 if ( ! selectedSponsor ) return null ;
@@ -53,7 +59,7 @@ export const CippSponsor = () => {
5359 altText : selectedSponsor . altText ,
5460 tooltip : selectedSponsor . tooltip ,
5561 } ;
56- } , [ theme ] ) ;
62+ } , [ selectedSponsor , theme ] ) ;
5763
5864 // Don't render if no sponsors are available
5965 if ( ! randomimg ) {
0 commit comments