mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-27 20:17:05 +02:00
add share button to stream view
This commit is contained in:
5
.changeset/fifty-falcons-join.md
Normal file
5
.changeset/fifty-falcons-join.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"nostrudel": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add share button to stream view
|
@@ -1,12 +1,12 @@
|
|||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import { ButtonProps, IconButton, IconButtonProps } from "@chakra-ui/react";
|
import { ButtonProps, IconButton } from "@chakra-ui/react";
|
||||||
import { Kind } from "nostr-tools";
|
import { Kind } from "nostr-tools";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
import { NostrEvent } from "../../../types/nostr-event";
|
import { NostrEvent } from "../../../types/nostr-event";
|
||||||
import { QuoteRepostIcon } from "../../icons";
|
import { QuoteRepostIcon } from "../../icons";
|
||||||
import { PostModalContext } from "../../../providers/post-modal-provider";
|
import { PostModalContext } from "../../../providers/post-modal-provider";
|
||||||
import { getSharableNoteId } from "../../../helpers/nip19";
|
import { getSharableEventAddress } from "../../../helpers/nip19";
|
||||||
|
|
||||||
export type QuoteRepostButtonProps = Omit<ButtonProps, "children" | "onClick"> & {
|
export type QuoteRepostButtonProps = Omit<ButtonProps, "children" | "onClick"> & {
|
||||||
event: NostrEvent;
|
event: NostrEvent;
|
||||||
@@ -14,24 +14,30 @@ export type QuoteRepostButtonProps = Omit<ButtonProps, "children" | "onClick"> &
|
|||||||
|
|
||||||
export function QuoteRepostButton({
|
export function QuoteRepostButton({
|
||||||
event,
|
event,
|
||||||
"aria-label": ariaLabel = "Quote repost",
|
"aria-label": ariaLabel,
|
||||||
title = "Quote repost",
|
title = "Quote repost",
|
||||||
...props
|
...props
|
||||||
}: QuoteRepostButtonProps) {
|
}: QuoteRepostButtonProps) {
|
||||||
const { openModal } = useContext(PostModalContext);
|
const { openModal } = useContext(PostModalContext);
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
const nevent = getSharableNoteId(event.id);
|
const nevent = getSharableEventAddress(event);
|
||||||
const draft = {
|
const draft = {
|
||||||
kind: Kind.Text,
|
kind: Kind.Text,
|
||||||
tags: [],
|
tags: [],
|
||||||
content: "nostr:" + nevent,
|
content: "\nnostr:" + nevent,
|
||||||
created_at: dayjs().unix(),
|
created_at: dayjs().unix(),
|
||||||
};
|
};
|
||||||
openModal(draft);
|
openModal(draft);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton icon={<QuoteRepostIcon />} onClick={handleClick} aria-label={ariaLabel} title={title} {...props} />
|
<IconButton
|
||||||
|
icon={<QuoteRepostIcon />}
|
||||||
|
onClick={handleClick}
|
||||||
|
aria-label={ariaLabel || title}
|
||||||
|
title={title}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
40
src/views/streams/components/stream-share-button.tsx
Normal file
40
src/views/streams/components/stream-share-button.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { useContext } from "react";
|
||||||
|
import { Button, ButtonProps } from "@chakra-ui/react";
|
||||||
|
import { Kind } from "nostr-tools";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { getSharableEventAddress } from "../../../helpers/nip19";
|
||||||
|
import { DraftNostrEvent } from "../../../types/nostr-event";
|
||||||
|
import { PostModalContext } from "../../../providers/post-modal-provider";
|
||||||
|
import { RepostIcon } from "../../../components/icons";
|
||||||
|
import { ParsedStream } from "../../../helpers/nostr/stream";
|
||||||
|
|
||||||
|
export type StreamShareButtonProps = Omit<ButtonProps, "children" | "onClick"> & {
|
||||||
|
stream: ParsedStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StreamShareButton({
|
||||||
|
stream,
|
||||||
|
"aria-label": ariaLabel,
|
||||||
|
title = "Quote repost",
|
||||||
|
...props
|
||||||
|
}: StreamShareButtonProps) {
|
||||||
|
const { openModal } = useContext(PostModalContext);
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
const nevent = getSharableEventAddress(stream.event);
|
||||||
|
const draft: DraftNostrEvent = {
|
||||||
|
kind: Kind.Text,
|
||||||
|
tags: [],
|
||||||
|
content: "\nnostr:" + nevent,
|
||||||
|
created_at: dayjs().unix(),
|
||||||
|
};
|
||||||
|
openModal(draft);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button leftIcon={<RepostIcon />} onClick={handleClick} aria-label={ariaLabel || title} title={title} {...props}>
|
||||||
|
Share
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
@@ -52,6 +52,7 @@ import TopZappers from "../components/top-zappers";
|
|||||||
import StreamHashtags from "../components/stream-hashtags";
|
import StreamHashtags from "../components/stream-hashtags";
|
||||||
import StreamZapButton from "../components/stream-zap-button";
|
import StreamZapButton from "../components/stream-zap-button";
|
||||||
import StreamGoal from "../components/stream-goal";
|
import StreamGoal from "../components/stream-goal";
|
||||||
|
import StreamShareButton from "../components/stream-share-button";
|
||||||
|
|
||||||
function DesktopStreamPage({ stream }: { stream: ParsedStream }) {
|
function DesktopStreamPage({ stream }: { stream: ParsedStream }) {
|
||||||
useAppTitle(stream.title);
|
useAppTitle(stream.title);
|
||||||
@@ -97,6 +98,7 @@ function DesktopStreamPage({ stream }: { stream: ParsedStream }) {
|
|||||||
</Heading>
|
</Heading>
|
||||||
<StreamStatusBadge stream={stream} fontSize="lg" />
|
<StreamStatusBadge stream={stream} fontSize="lg" />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
|
<StreamShareButton stream={stream} title="Share stream" />
|
||||||
<RelaySelectionButton display={{ base: "none", md: "block" }} />
|
<RelaySelectionButton display={{ base: "none", md: "block" }} />
|
||||||
<StreamDebugButton stream={stream} variant="ghost" />
|
<StreamDebugButton stream={stream} variant="ghost" />
|
||||||
<Button onClick={() => setShowChat((v) => !v)}>{showChat ? "Hide" : "Show"} Chat</Button>
|
<Button onClick={() => setShowChat((v) => !v)}>{showChat ? "Hide" : "Show"} Chat</Button>
|
||||||
@@ -151,6 +153,7 @@ function MobileStreamPage({ stream }: { stream: ParsedStream }) {
|
|||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
|
<StreamShareButton stream={stream} size="sm" />
|
||||||
<Button onClick={showChat.onOpen} size="sm">
|
<Button onClick={showChat.onOpen} size="sm">
|
||||||
Show Chat
|
Show Chat
|
||||||
</Button>
|
</Button>
|
||||||
|
Reference in New Issue
Block a user