Skip to content

Commit

Permalink
made tech list item titles dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
theodoremoreland committed Oct 24, 2024
1 parent d729e3a commit f41a916
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 46 deletions.
15 changes: 15 additions & 0 deletions app/src/components/TechList/TechList.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,18 @@ export const getTopicCounts = (repos: TaggedRepoData[]): TopicCounts => {

return topicCounts;
};

export const determineClassName = (
topicLabel: string,
featuredTopics: Set<string>
): "" | "selected" | "filtered-out" => {
if (featuredTopics.size === 0) {
return "";
}

if (featuredTopics.has(findKeyForTopicLabel(topicLabel))) {
return "selected";
}

return "filtered-out";
};
100 changes: 54 additions & 46 deletions app/src/components/TechList/TechList.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<TopicCounts | null>(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]) => (
<li
key={topicLabel}
title={`Click to filter projects by ${topicLabel}`}
className={`${determineClassName(topicLabel)}`}
onClick={() =>
updateFeaturedTopics(
findKeyForTopicLabel(topicLabel)
)
}
>
{findTopicLabelImageSrc(topicLabel) ? (
<>
<div className="tech-icon-container">
<img
src={findTopicLabelImageSrc(topicLabel)}
alt={topicLabel}
className="tech-icon"
/>
</div>
<div className="topic-label-container">
.map(([topicLabel, topicCount]) => {
const className: "" | "selected" | "filtered-out" =
determineClassName(topicLabel, featuredTopics);

return (
<li
key={topicLabel}
title={
className !== "selected"
? `Click to filter projects by ${topicLabel}.`
: `Click to remove ${topicLabel} filter.`
}
className={className}
onClick={() =>
updateFeaturedTopics(
findKeyForTopicLabel(topicLabel)
)
}
>
{findTopicLabelImageSrc(topicLabel) ? (
<>
<div className="tech-icon-container">
<img
src={findTopicLabelImageSrc(
topicLabel
)}
alt={topicLabel}
className="tech-icon"
/>
</div>
<div className="topic-label-container">
{topicLabel}:
<span className="count">
{topicCount}
</span>
</div>
</>
) : (
<>
{" "}
{topicLabel}:
<span className="count">{topicCount}</span>
</div>
</>
) : (
<>
{" "}
{topicLabel}:
<span className="count">{topicCount}</span>
</>
)}
</li>
));
</>
)}
</li>
);
});
},
[updateFeaturedTopics, featuredTopics]
);
Expand Down

0 comments on commit f41a916

Please sign in to comment.