2021-06-19 12:34:53 +01:00
|
|
|
import { useState } from "preact/hooks";
|
|
|
|
|
|
|
|
const counts: { [key: string]: number } = {};
|
|
|
|
|
2021-07-05 11:23:23 +01:00
|
|
|
export default function PaintCounter({
|
|
|
|
small,
|
|
|
|
always,
|
|
|
|
}: {
|
|
|
|
small?: boolean;
|
|
|
|
always?: boolean;
|
|
|
|
}) {
|
|
|
|
if (import.meta.env.PROD && !always) return null;
|
2021-06-19 15:29:04 +01:00
|
|
|
|
2021-07-05 11:23:23 +01:00
|
|
|
const [uniqueId] = useState("" + Math.random());
|
|
|
|
const count = counts[uniqueId] ?? 0;
|
|
|
|
counts[uniqueId] = count + 1;
|
|
|
|
return (
|
|
|
|
<div style={{ textAlign: "center", fontSize: "0.8em" }}>
|
|
|
|
{small ? <>P: {count + 1}</> : <>Painted {count + 1} time(s).</>}
|
|
|
|
</div>
|
|
|
|
);
|
2021-06-19 12:34:53 +01:00
|
|
|
}
|