-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
212 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useRef } from "react"; | ||
import { Box } from "@chakra-ui/react"; | ||
import { useOutletContext } from "react-router-dom"; | ||
|
||
import { unique } from "../../../helpers/array"; | ||
import { | ||
COMMUNITY_APPROVAL_KIND, | ||
getApprovedEmbeddedNote, | ||
getCommunityMods, | ||
getCommunityRelays, | ||
} from "../../../helpers/nostr/communities"; | ||
import { getEventCoordinate, getEventUID } from "../../../helpers/nostr/events"; | ||
import { useReadRelayUrls } from "../../../hooks/use-client-relays"; | ||
import useSubject from "../../../hooks/use-subject"; | ||
import { useTimelineCurserIntersectionCallback } from "../../../hooks/use-timeline-cursor-intersection-callback"; | ||
import useTimelineLoader from "../../../hooks/use-timeline-loader"; | ||
import { NostrEvent, isETag } from "../../../types/nostr-event"; | ||
import { EmbedEvent } from "../../../components/embed-event"; | ||
import useSingleEvent from "../../../hooks/use-single-event"; | ||
import { useAdditionalRelayContext } from "../../../providers/additional-relay-context"; | ||
import IntersectionObserverProvider, { useRegisterIntersectionEntity } from "../../../providers/intersection-observer"; | ||
import TimelineActionAndStatus from "../../../components/timeline-page/timeline-action-and-status"; | ||
|
||
function ApprovedEvent({ approval }: { approval: NostrEvent }) { | ||
const ref = useRef<HTMLDivElement | null>(null); | ||
useRegisterIntersectionEntity(ref, getEventUID(approval)); | ||
|
||
const additionalRelays = useAdditionalRelayContext(); | ||
const embeddedEvent = getApprovedEmbeddedNote(approval); | ||
const eventTag = approval.tags.find(isETag); | ||
|
||
const loadEvent = useSingleEvent( | ||
eventTag?.[1], | ||
eventTag?.[2] ? [eventTag[2], ...additionalRelays] : additionalRelays, | ||
); | ||
const event = loadEvent || embeddedEvent; | ||
if (!event) return; | ||
return ( | ||
<Box ref={ref}> | ||
<EmbedEvent event={event} /> | ||
</Box> | ||
); | ||
} | ||
|
||
export default function CommunityNewView() { | ||
const { community } = useOutletContext() as { community: NostrEvent }; | ||
const mods = getCommunityMods(community); | ||
|
||
const readRelays = useReadRelayUrls(getCommunityRelays(community)); | ||
const timeline = useTimelineLoader(`${getEventUID(community)}-approved-posts`, readRelays, { | ||
authors: unique([community.pubkey, ...mods]), | ||
kinds: [COMMUNITY_APPROVAL_KIND], | ||
"#a": [getEventCoordinate(community)], | ||
}); | ||
|
||
const approvals = useSubject(timeline.timeline); | ||
const callback = useTimelineCurserIntersectionCallback(timeline); | ||
|
||
return ( | ||
<> | ||
<IntersectionObserverProvider callback={callback}> | ||
{approvals.map((approval) => ( | ||
<ApprovedEvent key={getEventUID(approval)} approval={approval} /> | ||
))} | ||
</IntersectionObserverProvider> | ||
<TimelineActionAndStatus timeline={timeline} /> | ||
</> | ||
); | ||
} |
Oops, something went wrong.