show reused goals on stream view

This commit is contained in:
hzrd149 2023-09-06 11:37:35 -05:00
parent 57518fd78d
commit eeda7ba3b1
2 changed files with 16 additions and 6 deletions

View File

@ -16,6 +16,7 @@ export type ParsedStream = {
image?: string;
updated: number;
status: "live" | "ended" | string;
goal?: string;
starts?: number;
ends?: number;
identifier: string;
@ -33,6 +34,7 @@ export function parseStreamEvent(stream: NostrEvent): ParsedStream {
const endsTag = stream.tags.find((t) => t[0] === "ends")?.[1];
const streaming = stream.tags.find((t) => t[0] === "streaming")?.[1];
const recording = stream.tags.find((t) => t[0] === "recording")?.[1];
const goal = stream.tags.find((t) => t[0] === "goal")?.[1];
const identifier = stream.tags.find((t) => t[0] === "d")?.[1];
let relays = stream.tags.find((t) => t[0] === "relays");
@ -74,6 +76,7 @@ export function parseStreamEvent(stream: NostrEvent): ParsedStream {
status,
starts: startTime,
ends: endTime,
goal,
identifier,
relays,
};

View File

@ -11,18 +11,25 @@ import GoalProgress from "../../goals/components/goal-progress";
import { getSharableEventAddress } from "../../../helpers/nip19";
import GoalTopZappers from "../../goals/components/goal-top-zappers";
import GoalZapButton from "../../goals/components/goal-zap-button";
import singleEventService from "../../../services/single-event";
export default function StreamGoal({ stream, ...props }: Omit<CardProps, "children"> & { stream: ParsedStream }) {
const [goal, setGoal] = useState<NostrEvent>();
const relays = useReadRelayUrls(stream.relays);
useEffect(() => {
const request = new NostrRequest(relays);
request.onEvent.subscribe((event) => {
setGoal(event);
});
request.start({ "#a": [getATag(stream)], kinds: [GOAL_KIND] });
}, [stream.identifier, relays.join("|")]);
if (stream.goal) {
singleEventService.requestEvent(stream.goal, relays).then((event) => {
setGoal(event);
});
} else {
const request = new NostrRequest(relays);
request.onEvent.subscribe((event) => {
setGoal(event);
});
request.start({ "#a": [getATag(stream)], kinds: [GOAL_KIND] });
}
}, [stream.identifier, stream.goal, relays.join("|")]);
if (!goal) return null;
const nevent = getSharableEventAddress(goal);