Skip to content

Commit

Permalink
store & show date of last sync
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Oct 15, 2023
1 parent 8070418 commit 2c8a1de
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-leaflet": "^4.2.0",
"react-timeago-i18n": "^1.1.0",
"through2": "^4.0.2",
"wellknown": "^0.5.0"
},
Expand Down
7 changes: 6 additions & 1 deletion script/3conflate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
} from "./util";
import { calcBBox } from "./util/calcBbox";

type GeoJsonOutput = FeatureCollection<MultiLineString, ConflatedStreet> & {
lastUpdated: string;
};

// only used for comparing names
const stripMacrons = (str: string) =>
str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
Expand Down Expand Up @@ -53,9 +57,10 @@ async function main() {
);

console.log("Confating...");
const missing: FeatureCollection<MultiLineString, ConflatedStreet> = {
const missing: GeoJsonOutput = {
type: "FeatureCollection",
features: [],
lastUpdated: new Date().toISOString(),
};

for (const sector in linzDB) {
Expand Down
38 changes: 36 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback, useEffect, useState } from "react";
import TimeAgo from "react-timeago-i18n";
import { MapContainer, ScaleControl } from "react-leaflet";
import { MapHook, Imagery, Streets, WholeNetwork } from "./map-layers";
import type { MissingStreet } from "./types";
import { useKeyboardShortcut } from "./util";
import { HelpModal } from "./components";
import { HelpModal, Modal } from "./components";

import "./index.css";
import "leaflet/dist/leaflet.css";
Expand All @@ -21,7 +22,9 @@ const home = (() => {
export const App: React.FC = () => {
const [data, setData] = useState<MissingStreet[]>();
const [error, setError] = useState<unknown>();
const [lastUpdated, setLastUpdated] = useState<string>();
const [modalOpen, setModalOpen] = useState(false);
const [infoModalOpen, setInfoModalOpen] = useState(false);
const [hidden, setHidden] = useState(false);

const toggleHidden = useCallback(() => setHidden((c) => !c), []);
Expand All @@ -35,7 +38,10 @@ export const App: React.FC = () => {
: "https://linz-addr-cdn.kyle.kiwi/missing-streets.json"
)
.then((r) => r.json())
.then((geojson) => setData(geojson.features))
.then((geojson) => {
setData(geojson.features);
setLastUpdated(geojson.lastUpdated);
})
.catch(setError);
}, []);

Expand All @@ -45,8 +51,36 @@ export const App: React.FC = () => {
return (
<>
{modalOpen && <HelpModal onClose={() => setModalOpen(false)} />}
{infoModalOpen && (
<Modal onClose={() => setInfoModalOpen(false)}>
Running the sync is currently a manual process. If the data hasn’t
been updated recently,{" "}
<a
href="https://osm.org/message/new/❤️‍🔥_import"
target="_blank"
rel="noreferrer noopener"
>
send me a message on OpenStreetMap
</a>
.
</Modal>
)}
<aside>
<h3>Missing Streets in New Zealand</h3>
{lastUpdated && (
<small>
Data updated <TimeAgo date={lastUpdated} />
<button
className="small"
type="button"
onClick={() => setInfoModalOpen(true)}
>
?
</button>
</small>
)}
<br />
<br />
<button
className="nice"
type="button"
Expand Down
11 changes: 4 additions & 7 deletions src/components/HelpModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Modal } from "./Modal";

export const HelpModal: React.FC<{ onClose(): void }> = ({ onClose }) => {
return (
<dialog open>
<Modal onClose={onClose}>
<ul>
<li>
Press <kbd>b</kbd> to switch imagery.
Expand All @@ -12,11 +14,6 @@ export const HelpModal: React.FC<{ onClose(): void }> = ({ onClose }) => {
Press <kbd>h</kbd> to show/hide all features.
</li>
</ul>
<form method="dialog">
<button className="nice" type="submit" onClick={onClose}>
Close
</button>
</form>
</dialog>
</Modal>
);
};
17 changes: 17 additions & 0 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PropsWithChildren } from "react";

export const Modal: React.FC<PropsWithChildren & { onClose(): void }> = ({
children,
onClose,
}) => {
return (
<dialog open>
{children}
<form method="dialog">
<button className="nice" type="submit" onClick={onClose}>
Close
</button>
</form>
</dialog>
);
};
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./HelpModal";
export * from "./Modal";
export * from "./QuickFixModal";
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ aside {
button.nice {
padding: 8px;
}
button.small {
padding: 0px 2px;
margin-left: 2px;
}
button.small:active,
button.nice:active {
transform: scale(0.9);
}
Expand Down
3 changes: 2 additions & 1 deletion src/map-layers/Street.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const Street = memo<{ street: MissingStreet }>(({ street }) => {
const onClickEdit = useCallback(() => {
const pos = popup.current!.getLatLng()!;
window.open(
`https://www.openstreetmap.org/edit#map=18/${pos.lat}/${pos.lng}`
// open a fork of iD which has access to the roads overlay
`https://kyle.kiwi/iD#map=18/${pos.lat}/${pos.lng}`
);
}, []);

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7690,6 +7690,11 @@ react-scripts@^5.0.1:
optionalDependencies:
fsevents "^2.3.2"

react-timeago-i18n@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-timeago-i18n/-/react-timeago-i18n-1.1.0.tgz#fe2c07601ff1a5ddb7282cae424ae430a462d830"
integrity sha512-3yMs87tohXNBqBxV+h0hMjaujo1H67aiDVvlBeHrXrGS8OupZAA5WQ9Yy0m8rlM8Irb38v56T0HOrKKWyNj14A==

react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down

0 comments on commit 2c8a1de

Please sign in to comment.