mirror of
https://github.com/dergigi/boris.git
synced 2026-01-19 23:04:46 +01:00
- 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.
45 lines
2.7 KiB
JavaScript
45 lines
2.7 KiB
JavaScript
import { modifyHiddenTags, modifyPublicTags, List } from "applesauce-factory/operations";
|
|
import { addRelayTag, removeRelayTag } from "applesauce-factory/operations/tag";
|
|
import { kinds } from "nostr-tools";
|
|
function getRelaySetEvent(events, self, identifier) {
|
|
const set = typeof identifier === "string" ? events.getReplaceable(kinds.Relaysets, self, identifier) : identifier;
|
|
if (!set)
|
|
throw new Error("Can't find relay set");
|
|
if (set.kind !== kinds.Relaysets)
|
|
throw new Error("Event is not a relay set");
|
|
return set;
|
|
}
|
|
/** An action that adds a relay to a relay set*/
|
|
export function AddRelayToRelaySet(relay, identifier, hidden = false) {
|
|
return async function* ({ events, factory, self }) {
|
|
const relays = getRelaySetEvent(events, self, identifier);
|
|
const operations = Array.isArray(relay) ? relay.map((r) => addRelayTag(r)) : addRelayTag(relay);
|
|
const draft = await factory.modifyTags(relays, hidden ? { hidden: operations } : operations);
|
|
yield await factory.sign(draft);
|
|
};
|
|
}
|
|
/** An action that removes a relay from a relay set */
|
|
export function RemoveRelayFromRelaySet(relay, identifier, hidden = false) {
|
|
return async function* ({ events, factory, self }) {
|
|
const relays = getRelaySetEvent(events, self, identifier);
|
|
const operations = Array.isArray(relay) ? relay.map((r) => removeRelayTag(r)) : removeRelayTag(relay);
|
|
const draft = await factory.modifyTags(relays, hidden ? { hidden: operations } : operations);
|
|
yield await factory.sign(draft);
|
|
};
|
|
}
|
|
/** An action that creates a new relay set */
|
|
export function CreateRelaySet(title, options) {
|
|
return async function* ({ factory }) {
|
|
const draft = await factory.build({ kind: kinds.Relaysets }, List.setTitle(title), options?.description ? List.setDescription(options.description) : undefined, options?.image ? List.setImage(options.image) : undefined, options?.public ? modifyPublicTags(...options.public.map((r) => addRelayTag(r))) : undefined, options?.hidden ? modifyHiddenTags(...options.hidden.map((r) => addRelayTag(r))) : undefined);
|
|
yield await factory.sign(draft);
|
|
};
|
|
}
|
|
/** An action that updates the title, description, or image of a relay set */
|
|
export function UpdateRelaySetInformation(identifier, info) {
|
|
return async function* ({ events, factory, self }) {
|
|
const relays = getRelaySetEvent(events, self, identifier);
|
|
const draft = await factory.modify(relays, info?.title ? List.setTitle(info.title) : undefined, info?.description ? List.setDescription(info.description) : undefined, info?.image ? List.setImage(info.image) : undefined);
|
|
yield await factory.sign(draft);
|
|
};
|
|
}
|