Skip to content

Commit

Permalink
now showing Unverified notes, dropped isPlusCode, isValidPlusCode com…
Browse files Browse the repository at this point in the history
…ing from nr-app now
  • Loading branch information
K committed Nov 25, 2024
1 parent 784b7ab commit e2ca975
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 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
8 changes: 6 additions & 2 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,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;
}

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 @@ -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,
Expand Down
1 change: 0 additions & 1 deletion nr-common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const MAP_LAYERS = {
title: "Unverified",
rootUrl: "https://notes.trustroots.org",
kind: 30397,
pubkey: '*',
markerColor: "red",
} as MapLayer,
} as const;
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 All @@ -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);
Expand Down

0 comments on commit e2ca975

Please sign in to comment.