Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noah/fix window reference #77

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/news/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function App() {
setNews(fetchedNews);
};
getNews();
}, [news]);
}, []);
return (
<div className="bg-ivory h-full">
<NavBar />
Expand Down
16 changes: 0 additions & 16 deletions src/app/testing/page.tsx

This file was deleted.

10 changes: 6 additions & 4 deletions src/components/userComponents/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,14 @@ export default function Footer() {
const [inputValueEmail, setEmailValue] = useState('');
const [showError, setShowError] = useState(false);
const [errorMsg, setErrorMsg] = useState('');

const subbed = () =>
Boolean(JSON.parse(window.sessionStorage.getItem('subscribed') || 'false'));
const [subscribed, setSubscribed] = useState(subbed);
const [subscribed, setSubscribed] = useState(false);

useEffect(() => {
const subbed = () =>
Boolean(
JSON.parse(window.sessionStorage.getItem('subscribed') || 'false'),
);
setSubscribed(subbed);
window.sessionStorage.setItem('subscribed', subscribed.toString());
}, [subscribed]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ function HomeNewsFeed() {
setNews(topThreeNews);
};
getNews();
}, [news]);
}, []);

return (
<div
className="w-full flex flex-row px-2.5 py-20 web:px-56 web:py-28 gap-40
justify-center items-center justify-start"
justify-center items-center"
>
{isWebDevice && (
<img
Expand Down
10 changes: 7 additions & 3 deletions src/context/WindowWidthContext/WindowWidthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useEffect,
useContext,
useMemo,
useCallback,
} from 'react';

interface WindowWidthContextProps {
Expand All @@ -29,15 +30,18 @@ export function WindowWidthProvider({
}: {
children: React.ReactNode;
}) {
const [isWeb, setIsWeb] = useState(window.innerWidth >= 1024);
const [isWeb, setIsWeb] = useState(false);
const handleResize = useCallback(() => {
setIsWeb(window.innerWidth >= 1024);
}, []);

useEffect(() => {
const handleResize = () => setIsWeb(window.innerWidth >= 1024);
handleResize();
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
}, [handleResize]);

const windowWidthValue = useMemo(() => ({ isWeb }), [isWeb]);

Expand Down
Loading