mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
error wrapper hoc
This commit is contained in:
1 parent
ad78e45f1b
commit
d3ab4bac51
2 files changed
+52
-47
No files matched your search
@@ -1,12 +1,14 @@
|
|||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { ErrorWrapper } from "../components/ErrorWrapper";
|
import { ErrorWrapper } from "../components/ErrorWrapper";
|
||||||
|
|
||||||
export function withErrorWrapper<Props extends {}>(
|
export function withErrorWrapper<Props extends object>(
|
||||||
Component: (props: Props) => ReactNode,
|
Component: (props: Props) => ReactNode,
|
||||||
) {
|
) {
|
||||||
return function (props: Props) {
|
return function (props: Props) {
|
||||||
<ErrorWrapper>
|
return (
|
||||||
<Component {...props} />
|
<ErrorWrapper>
|
||||||
</ErrorWrapper>;
|
<Component {...props} />
|
||||||
|
</ErrorWrapper>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Fragment, useMemo } from "react";
|
import { Fragment, useMemo } from "react";
|
||||||
import { api } from "../../../../api/dynamic";
|
import { api } from "../../../../api/dynamic";
|
||||||
import { TankopediaLoadout } from "../../../../components/TankopediaLoadout";
|
import { TankopediaLoadout } from "../../../../components/TankopediaLoadout";
|
||||||
|
import { withErrorWrapper } from "../../../../hocs/withErrorWrapper";
|
||||||
import { withLocale } from "../../../../hocs/withLocale";
|
import { withLocale } from "../../../../hocs/withLocale";
|
||||||
import { useAwait } from "../../../../hooks/useAwait";
|
import { useAwait } from "../../../../hooks/useAwait";
|
||||||
import { useCharacteristicRenderer } from "../../../../hooks/useCharacteristicRenderer";
|
import { useCharacteristicRenderer } from "../../../../hooks/useCharacteristicRenderer";
|
||||||
@@ -13,59 +14,61 @@ interface PageProps {
|
|||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Page = withLocale(({ id }: PageProps) => {
|
export const Page = withErrorWrapper(
|
||||||
const protagonistTank = useAwait(() => api.tank(id), `tank-${id}`);
|
withLocale<PageProps>(({ id }) => {
|
||||||
|
const protagonistTank = useAwait(() => api.tank(id), `tank-${id}`);
|
||||||
|
|
||||||
Tankopedia.useInitialization(protagonistTank);
|
Tankopedia.useInitialization(protagonistTank);
|
||||||
|
|
||||||
const renderCharacteristic = useCharacteristicRenderer();
|
const renderCharacteristic = useCharacteristicRenderer();
|
||||||
|
|
||||||
const protagonist = Tankopedia.use((state) => state.protagonist);
|
const protagonist = Tankopedia.use((state) => state.protagonist);
|
||||||
const protagonistEquipment = useEquipment(protagonistTank.tank!);
|
const protagonistEquipment = useEquipment(protagonistTank.tank!);
|
||||||
|
|
||||||
const { characteristics } = useMemo(
|
const { characteristics } = useMemo(
|
||||||
() =>
|
() =>
|
||||||
computeCharacteristics(
|
computeCharacteristics(
|
||||||
protagonistTank,
|
protagonistTank,
|
||||||
protagonistEquipment,
|
protagonistEquipment,
|
||||||
protagonist,
|
protagonist,
|
||||||
),
|
),
|
||||||
[protagonist],
|
[protagonist],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>{protagonist.id}</h1>
|
<h1>{protagonist.id}</h1>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<TankopediaLoadout />
|
<TankopediaLoadout />
|
||||||
|
|
||||||
<h2>characteristics</h2>
|
<h2>characteristics</h2>
|
||||||
|
|
||||||
{characteristicsOrder.map((group) => {
|
{characteristicsOrder.map((group) => {
|
||||||
return (
|
return (
|
||||||
<Fragment key={group.group}>
|
<Fragment key={group.group}>
|
||||||
<h3>{group.group}</h3>
|
<h3>{group.group}</h3>
|
||||||
|
|
||||||
{group.order.map((item) => {
|
{group.order.map((item) => {
|
||||||
if ("toy" in item) {
|
if ("toy" in item) {
|
||||||
return <span key={`toy-${item.toy}`}>toy: {item.toy}</span>;
|
return <span key={`toy-${item.toy}`}>toy: {item.toy}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = characteristics[item.name];
|
const value = characteristics[item.name];
|
||||||
|
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span key={`characteristic-${item.name}`}>
|
<span key={`characteristic-${item.name}`}>
|
||||||
{item.name}: {renderCharacteristic(value, item)}
|
{item.name}: {renderCharacteristic(value, item)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
Reference in new issue
Block a user