From e2ca9754edaf9fd0d3c552ed5151ac77b7d11ff5 Mon Sep 17 00:00:00 2001 From: K Date: Mon, 25 Nov 2024 13:25:22 +0000 Subject: [PATCH] now showing Unverified notes, dropped isPlusCode, isValidPlusCode coming from nr-app now --- nr-app/src/common/utils.ts | 2 +- nr-app/src/components/Map.tsx | 8 ++++++-- nr-app/src/utils/map.utils.ts | 4 ++++ nr-common/constants.ts | 1 - nr-common/utils.ts | 5 +++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/nr-app/src/common/utils.ts b/nr-app/src/common/utils.ts index f6c974a..4f82a2f 100644 --- a/nr-app/src/common/utils.ts +++ b/nr-app/src/common/utils.ts @@ -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; diff --git a/nr-app/src/components/Map.tsx b/nr-app/src/components/Map.tsx index 6eac887..c0e9750 100644 --- a/nr-app/src/components/Map.tsx +++ b/nr-app/src/components/Map.tsx @@ -3,6 +3,7 @@ import { coordinatesToPlusCode, plusCodeToCoordinates, plusCodeToRectangle, + isValidPlusCode, } from "@/utils/map.utils"; import { FlatList, @@ -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"; @@ -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]; }, ); @@ -94,11 +97,12 @@ const NoteMarker = ({ "open-location-code", ); - if (typeof plusCode === "undefined" || !isPlusCode(plusCode)) { + if (typeof plusCode === "undefined" || !isValidPlusCode(plusCode)) { console.warn( "#9k8qKM skipping event with missing / invalid plusCode", event, ); + console.log(plusCode); return null; } diff --git a/nr-app/src/utils/map.utils.ts b/nr-app/src/utils/map.utils.ts index 5e08f61..c6e62e8 100644 --- a/nr-app/src/utils/map.utils.ts +++ b/nr-app/src/utils/map.utils.ts @@ -8,6 +8,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, diff --git a/nr-common/constants.ts b/nr-common/constants.ts index 0985aeb..74a60fb 100644 --- a/nr-common/constants.ts +++ b/nr-common/constants.ts @@ -65,7 +65,6 @@ export const MAP_LAYERS = { title: "Unverified", rootUrl: "https://notes.trustroots.org", kind: 30397, - pubkey: '*', markerColor: "red", } as MapLayer, } as const; diff --git a/nr-common/utils.ts b/nr-common/utils.ts index ff635ac..e75b9dc 100644 --- a/nr-common/utils.ts +++ b/nr-common/utils.ts @@ -5,6 +5,7 @@ import { } from "./constants.ts"; import type { Event } from "./mod.ts"; + function last(items: T[]): T { const lastIndex = Math.max(items.length - 1, 0); return items[lastIndex]; @@ -25,6 +26,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][23456789CFGHJMPQRVWX]{6}\+[23456789CFGHJMPQRVWX]{2,7})(\s|$)/i; return re.test(code);