Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Nov 25, 2024
2 parents a14562d + e2218ef commit bf5274b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nr-app/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function trustrootsMapFilterForPlusCodePrefixes(

export function filterForMapLayerConfig(layerConfig: MapLayer): Filter {
const filter: Filter = {
authors: [layerConfig.pubkey],
...(layerConfig.pubkey ? { authors: [layerConfig.pubkey] } : {}),
kinds: [layerConfig.kind],
};
return filter;
Expand Down
16 changes: 11 additions & 5 deletions nr-app/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
coordinatesToPlusCode,
plusCodeToCoordinates,
plusCodeToRectangle,
isValidPlusCode,
} from "@/utils/map.utils";
import {
FlatList,
Expand Down Expand Up @@ -30,7 +31,7 @@ import { MAP_LAYER_KEY, MAP_LAYERS, MapLayer } from "@common/constants";
import {
getFirstLabelValueFromEvent,
getFirstTagValueFromEvent,
isPlusCode,
// isPlusCode,
} from "@common/utils";
import { createSelector } from "@reduxjs/toolkit";
import { matchFilter, NostrEvent } from "nostr-tools";
Expand All @@ -47,9 +48,11 @@ const selectEventsForLayers = createSelector(
(layerKey): [MAP_LAYER_KEY, EventWithMetadata[]] => {
const layerConfig = MAP_LAYERS[layerKey];
const filter = filterForMapLayerConfig(layerConfig);
console.log("RETLIF", filter);
const events = allEvents.filter((event) =>
matchFilter(filter, event.event),
);
console.log("STNEVE", events);
return [layerKey, events];
},
);
Expand Down Expand Up @@ -94,11 +97,13 @@ const NoteMarker = ({
"open-location-code",
);

if (typeof plusCode === "undefined" || !isPlusCode(plusCode)) {
console.warn(
if (typeof plusCode === "undefined" || !isValidPlusCode(plusCode)) {
console.log(
"#9k8qKM skipping event with missing / invalid plusCode",
event,
);
console.log(plusCode);
console.log("Event tags:", event.event.tags);
return null;
}

Expand All @@ -109,6 +114,7 @@ const NoteMarker = ({
const url = getEventLinkUrl(event.event, layerConfig);

const pinColor = layerConfig?.markerColor || "red";
const rectangleColor = layerConfig?.rectangleColor || "rgba(255,0,0,0.5)";

return (
<View>
Expand All @@ -131,7 +137,7 @@ const NoteMarker = ({
</Marker>
<Polygon
coordinates={rectangleCoordinates}
fillColor="rgba(0, 200, 0, 0.5)" // Semi-transparent green
fillColor={rectangleColor}
strokeColor="rgba(0, 0, 0, 0.5)" // Semi-transparent black
strokeWidth={2}
/>
Expand Down Expand Up @@ -220,11 +226,11 @@ export default function Map() {
keyExtractor={([key]) => key}
renderItem={({ item: [key, config] }) => (
<View style={styles.toggleContainer}>
<Text>{config.title}</Text>
<Switch
value={enabledLayers[key]}
onValueChange={() => void dispatch(toggleLayer(key))}
/>
<Text>{config.title} </Text>
</View>
)}
/>
Expand Down
4 changes: 4 additions & 0 deletions nr-app/src/utils/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ type PlusCodeShortLength = 2 | 4 | 6 | 8;

const plusCodeCharacters = "23456789CFGHJMPQRVWX" as const;

export function isValidPlusCode(code: string): boolean {
return OpenLocationCode.isValid(code);
}

export function coordinatesToPlusCode({
latitude,
longitude,
Expand Down
21 changes: 16 additions & 5 deletions nr-common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export const TIMESAFARI_AUTHOR_PUBLIC_KEY =
export type MapLayer = {
title: string;
rootUrl: string;
kind: 30399 | 30398;
kind: 30399 | 30398 | 30397;
pubkey: string;
markerColor: string;
rectangleColor: string;
};

export const MAP_LAYERS = {
Expand All @@ -38,28 +39,38 @@ export const MAP_LAYERS = {
rootUrl: "https://hitchmap.com",
kind: 30399,
pubkey: HITCHMAPS_AUTHOR_PUBLIC_KEY,
markerColor: "gold",
markerColor: "yellow",
rectangleColor: "rgba(255, 255, 0, 0.5)",
} as MapLayer,
hitchwiki: {
title: "Hitchwiki",
rootUrl: "https://hitchwiki.org",
kind: 30399,
pubkey: HITCHWIKI_AUTHOR_PUBLIC_KEY,
markerColor: "yellow",
markerColor: "gold",
rectangleColor: "rgba(255, 215, 0, 0.5)",
} as MapLayer,
timesafari: {
title: "Time Safari",
rootUrl: "https://www.timesafari.app",
kind: 30399,
pubkey: TIMESAFARI_AUTHOR_PUBLIC_KEY,
markerColor: "green",
markerColor: "blue",
rectangleColor: "rgba(0, 0, 255, 0.5)",
} as MapLayer,
triphopping: {
title: "Trip Hopping",
rootUrl: "https://www.triphopping.com",
kind: 30398,
pubkey: DEV_PUBKEY,
markerColor: "blue",
markerColor: "brown",
} as MapLayer,
unverified: {
title: "Unverified",
rootUrl: "https://notes.trustroots.org",
kind: 30397,
markerColor: "red",
rectangleColor: "rgba(255, 0, 0, 0.5)",
} as MapLayer,
} as const;
export type MAP_LAYER_KEY = keyof typeof MAP_LAYERS;
Expand Down
5 changes: 5 additions & 0 deletions nr-common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "./constants.ts";
import type { Event } from "./mod.ts";


function last<T>(items: T[]): T {
const lastIndex = Math.max(items.length - 1, 0);
return items[lastIndex];
Expand Down Expand Up @@ -32,6 +33,10 @@ export function isHexKey(key: string): boolean {
}

export function isPlusCode(code: string) {
return true;
// todo: use OpenLocationCode.isValid instead
// https://github.com/tspoke/typescript-open-location-code/blob/f44c7dd208fc65a903f4ab28381f0b4b59faac47/src/open-location-code.ts#L137

const re =
/(^|\s)([23456789C][23456789CFGHJMPQRV][023456789CFGHJMPQRVWX]{6}\+[23456789CFGHJMPQRVWX]*)(\s|$)/i;
const simpleTestResult = re.test(code);
Expand Down

0 comments on commit bf5274b

Please sign in to comment.