Files
boris/node_modules/applesauce-actions/dist/actions/pins.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

42 lines
2.0 KiB
JavaScript

import { getReplaceableAddress, isReplaceable } from "applesauce-core/helpers";
import { modifyPublicTags } from "applesauce-factory/operations";
import { addAddressTag, addEventTag, removeAddressTag, removeEventTag } from "applesauce-factory/operations/tag";
import { kinds } from "nostr-tools";
export const ALLOWED_PIN_KINDS = [kinds.ShortTextNote, kinds.LongFormArticle];
/** An action that pins a note to the users pin list */
export function PinNote(note) {
if (!ALLOWED_PIN_KINDS.includes(note.kind))
throw new Error(`Event kind ${note.kind} can not be pinned`);
return async function* ({ events, factory, self }) {
const pins = events.getReplaceable(kinds.Pinlist, self);
const operation = isReplaceable(note.kind) ? addAddressTag(getReplaceableAddress(note)) : addEventTag(note.id);
const draft = pins
? await factory.modifyTags(pins, operation)
: await factory.build({ kind: kinds.Pinlist }, modifyPublicTags(operation));
yield await factory.sign(draft);
};
}
/** An action that removes an event from the users pin list */
export function UnpinNote(note) {
return async function* ({ events, factory, self }) {
const pins = events.getReplaceable(kinds.Pinlist, self);
if (!pins)
return;
const operation = isReplaceable(note.kind)
? removeAddressTag(getReplaceableAddress(note))
: removeEventTag(note.id);
const draft = await factory.modifyTags(pins, operation);
yield await factory.sign(draft);
};
}
/** An action that creates a new pin list for a user */
export function CreatePinList(pins = []) {
return async function* ({ events, factory, self }) {
const existing = events.getReplaceable(kinds.Pinlist, self);
if (existing)
throw new Error("Pin list already exists");
const draft = await factory.build({ kind: kinds.Pinlist }, modifyPublicTags(...pins.map((event) => addEventTag(event.id))));
yield await factory.sign(draft);
};
}