-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented the Contributions by type of contributor graph for …
…the list activity page (#2101)
- Loading branch information
Showing
4 changed files
with
148 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useState } from "react"; | ||
import useSWR, { Fetcher } from "swr"; | ||
|
||
import publicApiFetcher from "lib/utils/public-api-fetcher"; | ||
import { ContributorType } from "components/molecules/MostActiveContributorsCard/most-active-contributors-card"; | ||
import { ContributionEvolutionByTypeDatum } from "components/molecules/ContributionsEvolutionByTypeCard/contributions-evolution-by-type-card"; | ||
|
||
/** | ||
* Fetch most active contributors from a list. | ||
* | ||
*/ | ||
const useContributionsEvolutionByType = ({ | ||
listId, | ||
range = "30", | ||
defaultContributorType = "all", | ||
}: { | ||
listId: string; | ||
range: string; | ||
defaultContributorType?: ContributorType; | ||
}) => { | ||
const [contributorType, setContributorType] = useState<ContributorType>(defaultContributorType); | ||
|
||
const query = new URLSearchParams(); | ||
query.set("contributorType", `${contributorType}`); | ||
query.set("range", range); | ||
|
||
const apiEndpoint = `lists/${listId}/stats/contributions-evolution-by-contributor-type?${query.toString()}`; | ||
|
||
const { data, error, mutate } = useSWR<ContributionEvolutionByTypeDatum[], Error>( | ||
listId ? apiEndpoint : null, | ||
publicApiFetcher as Fetcher<ContributionEvolutionByTypeDatum[], Error> | ||
); | ||
|
||
return { | ||
data, | ||
isLoading: !error && !data, | ||
isError: !!error, | ||
contributorType, | ||
setContributorType, | ||
}; | ||
}; | ||
|
||
export default useContributionsEvolutionByType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.