Skip to content

Commit

Permalink
Update to new API, update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SAPikachu committed Dec 19, 2020
1 parent bb373e9 commit dcafc58
Show file tree
Hide file tree
Showing 48 changed files with 9,808 additions and 6,068 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@
"no-fallthrough": 2,
"no-octal-escape": 2,
"no-octal": 2,
"no-redeclare": 2,
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": [
"error", {"ignoreDeclarationMerge": true}
],
"no-with": 2,
"no-catch-shadow": 2,
"no-undef": 2,
"no-use-before-define": 2,
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"error"
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"brace-style": [1, "1tbs", { "allowSingleLine": true }],
"comma-spacing": [2, { "after": true }],
"comma-style": [2, "last"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
.eslintcache
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
12
6 changes: 4 additions & 2 deletions .rescriptsrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { editWebpackPlugin } = require("@rescripts/utilities");

module.exports = [
module.exports = [/*
config => { console.log(config); return config; },
process.env.NODE_ENV === "production"
? config =>
editWebpackPlugin(
Expand All @@ -12,6 +14,6 @@ module.exports = [
"GenerateSW",
config
)
: x => x
: x => x*/
];
// vim: sts=2:sw=2:ts=2:expandtab
15,023 changes: 9,221 additions & 5,802 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@
"main": "src/index.tsx",
"dependencies": {
"bootstrap": "4.4.1",
"clsx": "1.0.4",
"dayjs": "^1.8.17",
"i18next": "^19.3.2",
"i18next-browser-languagedetector": "^4.0.2",
"react": "16.12.0",
"react-dom": "16.12.0",
"react-helmet": "^5.2.1",
"react-i18next": "^11.3.3",
"clsx": "1.1.1",
"dayjs": "^1.9.7",
"i18next": "^19.8.4",
"i18next-browser-languagedetector": "^6.0.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-helmet": "^6.1.0",
"react-i18next": "^11.8.3",
"react-icons": "^3.8.0",
"react-loadable": "^5.5.0",
"react-router-dom": "5.1.2",
"react-scripts": "3.3.0",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.1",
"react-tooltip": "^3.11.1",
"react-virtualized": "9.21.2",
"react-virtualized": "9.22.2",
"recharts": "^1.8.5"
},
"devDependencies": {
"@rescripts/cli": "0.0.13",
"@types/google.analytics": "0.0.40",
"@types/react": "16.9.15",
"@types/react-dom": "16.9.4",
"@types/react-helmet": "^5.0.14",
"@types/react-loadable": "^5.5.2",
"@types/react-router-dom": "5.1.3",
"@rescripts/cli": "0.0.15",
"@types/google.analytics": "0.0.41",
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@types/react-helmet": "^6.1.0",
"@types/react-loadable": "^5.5.4",
"@types/react-router-dom": "5.1.6",
"@types/react-tooltip": "^3.11.0",
"@types/react-virtualized": "9.21.6",
"@types/recharts": "^1.8.3",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"eslint": "^6.7.2",
"node-sass": "^4.13.0",
"typescript": "3.7.3"
"@types/react-virtualized": "9.21.10",
"@types/recharts": "^1.8.18",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"eslint": "^7.15.0",
"node-sass": "^4.0.0",
"typescript": "4.1.2"
},
"scripts": {
"start": "rescripts start",
Expand Down
3 changes: 1 addition & 2 deletions src/components/app/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const NAV_ITEMS = [
.map(([label, path]) => ({ label, path }));

const SITE_LINKS = [
["四麻玉/王座", CONFIGURATIONS.DEFAULT.canonicalDomain],
["四麻金", CONFIGURATIONS.ako.canonicalDomain],
["四麻", CONFIGURATIONS.DEFAULT.canonicalDomain],
["三麻", CONFIGURATIONS.ikeda.canonicalDomain],
].map(([label, domain]) => ({ label, domain, active: Conf.canonicalDomain === domain }));

Expand Down
27 changes: 13 additions & 14 deletions src/components/charts/simplePieChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import React from "react";
import { ResponsiveContainer, PieChart, Pie, Cell, LabelList, LabelProps, PolarViewBox } from "recharts";
import {
ResponsiveContainer,
PieChart,
Pie,
Cell,
LabelList,
LabelProps,
PolarViewBox,
} from "recharts";
import { useMemo } from "react";

const DEFAULT_COLORS = ["#003f5c", "#7a5195", "#ef5675", "#ffa600"];
Expand All @@ -15,18 +23,15 @@ const RADIAN = Math.PI / 180;

const polarToCartesian = (cx: number, cy: number, radius: number, angle: number) => ({
x: cx + Math.cos(-RADIAN * angle) * radius,
y: cy + Math.sin(-RADIAN * angle) * radius
y: cy + Math.sin(-RADIAN * angle) * radius,
});

const renderCustomizedLabelFactory = ({ lineHeight = 24, innerLabelFontSize = "1rem" }) => (props: LabelProps) => {
const { value } = props;
if (!value) {
return null;
}
const lines = value
.toString()
.trim()
.split("\n");
const lines = value.toString().trim().split("\n");
const { cx, cy, outerRadius, startAngle, endAngle } = props.viewBox as Required<PolarViewBox>;
const labelAngle = startAngle + getDeltaAngle(startAngle, endAngle) / 2;
const { x, y } = polarToCartesian(cx, cy, outerRadius / 2, labelAngle);
Expand Down Expand Up @@ -65,12 +70,6 @@ function defaultOuterLabel<T extends PieChartItem>(item: T) {
return item.outerLabel || "";
}

declare module "recharts" {
interface LabelListProps {
fill?: string;
}
}

export default function SimplePieChart<T extends PieChartItem>({
items,
innerLabel = defaultInnerLabel,
Expand All @@ -80,7 +79,7 @@ export default function SimplePieChart<T extends PieChartItem>({
startAngle = 0,
colors = DEFAULT_COLORS,
innerLabelFontSize = "1rem",
aspect = 1
aspect = 1,
}: {
items: T[];
innerLabel?: (item: T) => string;
Expand Down Expand Up @@ -128,8 +127,8 @@ export default function SimplePieChart<T extends PieChartItem>({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dataKey={undefined as any}
position="inside"
fill="#fff"
content={renderCustomizedLabel}
{...{ fill: "#fff" }}
/>
</Pie>
</PieChart>
Expand Down
3 changes: 2 additions & 1 deletion src/components/contestTools/minMax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function MinMax() {
[key: string]: typeof playerList[0];
};
while (cur.isBefore(end)) {
const loader = new ListingDataLoader(cur);
const loader = new ListingDataLoader(cur, null);
for (;;) {
const records = await loader.getNextChunk();
if (!records.length) {
Expand Down Expand Up @@ -69,6 +69,7 @@ export default function MinMax() {
}
setPlayerList(Object.values(players));
setLoading(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setLoading, dateStart, dateEnd, setPlayerList, playerList]);
return (
<>
Expand Down
101 changes: 62 additions & 39 deletions src/components/form/checkboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,113 @@
import React from "react";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
import { useState } from "react";

export interface CheckboxItem {
export interface CheckboxItem<T> {
key: string;
label: string;
value: T;
}

type CommonGroupParams = {
items: CheckboxItem[];
type GroupParams<T> = {
type: "checkbox" | "radio";
items: CheckboxItem<T>[];
groupKey: string;
selectedItems: Iterable<string | CheckboxItem<T>> | null;
onChange: (selectedItems: CheckboxItem<T>[]) => void;
};
type CheckboxGroupParams = CommonGroupParams & {
type: "checkbox";
selectedItemKeys: Set<string> | null;
onChange: (selectedItemKeys: Set<string>) => void;
};
type RadioGroupParams = CommonGroupParams & {
type: "radio";
selectedItemKey: string;
onChange: (selectedItemKey: string) => void;
};

export function CheckboxGroup(
props: CheckboxGroupParams | RadioGroupParams = {
export function CheckboxGroup<T>(
props: GroupParams<T> = {
type: "checkbox",
items: [],
groupKey: "default",
selectedItemKeys: null,
selectedItems: null,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onChange: () => {}
onChange: () => {},
}
) {
const { t } = useTranslation();
const { type, items, groupKey } = props;
const { setSelected, isChecked } = (() => {
const [activeKey, setActiveKey] = useState(null as string | null);
const selectedItemKeys = useMemo(() => {
const ret = new Set<string>();
for (const item of props.selectedItems || []) {
if (typeof item === "string") {
ret.add(item);
} else {
ret.add(item.key);
}
}
return ret;
}, [props.selectedItems]);
const { type, items, groupKey, onChange } = props;
const { setSelected, selectSingle } = useMemo(() => {
if (props.type === "checkbox") {
const { selectedItemKeys, onChange } = props;
return {
setSelected(key: string, isSelected: boolean) {
if (isSelected && (!selectedItemKeys || selectedItemKeys.has(key))) {
if (isSelected && selectedItemKeys.has(key)) {
return;
}
if (!isSelected && selectedItemKeys && !selectedItemKeys.has(key)) {
if (!isSelected && !selectedItemKeys.has(key)) {
return;
}
const newSet = new Set(selectedItemKeys || items.map(x => x.key));
const newSet = new Set(selectedItemKeys || items.map((x) => x.key));
if (isSelected) {
newSet.add(key);
} else {
newSet.delete(key);
}
onChange(newSet);
onChange(items.filter((x) => newSet.has(x.key)));
},
selectSingle(key: string) {
if (selectedItemKeys.size === 1 && selectedItemKeys.has(key)) {
return;
}
onChange(items.filter((x) => x.key === key));
},
isChecked: (key: string) => !selectedItemKeys || selectedItemKeys.has(key)
};
} else {
const { selectedItemKey, onChange } = props;
return {
setSelected(key: string, isSelected: boolean) {
if (!isSelected) {
return;
}
onChange(key);
const item = items.find((x) => x.key === key);
onChange(item ? [item] : []);
},
selectSingle(key: string) {
setSelected(key, true);
},
isChecked: (key: string) => selectedItemKey === key
};
}
})();
}, [items, onChange, props.type, selectedItemKeys]);
return (
<React.Fragment>
{items.map(item => (
<div className="form-check form-check-inline" key={item.key}>
<div className={clsx("checkbox-group", "checkbox-group-" + type, activeKey && "checkbox-group-has-active")}>
{items.map((item) => (
<div className={clsx("form-check form-check-inline", activeKey === item.key && "active")} key={item.key}>
<input
className="form-check-input"
type={type}
id={`CG_${groupKey}_${item.key}`}
name={`CG_${groupKey}_${item.key}`}
value={item.key}
checked={isChecked(item.key)}
onChange={event => setSelected(item.key, event.currentTarget.checked)}
checked={selectedItemKeys.has(item.key)}
onChange={(event) => setSelected(item.key, event.currentTarget.checked)}
/>
<label className="form-check-label" htmlFor={`CG_${groupKey}_${item.key}`}>
<label
className="form-check-label"
htmlFor={`CG_${groupKey}_${item.key}`}
onMouseEnter={() => setActiveKey(item.key)}
onMouseLeave={() => (activeKey === item.key ? setActiveKey(null) : undefined)}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
selectSingle(item.key);
}}
>
{t(item.label)}
</label>
</div>
))}
</React.Fragment>
</div>
);
}
}
1 change: 1 addition & 0 deletions src/components/form/datePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import React from "react";

import dayjs from "dayjs";
Expand Down
Loading

0 comments on commit dcafc58

Please sign in to comment.