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

View File

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