11import { config } from '@fortawesome/fontawesome-svg-core' ;
22import Head from 'next/head' ;
3- import React , { useEffect } from 'react' ;
3+ import { useRouter } from 'next/router' ;
4+ import Script from 'next/script' ;
5+ import React , { useEffect , useState } from 'react' ;
46import ReactDOM from 'react-dom' ;
57
68import '@fortawesome/fontawesome-svg-core/styles.css' ;
@@ -9,12 +11,63 @@ import '../styles/App.scss';
911config . autoAddCss = false ; // Tell Font Awesome to skip adding the CSS automatically since it's being imported above
1012
1113export default function App ( { Component, pageProps } ) {
14+ const [ showPopup , setShowPopup ] = useState ( false ) ;
15+ const router = useRouter ( ) ;
16+
1217 useEffect ( ( ) => {
1318 if ( process . env . NODE_ENV !== 'production' ) {
1419 const axe = require ( '@axe-core/react' ) ;
1520 axe ( React , ReactDOM , 1000 ) ;
1621 }
1722 } , [ ] ) ;
23+
24+ useEffect ( ( ) => {
25+ if ( typeof window !== 'undefined' ) {
26+ try {
27+ const hasSeenPopup = localStorage . getItem ( 'mailchimpPopupShown' ) ;
28+
29+ if ( ! hasSeenPopup ) {
30+ setShowPopup ( true ) ;
31+ localStorage . setItem ( 'mailchimpPopupShown' , 'true' ) ;
32+ }
33+ } catch ( error ) {
34+ // eslint-disable-next-line no-console
35+ console . error ( 'LocalStorage access error:' , error ) ;
36+ }
37+ }
38+ } , [ ] ) ;
39+
40+ useEffect ( ( ) => {
41+ const handleRouteChange = ( ) => {
42+ setShowPopup ( false ) ;
43+
44+ const existingScript = document . getElementById ( 'mailchimp-popup' ) ;
45+ if ( existingScript ) {
46+ existingScript . remove ( ) ;
47+ }
48+
49+ document . querySelectorAll (
50+ '.mc-modal, #mc_embed_signup, .modalContent, .bannerContent, #dijit__TemplatedMixin_0, [data-dojo-attach-point="bannerContainer"], [data-dojo-attach-point="modalOpen"], [data-dojo-attach-point="bannerDescriptionContainer"]' ,
51+ ) . forEach ( el => {
52+ el . remove ( ) ;
53+ } ) ;
54+
55+ setTimeout ( ( ) => {
56+ document . querySelectorAll ( '.bannerContent, #dijit__TemplatedMixin_0' ) . forEach ( el => {
57+ el . style . display = 'none' ;
58+ el . style . visibility = 'hidden' ;
59+ el . style . opacity = '0' ;
60+ } ) ;
61+ } , 1000 ) ;
62+
63+ } ;
64+
65+ router . events . on ( 'routeChangeStart' , handleRouteChange ) ;
66+ return ( ) => {
67+ router . events . off ( 'routeChangeStart' , handleRouteChange ) ;
68+ } ;
69+ } , [ router ] ) ;
70+
1871 return (
1972 < >
2073 < Head >
@@ -23,6 +76,14 @@ export default function App({ Component, pageProps }) {
2376 < meta name = "viewport" content = "width=device-width, initial-scale=1" />
2477 < title > ACM at UCLA | Association for Computing Machinery</ title >
2578 </ Head >
79+
80+ { showPopup && (
81+ < Script
82+ id = "mailchimp-popup"
83+ strategy = "afterInteractive"
84+ src = "https://chimpstatic.com/mcjs-connected/js/users/5666284d62e955e1bc84f7ba0/4a4c455ee0b05fb0493dc86b2.js"
85+ />
86+ ) }
2687 < Component { ...pageProps } />
2788 </ >
2889 ) ;
0 commit comments