Skip to content

Commit

Permalink
Fix closing and reopening modals (#105)
Browse files Browse the repository at this point in the history
* fix closing and reopening modals

* add var usage
  • Loading branch information
hiba9201 authored Dec 10, 2023
1 parent da867ee commit 22ce123
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/components/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ export function MainPage({ cards, cardsDynamicData, marqueeItems, articles }: Ma

useEffect(() => {
const handlePopState = (e: PopStateEvent) => {
if (e.state.url === '/') {
const slug = e.state.articleSlug;

if (e.state.url === '/' || slug === null) {
setOpenedArticle(null);

return;
}

if (slug) {
const article = articles.find((a) => a.slug === slug);

if (!article) {
return;
}

setOpenedArticle(article);
}
};

Expand Down

0 comments on commit 22ce123

Please sign in to comment.