2022-01-29 20:50:44 +01:00
|
|
|
import React from 'react';
|
2022-01-17 19:50:14 +01:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { getMemory } from '../memory';
|
2022-02-03 22:20:07 +01:00
|
|
|
import { StolenDataEntry } from '../stolen-data-entry';
|
2022-01-17 19:50:14 +01:00
|
|
|
import { reduceConcat, useEmitter } from '../util';
|
|
|
|
import EmailTemplate from './email-template';
|
2021-11-07 13:57:24 +01:00
|
|
|
|
2022-02-02 10:33:09 +01:00
|
|
|
import './report-window.scss';
|
|
|
|
|
2021-11-07 13:57:24 +01:00
|
|
|
function Report() {
|
2022-01-30 17:36:42 +01:00
|
|
|
try {
|
2022-02-02 10:33:09 +01:00
|
|
|
const origin = new URL(document.location.toString()).searchParams.get('origin');
|
2022-01-30 17:36:42 +01:00
|
|
|
const [counter, setCounter] = useEmitter(getMemory());
|
|
|
|
const clusters = getMemory().getClustersForOrigin(origin);
|
|
|
|
const [entries, setEntries] = React.useState<StolenDataEntry[]>([]);
|
|
|
|
React.useEffect(() => {
|
|
|
|
setEntries(
|
|
|
|
Object.values(clusters)
|
|
|
|
.map((cluster) => {
|
|
|
|
cluster.calculateRepresentativeStolenData();
|
|
|
|
return cluster.representativeStolenData;
|
|
|
|
})
|
|
|
|
.reduce(reduceConcat, [])
|
|
|
|
.filter((entry) => entry.isMarked)
|
|
|
|
);
|
|
|
|
}, []);
|
|
|
|
if (entries.length == 0) {
|
|
|
|
return <>Wczytywanie...</>;
|
|
|
|
}
|
|
|
|
const result = (
|
|
|
|
<div {...{ 'data-version': counter }}>
|
2022-02-02 10:33:09 +01:00
|
|
|
<nav>
|
|
|
|
<img src="../assets/icon-addon.svg" width={48} height={48}></img>{' '}
|
|
|
|
<h1>Rentgen - Generuj treść maila dla {origin}</h1>
|
|
|
|
</nav>
|
|
|
|
|
2022-01-30 17:36:42 +01:00
|
|
|
<EmailTemplate {...{ entries, clusters, version: counter }} />
|
|
|
|
{/* <HARConverter {...{ entries }} /> */}
|
|
|
|
</div>
|
2022-01-17 19:50:14 +01:00
|
|
|
);
|
2022-01-30 17:36:42 +01:00
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2022-02-02 10:33:09 +01:00
|
|
|
return <div>ERROR! {JSON.stringify(e)}</div>;
|
2022-01-17 19:50:14 +01:00
|
|
|
}
|
2021-11-07 13:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-01-17 19:50:14 +01:00
|
|
|
ReactDOM.render(<Report />, document.getElementById('app'));
|