From f41a916930979cf777b6f42af1da68b137b161ef Mon Sep 17 00:00:00 2001 From: theodoremoreland Date: Thu, 24 Oct 2024 15:42:27 -0500 Subject: [PATCH] made tech list item titles dynamic --- .../TechList/TechList.controller.ts | 15 +++ app/src/components/TechList/TechList.tsx | 100 ++++++++++-------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/app/src/components/TechList/TechList.controller.ts b/app/src/components/TechList/TechList.controller.ts index 8834ef7..2018df3 100644 --- a/app/src/components/TechList/TechList.controller.ts +++ b/app/src/components/TechList/TechList.controller.ts @@ -168,3 +168,18 @@ export const getTopicCounts = (repos: TaggedRepoData[]): TopicCounts => { return topicCounts; }; + +export const determineClassName = ( + topicLabel: string, + featuredTopics: Set +): "" | "selected" | "filtered-out" => { + if (featuredTopics.size === 0) { + return ""; + } + + if (featuredTopics.has(findKeyForTopicLabel(topicLabel))) { + return "selected"; + } + + return "filtered-out"; +}; diff --git a/app/src/components/TechList/TechList.tsx b/app/src/components/TechList/TechList.tsx index ed15814..e8183ac 100644 --- a/app/src/components/TechList/TechList.tsx +++ b/app/src/components/TechList/TechList.tsx @@ -1,10 +1,17 @@ -import { useCallback, useContext, useEffect, useState } from "react"; +import { + ReactElement, + useCallback, + useContext, + useEffect, + useState, +} from "react"; // Controller import { findKeyForTopicLabel, findTopicLabelImageSrc, getTopicCounts, + determineClassName, } from "./TechList.controller"; // Context @@ -16,64 +23,65 @@ import { TopicCounts } from "../../types"; // Styles import "./TechList.css"; -const TechList = () => { +const TechList = (): ReactElement => { const { repos, updateFeaturedTopics, featuredTopics } = useContext(ProjectsContext); const [topicsCount, setTopicsCount] = useState(null); const generateListItems = useCallback( (topics: { [key: string]: number }) => { - const determineClassName = (topicLabel: string) => { - if (featuredTopics.size === 0) { - return ""; - } - - if (featuredTopics.has(findKeyForTopicLabel(topicLabel))) { - return "selected"; - } - - return "filtered-out"; - }; - return Object.entries(topics) .sort( ([, topicCount1], [, topicCount2]) => topicCount2 - topicCount1 ) - .map(([topicLabel, topicCount]) => ( -
  • - updateFeaturedTopics( - findKeyForTopicLabel(topicLabel) - ) - } - > - {findTopicLabelImageSrc(topicLabel) ? ( - <> -
    - {topicLabel} -
    -
    + .map(([topicLabel, topicCount]) => { + const className: "" | "selected" | "filtered-out" = + determineClassName(topicLabel, featuredTopics); + + return ( +
  • + updateFeaturedTopics( + findKeyForTopicLabel(topicLabel) + ) + } + > + {findTopicLabelImageSrc(topicLabel) ? ( + <> +
    + {topicLabel} +
    +
    + {topicLabel}: + + {topicCount} + +
    + + ) : ( + <> + {" "} {topicLabel}: {topicCount} - - - ) : ( - <> - {" "} - {topicLabel}: - {topicCount} - - )} -
  • - )); + + )} + + ); + }); }, [updateFeaturedTopics, featuredTopics] );