diff --git a/components/molecules/SelectableTable/selectable-table.tsx b/components/molecules/SelectableTable/repository-table.tsx similarity index 93% rename from components/molecules/SelectableTable/selectable-table.tsx rename to components/molecules/SelectableTable/repository-table.tsx index 108c4f4764..02485b0b7a 100644 --- a/components/molecules/SelectableTable/selectable-table.tsx +++ b/components/molecules/SelectableTable/repository-table.tsx @@ -12,7 +12,7 @@ import humanizeNumber from "../../../lib/utils/humanizeNumber"; interface RepoSelectableTableProps { title: string; tableType: "participants"; - rows: { title: string; stars: number; forks: number; persons: number }[]; + rows: { name: string; stars: number; forks: number; persons: number, size: string }[]; } const iconSuite = { @@ -79,7 +79,7 @@ const RepoSelectableTable: React.FC = ({ title, tableT - {rows?.map(({ title, stars, persons }, index) => { + {rows?.map(({ name, stars, persons, size }, index) => { return ( = ({ title, tableT }} > addCheckboxToRef(element)}> - {divSize > 0 && divSize < 350 ? truncateString(title, 3) : title} + {divSize > 0 && divSize < 350 ? truncateString(name, 3) : name} {humanizeNumber(stars)} {humanizeNumber(12)} {humanizeNumber(1234)} - {persons} + {humanizeNumber(parseInt(size))} ); })} diff --git a/components/organisms/Repositories/repositories.tsx b/components/organisms/Repositories/repositories.tsx index 3cbeb73de2..e6e84c6ef2 100644 --- a/components/organisms/Repositories/repositories.tsx +++ b/components/organisms/Repositories/repositories.tsx @@ -1,13 +1,15 @@ import Card from "../../atoms/Card/card"; -import SelectableTable from "components/molecules/SelectableTable/selectable-table"; -import useRepositoriesList from "lib/hooks/useRepositoriesList"; +import SelectableTable from "components/molecules/SelectableTable/repository-table"; +import {useRepositoriesList} from "lib/hooks/useRepositoriesList"; const Reports = (): JSX.Element => { - const { repositoriesList } = useRepositoriesList(); + const { repoList, isLoading } = useRepositoriesList(); + const data = repoList.data || {data: []}; + return (
- + {isLoading ? <>...Loading : }
); diff --git a/components/organisms/ToolList/nav.tsx b/components/organisms/ToolList/nav.tsx index 9a857986ee..e0c033fde1 100644 --- a/components/organisms/ToolList/nav.tsx +++ b/components/organisms/ToolList/nav.tsx @@ -1,5 +1,6 @@ import React from "react"; import Link from "next/link"; +import humanizeNumber from "../../../lib/utils/humanizeNumber"; type toolListArray = { name: string; @@ -40,7 +41,7 @@ const Nav: React.FC = ({ toolList, selectedTool = "dashboard", selecte { tool.numOf &&
- {tool.numOf} + {humanizeNumber(tool.numOf)}
} diff --git a/lib/hooks/useNav.ts b/lib/hooks/useNav.ts index 8ee99dbc34..a88428a4ab 100644 --- a/lib/hooks/useNav.ts +++ b/lib/hooks/useNav.ts @@ -1,7 +1,11 @@ import { useRouter } from "next/router"; +import {useRepositoriesList} from "lib/hooks/useRepositoriesList"; +import humanizeNumber from "../utils/humanizeNumber"; const useNav = () => { const router = useRouter(); + const { repoList, isLoading } = useRepositoriesList(); + const meta = repoList.meta || {}; const defaultTools = [ { @@ -15,7 +19,7 @@ const useNav = () => { }, { name: "Repositories", - numOf: 20 + numOf: meta.itemCount }, { name: "Contributors", @@ -35,4 +39,4 @@ const useNav = () => { }; }; -export default useNav; \ No newline at end of file +export default useNav; diff --git a/lib/hooks/useRepoList.ts b/lib/hooks/useRepoList.ts deleted file mode 100644 index 7a56067d5c..0000000000 --- a/lib/hooks/useRepoList.ts +++ /dev/null @@ -1,14 +0,0 @@ -import useSWR from "swr"; - -const useRepoList = () => { - const { data, error, mutate } = useSWR("repos/list"); - - return { - repoList: data || {data: []}, - isLoading: !error && !data, - isError: !!error, - mutate - }; -}; - -export {useRepoList}; diff --git a/lib/hooks/useRepositoriesList.ts b/lib/hooks/useRepositoriesList.ts index ff7cbe9cfb..b083bef178 100644 --- a/lib/hooks/useRepositoriesList.ts +++ b/lib/hooks/useRepositoriesList.ts @@ -1,201 +1,14 @@ +import useSWR from "swr"; + const useRepositoriesList = () => { - const repositoriesList = [ - { - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - }, - { - title: "react", - stars: 100, - forks: 20, - persons: 30, - unknown: 10 - }, - { - title: "java-design-patterns", - stars: 20, - forks: 14, - persons: 10, - unknown: 0 - },{ - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - }, - { - title: "react", - stars: 100, - forks: 20, - persons: 30, - unknown: 10 - }, - { - title: "java-design-patterns", - stars: 20, - forks: 14, - persons: 10, - unknown: 0 - },{ - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - }, - { - title: "react", - stars: 100, - forks: 20, - persons: 30, - unknown: 10 - }, - { - title: "java-design-patterns", - stars: 20, - forks: 14, - persons: 10, - unknown: 0 - },{ - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - }, - { - title: "react", - stars: 100, - forks: 20, - persons: 30, - unknown: 10 - }, - { - title: "java-design-patterns", - stars: 20, - forks: 14, - persons: 10, - unknown: 0 - },{ - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - }, - { - title: "react", - stars: 100, - forks: 20, - persons: 30, - unknown: 10 - }, - { - title: "java-design-patterns", - stars: 20, - forks: 14, - persons: 10, - unknown: 0 - },{ - title: "freecodecamp", - stars: 100, - forks: 20, - persons: 40, - unknown: 5 - }, - { - title: "free-programming-books", - stars: 60, - forks: 10, - persons: 20, - unknown: 5 - }, - { - title: "material-ui", - stars: 20, - forks: 30, - persons: 10, - unknown: 2 - } - ]; + const { data, error, mutate } = useSWR("repos/list"); return { - repositoriesList + repoList: data || {data: []}, + isLoading: !error && !data, + isError: !!error, + mutate }; }; -export default useRepositoriesList; \ No newline at end of file +export {useRepositoriesList}; diff --git a/stories/molecules/selectable-table.stories.tsx b/stories/molecules/selectable-table.stories.tsx index c108a0b025..6b6ccd7b92 100644 --- a/stories/molecules/selectable-table.stories.tsx +++ b/stories/molecules/selectable-table.stories.tsx @@ -1,6 +1,6 @@ import React from "react"; import { ComponentStory, ComponentMeta } from "@storybook/react"; -import SelectableTable from "../../components/molecules/SelectableTable/selectable-table"; +import SelectableTable from "../../components/molecules/SelectableTable/repository-table"; const storyConfig = { title: "Design System/Molecules/Selectable Table", @@ -11,34 +11,39 @@ export default storyConfig; const testRows = [ { - title: "freecodecamp", + name: "freecodecamp", stars: 100, forks: 20, - persons: 5 + persons: 5, + size: "30984" }, { - title: "free-programming-books", + name: "free-programming-books", stars: 60, forks: 10, - persons: 5 + persons: 5, + size: "30984" }, { - title: "material-ui", + name: "material-ui", stars: 20, forks: 30, - persons: 2 + persons: 2, + size: "30984" }, { - title: "react", + name: "react", stars: 100, forks: 20, - persons: 10 + persons: 10, + size: "30984" }, { - title: "java-design-patterns", + name: "java-design-patterns", stars: 20, forks: 14, - persons: 0 + persons: 0, + size: "30984" } ]; diff --git a/stories/organisms/tool-nav.stories.tsx b/stories/organisms/tool-nav.stories.tsx index 29cd12b9f0..800b1ae570 100644 --- a/stories/organisms/tool-nav.stories.tsx +++ b/stories/organisms/tool-nav.stories.tsx @@ -24,4 +24,4 @@ const ToolNavTemplate: ComponentStory = (args) =>