Skip to content

Commit dda2ba2

Browse files
committed
futz
1 parent 98a58a4 commit dda2ba2

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/Results/PositionCell.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FunctionComponent } from 'preact';
1+
import type { FunctionComponent } from 'preact';
2+
import { useCallback } from 'preact/compat';
23
import type { Point } from 'geojson';
34
import Icon from '../Icon';
45
import { formatCoord } from '../util';
@@ -14,16 +15,13 @@ const PositionCell: FunctionComponent<Props> = ({ coord }) => {
1415
query: [coord.coordinates[1], coord.coordinates[0]].join(','),
1516
});
1617
const url = 'https://www.google.com/maps/search/?' + params.toString();
18+
const onCopyClick = useCallback(() => {
19+
navigator.clipboard.writeText(stringCoord).catch(console.error);
20+
}, [stringCoord]);
1721
return (
1822
<td className="position">
1923
<a href={url}>{stringCoord}</a>
20-
<Icon
21-
name="copy"
22-
label="Copy coordinates"
23-
onClick={() => {
24-
navigator.clipboard.writeText(stringCoord).catch(console.error);
25-
}}
26-
/>
24+
<Icon name="copy" label="Copy coordinates" onClick={onCopyClick} />
2725
</td>
2826
);
2927
};

src/Results/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import { FunctionComponent } from 'preact';
2-
import { useMemo } from 'preact/compat';
32
import { decorate } from '../computation';
43
import { selectExtraGc, selectGameConfig } from '../gameConfig';
5-
import { useAppSelector } from '../store';
4+
import { createAppSelector, useAppSelector } from '../store';
65
import Grid from './Grid';
76

8-
const Results: FunctionComponent = () => {
9-
const game = useAppSelector(selectGameConfig);
10-
const extraGc = useAppSelector(selectExtraGc);
11-
const photos = useAppSelector((state) => state.data.photos);
12-
const results = useMemo(() => {
7+
const selectResults = createAppSelector(
8+
[selectGameConfig, (state) => state.data.photos],
9+
(game, photos) => {
1310
if (game && photos && photos.features.length > 0) {
1411
return decorate(game, photos);
1512
} else {
1613
return null;
1714
}
18-
}, [game, photos]);
15+
}
16+
);
17+
18+
const Results: FunctionComponent = () => {
19+
const extraGc = useAppSelector(selectExtraGc);
20+
const results = useAppSelector(selectResults);
1921
if (results && results.features.length > 0) {
2022
return (
2123
<>

src/parseData.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import { kml } from './togeojson';
1414
const readFile = (f: Blob): Promise<string> =>
1515
new Promise((resolve, reject) => {
1616
const reader = new FileReader();
17-
reader.addEventListener('load', () => resolve(reader.result as string));
17+
reader.addEventListener('load', () => {
18+
if (typeof reader.result === 'string') {
19+
resolve(reader.result);
20+
} else {
21+
reject('Could not read data');
22+
}
23+
});
1824
reader.addEventListener('error', (e) => reject('Could not read file'));
1925
reader.readAsText(f);
2026
});

0 commit comments

Comments
 (0)