react-github-calendar
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -12,2 +12,4 @@ import { FunctionComponent } from 'react'; | ||
transformTotalCount?: boolean; | ||
throwOnError?: boolean; | ||
errorMessage?: string; | ||
} | ||
@@ -14,0 +16,0 @@ |
@@ -66,3 +66,3 @@ 'use client'; | ||
if (!response.ok) { | ||
throw Error(`Unable to fetch GitHub contribution data for ${username}: HTTP ${response.status}}`); | ||
throw Error(`Fetching GitHub contribution data for "${username}" failed: ${data.error}`); | ||
} | ||
@@ -75,4 +75,6 @@ return data; | ||
labels, | ||
transformData: transformDataCallback, | ||
transformData: transformFn, | ||
transformTotalCount = true, | ||
throwOnError = false, | ||
errorMessage = `Error – Fetching GitHub contribution data for "${username}" failed.`, | ||
...props | ||
@@ -82,7 +84,7 @@ }) => { | ||
const [loading, setLoading] = React.useState(false); | ||
const [error, setError] = React.useState(null); | ||
const [fetchError, setFetchError] = React.useState(null); | ||
const fetchData = React.useCallback(() => { | ||
setLoading(true); | ||
setError(null); | ||
fetchCalendarData(username, year).then(setData).catch(setError).finally(() => setLoading(false)); | ||
setFetchError(null); | ||
fetchCalendarData(username, year).then(setData).catch(setFetchError).finally(() => setLoading(false)); | ||
}, [username, year]); | ||
@@ -92,4 +94,8 @@ React.useEffect(fetchData, [fetchData]); | ||
// React error boundaries can't handle asynchronous code, so rethrow. | ||
if (error) { | ||
throw error; | ||
if (fetchError) { | ||
if (throwOnError) { | ||
throw fetchError; | ||
} else { | ||
return /*#__PURE__*/React__default.default.createElement("div", null, errorMessage); | ||
} | ||
} | ||
@@ -107,6 +113,6 @@ if (loading || !data) { | ||
return /*#__PURE__*/React__default.default.createElement(Calendar__default.default, _extends({ | ||
data: transformData(data.contributions, transformDataCallback), | ||
data: transformData(data.contributions, transformFn), | ||
theme: theme, | ||
labels: Object.assign({}, defaultLabels, labels), | ||
totalCount: transformDataCallback && transformTotalCount ? undefined : totalCount | ||
totalCount: transformFn && transformTotalCount ? undefined : totalCount | ||
}, props, { | ||
@@ -113,0 +119,0 @@ maxLevel: 4 |
{ | ||
"name": "react-github-calendar", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": " A flexible React component to display a GitHub contributions graph", | ||
@@ -5,0 +5,0 @@ "author": "Jonathan Gruber <gruberjonathan@gmail.com>", |
Sorry, the diff of this file is not supported yet
17308
122