mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-21 22:13:11 +02:00
fix bug with reaction images overflowing
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Button, ButtonGroup, ButtonGroupProps, ButtonProps, IconButton, Image, useDisclosure } from "@chakra-ui/react";
|
import { Button, ButtonProps, IconButton, Image, useDisclosure } from "@chakra-ui/react";
|
||||||
import { useCallback, useMemo } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import { NostrEvent } from "../types/nostr-event";
|
import { NostrEvent } from "../types/nostr-event";
|
||||||
import useEventReactions from "../hooks/use-event-reactions";
|
import useEventReactions from "../hooks/use-event-reactions";
|
||||||
@@ -9,11 +9,12 @@ import { useSigningContext } from "../providers/signing-provider";
|
|||||||
import clientRelaysService from "../services/client-relays";
|
import clientRelaysService from "../services/client-relays";
|
||||||
import NostrPublishAction from "../classes/nostr-publish-action";
|
import NostrPublishAction from "../classes/nostr-publish-action";
|
||||||
import eventReactionsService from "../services/event-reactions";
|
import eventReactionsService from "../services/event-reactions";
|
||||||
|
import { useCurrentAccount } from "../hooks/use-current-account";
|
||||||
|
|
||||||
export function ReactionIcon({ emoji, url }: { emoji: string; url?: string }) {
|
export function ReactionIcon({ emoji, url }: { emoji: string; url?: string }) {
|
||||||
if (emoji === "+") return <LikeIcon />;
|
if (emoji === "+") return <LikeIcon />;
|
||||||
if (emoji === "-") return <DislikeIcon />;
|
if (emoji === "-") return <DislikeIcon />;
|
||||||
if (url) return <Image src={url} title={emoji} alt={emoji} />;
|
if (url) return <Image src={url} title={emoji} alt={emoji} w="1em" h="1em" display="inline" />;
|
||||||
return <span>{emoji}</span>;
|
return <span>{emoji}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,16 +28,14 @@ function ReactionGroupButton({
|
|||||||
return <IconButton icon={<ReactionIcon emoji={emoji} url={url} />} aria-label="Reaction" {...props} />;
|
return <IconButton icon={<ReactionIcon emoji={emoji} url={url} />} aria-label="Reaction" {...props} />;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Button leftIcon={<ReactionIcon emoji={emoji} url={url} />} {...props}>
|
<Button leftIcon={<ReactionIcon emoji={emoji} url={url} />} title={emoji} {...props}>
|
||||||
{count > 1 && count}
|
{count > 1 && count}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EventReactions({
|
export default function EventReactionButtons({ event, ...props }: { event: NostrEvent }) {
|
||||||
event,
|
const account = useCurrentAccount();
|
||||||
...props
|
|
||||||
}: Omit<ButtonGroupProps, "children"> & { event: NostrEvent }) {
|
|
||||||
const detailsModal = useDisclosure();
|
const detailsModal = useDisclosure();
|
||||||
const reactions = useEventReactions(event.id) ?? [];
|
const reactions = useEventReactions(event.id) ?? [];
|
||||||
const grouped = useMemo(() => groupReactions(reactions), [reactions]);
|
const grouped = useMemo(() => groupReactions(reactions), [reactions]);
|
||||||
@@ -57,7 +56,6 @@ export default function EventReactions({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ButtonGroup wrap="wrap" {...props}>
|
|
||||||
{grouped.map((group) => (
|
{grouped.map((group) => (
|
||||||
<ReactionGroupButton
|
<ReactionGroupButton
|
||||||
key={group.emoji}
|
key={group.emoji}
|
||||||
@@ -65,10 +63,10 @@ export default function EventReactions({
|
|||||||
url={group.url}
|
url={group.url}
|
||||||
count={group.count}
|
count={group.count}
|
||||||
onClick={() => addReaction(group.emoji, group.url)}
|
onClick={() => addReaction(group.emoji, group.url)}
|
||||||
|
colorScheme={account && group.pubkeys.includes(account?.pubkey) ? "brand" : undefined}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Button onClick={detailsModal.onOpen}>Show all</Button>
|
<Button onClick={detailsModal.onOpen}>Show all</Button>
|
||||||
</ButtonGroup>
|
|
||||||
{detailsModal.isOpen && <ReactionDetailsModal isOpen onClose={detailsModal.onClose} reactions={reactions} />}
|
{detailsModal.isOpen && <ReactionDetailsModal isOpen onClose={detailsModal.onClose} reactions={reactions} />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@@ -14,15 +14,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
|||||||
<ReloadPrompt mb="2" />
|
<ReloadPrompt mb="2" />
|
||||||
<Container size="lg" display="flex" padding="0" gap="4" alignItems="flex-start">
|
<Container size="lg" display="flex" padding="0" gap="4" alignItems="flex-start">
|
||||||
{!isMobile && <DesktopSideNav position="sticky" top="0" />}
|
{!isMobile && <DesktopSideNav position="sticky" top="0" />}
|
||||||
<Flex
|
<Flex flexGrow={1} direction="column" w="full" overflow="hidden" pb={isMobile ? "14" : 0} minH="50vh">
|
||||||
flexGrow={1}
|
|
||||||
direction="column"
|
|
||||||
w="full"
|
|
||||||
overflowX="hidden"
|
|
||||||
overflowY="visible"
|
|
||||||
pb={isMobile ? "14" : 0}
|
|
||||||
minH="50vh"
|
|
||||||
>
|
|
||||||
<ErrorBoundary>{children}</ErrorBoundary>
|
<ErrorBoundary>{children}</ErrorBoundary>
|
||||||
</Flex>
|
</Flex>
|
||||||
{isMobile && (
|
{isMobile && (
|
||||||
|
21
src/components/note/components/note-reactions.tsx
Normal file
21
src/components/note/components/note-reactions.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { ButtonGroup, ButtonGroupProps, Divider } from "@chakra-ui/react";
|
||||||
|
import { NostrEvent } from "../../../types/nostr-event";
|
||||||
|
import ReactionButton from "./reaction-button";
|
||||||
|
import EventReactionButtons from "../../event-reactions";
|
||||||
|
import useEventReactions from "../../../hooks/use-event-reactions";
|
||||||
|
|
||||||
|
export default function NoteReactions({ event, ...props }: Omit<ButtonGroupProps, "children"> & { event: NostrEvent }) {
|
||||||
|
const reactions = useEventReactions(event.id) ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ButtonGroup spacing="1" {...props}>
|
||||||
|
<ReactionButton event={event} />
|
||||||
|
{reactions.length > 0 && (
|
||||||
|
<>
|
||||||
|
<Divider orientation="vertical" h="1.5rem" />
|
||||||
|
<EventReactionButtons event={event} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ButtonGroup>
|
||||||
|
);
|
||||||
|
}
|
@@ -8,7 +8,6 @@ import {
|
|||||||
CardFooter,
|
CardFooter,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardProps,
|
CardProps,
|
||||||
Divider,
|
|
||||||
Flex,
|
Flex,
|
||||||
IconButton,
|
IconButton,
|
||||||
Link,
|
Link,
|
||||||
@@ -21,7 +20,6 @@ import { NoteMenu } from "./note-menu";
|
|||||||
import { EventRelays } from "./note-relays";
|
import { EventRelays } from "./note-relays";
|
||||||
import { UserLink } from "../user-link";
|
import { UserLink } from "../user-link";
|
||||||
import { UserDnsIdentityIcon } from "../user-dns-identity-icon";
|
import { UserDnsIdentityIcon } from "../user-dns-identity-icon";
|
||||||
import ReactionButton from "./components/reaction-button";
|
|
||||||
import NoteZapButton from "./note-zap-button";
|
import NoteZapButton from "./note-zap-button";
|
||||||
import { ExpandProvider } from "./expanded";
|
import { ExpandProvider } from "./expanded";
|
||||||
import useSubject from "../../hooks/use-subject";
|
import useSubject from "../../hooks/use-subject";
|
||||||
@@ -35,8 +33,9 @@ import { TrustProvider } from "../../providers/trust";
|
|||||||
import { NoteLink } from "../note-link";
|
import { NoteLink } from "../note-link";
|
||||||
import { useRegisterIntersectionEntity } from "../../providers/intersection-observer";
|
import { useRegisterIntersectionEntity } from "../../providers/intersection-observer";
|
||||||
import BookmarkButton from "./components/bookmark-button";
|
import BookmarkButton from "./components/bookmark-button";
|
||||||
import EventReactions from "../event-reactions";
|
import EventReactionButtons from "../event-reactions";
|
||||||
import { useCurrentAccount } from "../../hooks/use-current-account";
|
import { useCurrentAccount } from "../../hooks/use-current-account";
|
||||||
|
import NoteReactions from "./components/note-reactions";
|
||||||
|
|
||||||
export type NoteProps = {
|
export type NoteProps = {
|
||||||
event: NostrEvent;
|
event: NostrEvent;
|
||||||
@@ -55,6 +54,8 @@ export const Note = React.memo(({ event, variant = "outline" }: NoteProps) => {
|
|||||||
|
|
||||||
const showReactionsOnNewLine = useBreakpointValue({ base: true, md: false });
|
const showReactionsOnNewLine = useBreakpointValue({ base: true, md: false });
|
||||||
|
|
||||||
|
const reactionButtons = showReactions && <NoteReactions event={event} flexWrap="wrap" variant="ghost" size="xs" />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TrustProvider event={event}>
|
<TrustProvider event={event}>
|
||||||
<ExpandProvider>
|
<ExpandProvider>
|
||||||
@@ -75,22 +76,14 @@ export const Note = React.memo(({ event, variant = "outline" }: NoteProps) => {
|
|||||||
<NoteContentWithWarning event={event} />
|
<NoteContentWithWarning event={event} />
|
||||||
</CardBody>
|
</CardBody>
|
||||||
<CardFooter padding="2" display="flex" gap="2" flexDirection="column" alignItems="flex-start">
|
<CardFooter padding="2" display="flex" gap="2" flexDirection="column" alignItems="flex-start">
|
||||||
{showReactions && showReactionsOnNewLine && (
|
{showReactionsOnNewLine && reactionButtons}
|
||||||
<EventReactions event={event} variant="ghost" size="xs" spacing="1" />
|
|
||||||
)}
|
|
||||||
<Flex gap="2" w="full" alignItems="center">
|
<Flex gap="2" w="full" alignItems="center">
|
||||||
<ButtonGroup size="xs" variant="ghost" isDisabled={account?.readonly ?? true}>
|
<ButtonGroup size="xs" variant="ghost" isDisabled={account?.readonly ?? true}>
|
||||||
<RepostButton event={event} />
|
<RepostButton event={event} />
|
||||||
<QuoteRepostButton event={event} />
|
<QuoteRepostButton event={event} />
|
||||||
<NoteZapButton event={event} />
|
<NoteZapButton event={event} />
|
||||||
<ReactionButton event={event} />
|
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
{showReactions && !showReactionsOnNewLine && (
|
{!showReactionsOnNewLine && reactionButtons}
|
||||||
<>
|
|
||||||
<Divider orientation="vertical" h="1.5rem" />
|
|
||||||
<EventReactions event={event} variant="ghost" size="xs" spacing="1" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Box flexGrow={1} />
|
<Box flexGrow={1} />
|
||||||
{externalLink && (
|
{externalLink && (
|
||||||
<IconButton
|
<IconButton
|
||||||
|
Reference in New Issue
Block a user