Skip to content

Commit

Permalink
Merge branch 'hotfix/build-page-query-parameter-link' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gabros20 committed Aug 7, 2024
2 parents 4afe6c2 + 8a0f353 commit b1a09f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules/
package-lock.json
.idea/
.env.development
.env.production
.env.production
.vercel
27 changes: 19 additions & 8 deletions src/components/framework-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@ import queryString from "query-string";
const FrameworkTabs = ({ content, categories, anchorId, section }) => {
const [selectedTab, setSelectedTab] = useState("All");

const allUniqueCategories = [...new Set(categories.items.flatMap((item) => item.category))];

useEffect(() => {
const params = queryString.parse(window.location.search);
const categoryParam = params[`${section.toLowerCase()}_category`] || params.framework_category;
if (categoryParam && allUniqueCategories.includes(categoryParam)) {
setSelectedTab(categoryParam);
// Function to get URL parameters
const getUrlParameter = (name) => {
if (typeof window !== "undefined") {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(window.location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
return "";
};

// Set the selected tab based on URL parameter
const paramName = section.toLowerCase() + "_category";
const categoryFromUrl = getUrlParameter(paramName);
if (categoryFromUrl && categories.items.some((item) => item.category.includes(categoryFromUrl))) {
setSelectedTab(categoryFromUrl);
}
}, [section, allUniqueCategories]);
}, [section, categories.items]);

console.log(allUniqueCategories);
const allUniqueCategories = ["All", ...new Set(categories.items.flatMap((item) => item.category))];

return (
<section className='frameworks' id={`${content.items[anchorId].title.replace(/\s+/g, "-").toLowerCase()}`}>
Expand All @@ -29,6 +39,7 @@ const FrameworkTabs = ({ content, categories, anchorId, section }) => {
{allUniqueCategories.map(function (category) {
return (
<div
key={category}
className={`col-auto tab-item ${selectedTab === category && "active"} plausible-event-name=${category.replace(
/\s+/g,
"-"
Expand Down

0 comments on commit b1a09f9

Please sign in to comment.