Skip to content

Commit 234a77e

Browse files
authored
Merge pull request #78 from AzureCosmosDB/ai_first
Fix deep link handling in ShowcaseCard; update URL after dismissing p…
2 parents 8b37071 + 7964f67 commit 234a77e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/components/gallery/ShowcaseCard/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,26 @@ function ShowcaseCard({
8181

8282
// Handle closing panel and removing deep link
8383
const handleDismissPanel = () => {
84-
const searchParams = new URLSearchParams(location.search);
85-
searchParams.delete('card');
86-
history.push({
87-
pathname: location.pathname,
88-
search: searchParams.toString(),
89-
});
84+
// Dismiss panel first to prevent re-render conflicts
9085
dismissPanel();
86+
87+
// Then update URL after a brief delay to ensure state is updated
88+
setTimeout(() => {
89+
const searchParams = new URLSearchParams(location.search);
90+
searchParams.delete('card');
91+
history.push({
92+
pathname: location.pathname,
93+
search: searchParams.toString(),
94+
});
95+
}, 0);
9196
};
9297

9398
// Check if this card should be opened based on URL parameter
9499
useEffect(() => {
95100
const searchParams = new URLSearchParams(location.search);
96101
const cardParam = searchParams.get('card');
102+
103+
// Only open if URL matches this card and panel is not already open
97104
if (cardParam === cardSlug && !isOpen) {
98105
// Track deep link access in Google Analytics
99106
if (typeof window !== 'undefined' && (window as any).gtag) {
@@ -107,8 +114,11 @@ function ShowcaseCard({
107114
});
108115
}
109116
openPanel();
117+
} else if (!cardParam && isOpen) {
118+
// Close if URL param is removed but panel is still open
119+
dismissPanel();
110120
}
111-
}, [location.search, cardSlug, isOpen, openPanel, title, user.author]);
121+
}, [location.search, cardSlug, isOpen, openPanel, dismissPanel, title, user.author]);
112122

113123
const fetchGitHubData = async (owner: string, repo: string) => {
114124
const token = siteConfig.customFields.REACT_APP_GITHUB_TOKEN;

0 commit comments

Comments
 (0)