Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
fix: correct duplicate data coming from open-sauced-goals (#1247)
Browse files Browse the repository at this point in the history
closes #1246
  • Loading branch information
0-vortex committed Oct 21, 2021
1 parent 095ff43 commit d825768
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/components/ListGoals.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {Select} from "../styles/Select";
import RepoListItem from "../components/RepoListItem";
import Card from "../components/Card";
import List from "../styles/List";
//import {merge} from "lodash";
//import sortBy from "lodash/sortBy";
import Search from "../styles/Search";
import {EmptyPlaceholder} from "../styles/EmptyPlaceholder";
import {SearchIcon} from "@primer/octicons-react";
Expand All @@ -28,19 +26,27 @@ function merge(goals, additionalData) {
}

function ListGoals({goals, data}) {
const goalsWithData = merge(goals.nodes, data || []);
const goalsWithData = merge(goals.nodes, data || []).map((e) => ({
...e,
full_name_lc: e.full_name.toLowerCase()
}));

const [listGoals, setGoals] = useState(goalsWithData);
const [searchTerm, setSearchTerm] = useState("");
useEffect(() => {
setGoals(merge(goals.nodes, data));
const goalsWithData = merge(goals.nodes, data || []).map((e) => ({
...e,
full_name_lc: e.full_name.toLowerCase()
}));
setGoals(goalsWithData);
}, [goals, data]);
const handleSort = (sortType) => {
switch (sortType) {
case "a_z":
setGoals(sortBy(goalsWithData, "full_name"));
setGoals(sortBy(goalsWithData, "full_name_lc"));
break;
case "z_a":
setGoals(sortBy(goalsWithData, "full_name").reverse());
setGoals(sortBy(goalsWithData, "full_name_lc").reverse());
break;
case "most_stars":
setGoals(sortBy(goalsWithData, "stargazers_count").reverse());
Expand All @@ -54,7 +60,7 @@ function ListGoals({goals, data}) {
};

const filteredSearch = listGoals.filter((goals) =>
goals.full_name.toLowerCase().includes(searchTerm.toLowerCase())
goals.full_name_lc.includes(searchTerm.toLowerCase())
);

return (
Expand Down Expand Up @@ -82,8 +88,8 @@ function ListGoals({goals, data}) {
<Card fitted>
<List>
{goalsWithData &&
filteredSearch.map((goal) => (
<li key={goal.full_name}>
filteredSearch.map(goal => (
<li key={goal.full_name + goal.number}>
<Link
to={{
pathname: `/repos/${goal.full_name.replace(/\s+/g, "")}/${
Expand Down
8 changes: 7 additions & 1 deletion src/components/RepositoryGoals.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ function RepositoryGoals({user}) {
dispatch({type: "UPDATE", payload: updatedRepos});
};

const data = repository && repository.data && repository.data.text && JSON.parse(repository.data.text);
const
keys = ["full_name", "stargazers_count"],
data = repository && repository.data && repository.data.text && JSON.parse(repository.data.text).filter(
(s => o =>
(k => !s.has(k) && s.add(k))(keys.map(k => o[k]).join("|"))
)(new Set())
);
const viewerStars = repository && repository.stars && repository.stars.text && JSON.parse(repository.stars.text);

const stars = remainingStars(data, viewerStars);
Expand Down

0 comments on commit d825768

Please sign in to comment.