Skip to content

Commit

Permalink
Merge pull request #91 from ibm-client-engineering/Dhanvi-updates
Browse files Browse the repository at this point in the history
Reverted to old change
  • Loading branch information
Sahaj-IBM authored Jul 8, 2024
2 parents da3f310 + 1577cac commit d77cacf
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/app/projects/page.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { Grid, Column, Search, FilterableMultiSelect, Row } from "@carbon/react";
import React, { useState, useEffect } from "react";
import React, { useState } from "react";
import ProjectsTiles from "./ProjectsTiles";

import data from "../../../repoData.json";
Expand All @@ -17,8 +17,13 @@ repoData.forEach((node) => {
});
const topicsArray = Array.from(topics);

// Parse URL parameters outside the component
const urlParams = new URLSearchParams(window.location.search);
const topic = urlParams.get('topic');
const initialSelectedTopics = topic ? [topic] : [];

function ProjectsPage() {
const [selectedTopics, setSelectedTopics] = useState([]);
const [selectedTopics, setSelectedTopics] = useState(initialSelectedTopics);

// Define the renderProjects function
let renderProjects = () => {
Expand All @@ -34,17 +39,13 @@ function ProjectsPage() {
};

//this function calls renderProjects initially to reflect initial selection
useEffect(() => {
if (typeof window !== "undefined") {
const urlParams = new URLSearchParams(window.location.search);
const topic = urlParams.get('topic');
if (topic) {
setSelectedTopics([topic]);
filterProjectsByTag(topic);
}
React.useEffect(() => {
if (topic) {
filterProjectsByTopic(topic);
}
}, []);


let searchProjects = (e) => {
const inputText = e.target.value.toLowerCase();
repoData.forEach((node) => {
Expand Down Expand Up @@ -86,8 +87,8 @@ function ProjectsPage() {
renderProjects();
};

// Define the filterProjectsByTag function
let filterProjectsByTag = (topic) => {
// Define the filterProjectsByTopic function
let filterProjectsByTopic = (topic) => {
repoData.forEach((node) => {
var nodeTopics = node.repositoryTopics.nodes.map((topic) => topic.topic.name);
var inRepo = nodeTopics.includes(topic);
Expand Down

0 comments on commit d77cacf

Please sign in to comment.