small improvements to community view

This commit is contained in:
hzrd149
2023-09-28 14:28:54 -05:00
parent a91b36d948
commit 3dea032ccb
3 changed files with 71 additions and 31 deletions

View File

@@ -26,7 +26,7 @@ function CommunityCard({ community, ...props }: Omit<CardProps, "children"> & {
<Box <Box
backgroundImage={getCommunityImage(community)} backgroundImage={getCommunityImage(community)}
backgroundRepeat="no-repeat" backgroundRepeat="no-repeat"
backgroundSize="contain" backgroundSize="cover"
backgroundPosition="center" backgroundPosition="center"
aspectRatio={3 / 1} aspectRatio={3 / 1}
/> />

View File

@@ -1,4 +1,6 @@
import { Box, BoxProps } from "@chakra-ui/react"; import { useState } from "react";
import { Box, BoxProps, Button } from "@chakra-ui/react";
import { NostrEvent } from "../../../types/nostr-event"; import { NostrEvent } from "../../../types/nostr-event";
import { getCommunityDescription } from "../../../helpers/nostr/communities"; import { getCommunityDescription } from "../../../helpers/nostr/communities";
import { EmbedableContent, embedUrls, truncateEmbedableContent } from "../../../helpers/embeds"; import { EmbedableContent, embedUrls, truncateEmbedableContent } from "../../../helpers/embeds";
@@ -7,19 +9,28 @@ import { renderGenericUrl } from "../../../components/embed-types";
export default function CommunityDescription({ export default function CommunityDescription({
community, community,
maxLength, maxLength,
showExpand,
...props ...props
}: Omit<BoxProps, "children"> & { community: NostrEvent; maxLength?: number }) { }: Omit<BoxProps, "children"> & { community: NostrEvent; maxLength?: number; showExpand?: boolean }) {
const description = getCommunityDescription(community); const description = getCommunityDescription(community);
let content: EmbedableContent = description ? [description] : []; let content: EmbedableContent = description ? [description] : [];
const [showAll, setShowAll] = useState(false);
content = embedUrls(content, [renderGenericUrl]); content = embedUrls(content, [renderGenericUrl]);
if (maxLength !== undefined) { if (maxLength !== undefined && !showAll) {
content = truncateEmbedableContent(content, maxLength); content = truncateEmbedableContent(content, maxLength);
} }
return ( return (
<>
<Box whiteSpace="pre-wrap" {...props}> <Box whiteSpace="pre-wrap" {...props}>
{content} {content}
</Box> </Box>
{maxLength !== undefined && showExpand && !showAll && (description?.length ?? 0) > maxLength && (
<Button variant="link" onClick={() => setShowAll(true)}>
Show More
</Button>
)}
</>
); );
} }

View File

@@ -1,5 +1,5 @@
import { useRef } from "react"; import { useRef } from "react";
import { Box, Flex, Heading, Text } from "@chakra-ui/react"; import { Box, Button, Card, Flex, Heading, Text } from "@chakra-ui/react";
import { import {
COMMUNITY_APPROVAL_KIND, COMMUNITY_APPROVAL_KIND,
@@ -8,6 +8,7 @@ import {
getCommunityImage, getCommunityImage,
getCommunityMods, getCommunityMods,
getCommunityName, getCommunityName,
getCommunityDescription,
} from "../../helpers/nostr/communities"; } from "../../helpers/nostr/communities";
import { NostrEvent, isETag } from "../../types/nostr-event"; import { NostrEvent, isETag } from "../../types/nostr-event";
import VerticalPageLayout from "../../components/vertical-page-layout"; import VerticalPageLayout from "../../components/vertical-page-layout";
@@ -48,6 +49,44 @@ function ApprovedEvent({ approval }: { approval: NostrEvent }) {
); );
} }
function CommunityDetails({ community }: { community: NostrEvent }) {
const communityRelays = getCommunityRelays(community);
const mods = getCommunityMods(community);
const description = getCommunityDescription(community);
return (
<Card p="2" w="xs" flexShrink={0}>
{description && (
<>
<Heading size="sm">Description:</Heading>
<CommunityDescription community={community} maxLength={256} showExpand />
</>
)}
<Heading size="sm" mt="2">
Moderators:
</Heading>
<Flex direction="column" gap="2">
{mods.map((pubkey) => (
<Flex gap="2">
<UserAvatarLink pubkey={pubkey} size="xs" />
<UserLink pubkey={pubkey} />
</Flex>
))}
</Flex>
{communityRelays.length > 0 && (
<>
<Heading size="sm" mt="2">
Relays:
</Heading>
<Flex direction="column" gap="2">
<RelayIconStack relays={communityRelays} />
</Flex>
</>
)}
</Card>
);
}
export default function CommunityHomePage({ community }: { community: NostrEvent }) { export default function CommunityHomePage({ community }: { community: NostrEvent }) {
const mods = getCommunityMods(community); const mods = getCommunityMods(community);
const image = getCommunityImage(community); const image = getCommunityImage(community);
@@ -70,9 +109,9 @@ export default function CommunityHomePage({ community }: { community: NostrEvent
<Box <Box
backgroundImage={getCommunityImage(community)} backgroundImage={getCommunityImage(community)}
backgroundRepeat="no-repeat" backgroundRepeat="no-repeat"
backgroundSize="contain" backgroundSize="cover"
backgroundPosition="center" backgroundPosition="center"
aspectRatio={4 / 1} aspectRatio={3 / 1}
backgroundColor="rgba(0,0,0,0.2)" backgroundColor="rgba(0,0,0,0.2)"
/> />
)} )}
@@ -84,28 +123,18 @@ export default function CommunityHomePage({ community }: { community: NostrEvent
</Flex> </Flex>
<CommunityJoinButton community={community} ml="auto" /> <CommunityJoinButton community={community} ml="auto" />
</Flex> </Flex>
<CommunityDescription community={community} />
<Flex wrap="wrap" gap="2">
<Text>Moderators:</Text>
{mods.map((pubkey) => (
<Flex gap="2">
<UserAvatarLink pubkey={pubkey} size="xs" />
<UserLink pubkey={pubkey} />
</Flex>
))}
</Flex>
{communityRelays.length > 0 && (
<Flex wrap="wrap" gap="2">
<Text>Relays:</Text>
<RelayIconStack relays={communityRelays} />
</Flex>
)}
<Flex gap="2" alignItems="flex-start">
<Flex direction="column" gap="2" flex={1}>
<IntersectionObserverProvider callback={callback}> <IntersectionObserverProvider callback={callback}>
{approvals.map((approval) => ( {approvals.map((approval) => (
<ApprovedEvent key={getEventUID(approval)} approval={approval} /> <ApprovedEvent key={getEventUID(approval)} approval={approval} />
))} ))}
</IntersectionObserverProvider> </IntersectionObserverProvider>
</Flex>
<CommunityDetails community={community} />
</Flex>
</VerticalPageLayout> </VerticalPageLayout>
</AdditionalRelayProvider> </AdditionalRelayProvider>
); );