-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add total games stats and error handling (#224)
- Loading branch information
1 parent
fb6f6ac
commit 04f3f28
Showing
11 changed files
with
268 additions
and
84 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
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,66 @@ | ||
import React from "react"; | ||
import { AlertBox } from "./alert-box"; | ||
import { Row, Typography } from "antd"; | ||
import config from "../config"; | ||
const { Text } = Typography; | ||
|
||
class ErrorBoundary extends React.Component { | ||
constructor(props: any) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
static getDerivedStateFromError(error: any) { | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: any, errorInfo: any) { | ||
// You can also log the error to an error reporting service | ||
// logErrorToMyService(error, errorInfo); | ||
} | ||
|
||
render() { | ||
// @ts-ignore | ||
if (this.state.hasError) { | ||
// You can render any custom fallback UI | ||
return ( | ||
<Row justify="center" style={{ paddingTop: "10px" }}> | ||
<AlertBox | ||
type={"error"} | ||
message={"There was an error rendering the component."} | ||
description={ | ||
<div> | ||
Please refresh the app (press F5). If the problem persists after refreshing the | ||
page please report it together with <Text strong>screenshot, url</Text> and | ||
preferably copy all the error text which is in the Console of browser developer | ||
tools ( | ||
<a | ||
href={"https://updraftplus.com/faqs/how-do-i-open-my-browsers-developer-tools/"} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{" "} | ||
how to open dev tools | ||
</a> | ||
) in our Discord{" "} | ||
<a href={config.discordInviteLink} target="_blank" rel="noopener noreferrer"> | ||
<img | ||
width={30} | ||
height={30} | ||
src={"/resources/discord-icon.svg"} | ||
alt={"Discord Logo"} | ||
/> | ||
</a> | ||
</div> | ||
} | ||
/> | ||
</Row> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export { ErrorBoundary }; |
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
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
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
69 changes: 69 additions & 0 deletions
69
packages/web/src/pages/stats/general-charts/total-games-pie.tsx
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,69 @@ | ||
import { ResponsivePie } from "@nivo/pie"; | ||
import React from "react"; | ||
import { Empty } from "antd"; | ||
|
||
import { StatsDataObject, statsTypesInDB } from "../../../coh/types"; | ||
|
||
interface FactionsPlayedPieChartProps { | ||
data: StatsDataObject; | ||
} | ||
|
||
export const TotalGamesPieChart: React.FC<FactionsPlayedPieChartProps> = ({ data }) => { | ||
const chartData = []; | ||
|
||
// "1v1", "2v2", "3v3" ... | ||
for (let type of statsTypesInDB) { | ||
chartData.push({ | ||
id: type, | ||
label: type, | ||
value: data[type as "1v1" | "2v2" | "3v3" | "4v4"].totalGames, | ||
}); | ||
} | ||
|
||
if (!data["1v1"].totalGames && !((data["1v1"].totalGames || 0) > data["1v1"].matchCount)) { | ||
return <Empty description={"We started tracking total games from June 2022"} />; | ||
} | ||
|
||
return ( | ||
<ResponsivePie | ||
// @ts-ignore | ||
data={chartData} | ||
margin={{ bottom: 5, top: 5, right: 10 }} | ||
innerRadius={0.4} | ||
padAngle={0.7} | ||
cornerRadius={3} | ||
activeOuterRadiusOffset={8} | ||
borderWidth={1} | ||
arcLinkLabelsSkipAngle={10} | ||
arcLinkLabelsTextColor="#333333" | ||
arcLinkLabelsThickness={2} | ||
arcLabelsSkipAngle={10} | ||
enableArcLinkLabels={false} | ||
legends={[ | ||
{ | ||
anchor: "bottom-right", | ||
direction: "column", | ||
justify: false, | ||
translateX: 45, | ||
translateY: 0, | ||
itemsSpacing: 5, | ||
itemWidth: 100, | ||
itemHeight: 18, | ||
itemTextColor: "#999", | ||
itemDirection: "left-to-right", | ||
itemOpacity: 1, | ||
symbolSize: 18, | ||
symbolShape: "circle", | ||
effects: [ | ||
{ | ||
on: "hover", | ||
style: { | ||
itemTextColor: "#000", | ||
}, | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.