({ children }: { children: React.ReactNode })
| 30 | }; |
| 31 | |
| 32 | export function KonamiProvider({ children }: { children: React.ReactNode }) { |
| 33 | const content = useRef<Map<Text, string>>(new Map()); |
| 34 | const { setUser } = useAppMode(); |
| 35 | const router = useRouter(); |
| 36 | const routerRef = useRef(router); |
| 37 | |
| 38 | useEffect(() => { |
| 39 | routerRef.current = router; |
| 40 | }, [router]); |
| 41 | |
| 42 | const handleSpecialTranslation = useCallback( |
| 43 | (translation: string) => { |
| 44 | updateUserSettings({ preferredLocale: translation }).then((result) => { |
| 45 | if (result.success && result.data?.user) { |
| 46 | setUser(result.data.user); |
| 47 | routerRef.current.refresh(); |
| 48 | } |
| 49 | }); |
| 50 | }, |
| 51 | [setUser] |
| 52 | ); |
| 53 | |
| 54 | const { isChaos, toggleChaos, activeGif, clearGif } = useEasterEggs({ |
| 55 | onSpecialTranslation: handleSpecialTranslation, |
| 56 | }); |
| 57 | |
| 58 | const apply = useCallback( |
| 59 | () => startChaos(getTextNodes(document.body), content.current), |
| 60 | [] |
| 61 | ); |
| 62 | |
| 63 | const reset = useCallback(() => { |
| 64 | resetChaos(content.current); |
| 65 | }, []); |
| 66 | |
| 67 | useEffect(() => { |
| 68 | if (!isChaos) return reset(); |
| 69 | apply(); |
| 70 | }, [isChaos, apply, reset]); |
| 71 | |
| 72 | return ( |
| 73 | <ChaosContext.Provider value={{ isChaos, toggleChaos }}> |
| 74 | {children} |
| 75 | <ImageOverlay src={activeGif} onClose={clearGif} alt="Easter egg" /> |
| 76 | </ChaosContext.Provider> |
| 77 | ); |
| 78 | } |
nothing calls this directly
no test coverage detected