Skip to content

Commit

Permalink
Add tools menu under thread post
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Nov 15, 2024
1 parent 0438f3e commit b7bf4a3
Show file tree
Hide file tree
Showing 13 changed files with 517 additions and 283 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-fishes-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostrudel": minor
---

Add tools menu under thread post
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@codemirror/autocomplete": "^6.18.3",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/language": "^6.10.3",
"@codemirror/view": "^6.34.2",
"@codemirror/view": "^6.34.3",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@fedimint/core-web": "^0.0.7",
Expand Down Expand Up @@ -114,7 +114,7 @@
"workbox-core": "7.0.0",
"workbox-precaching": "7.0.0",
"workbox-routing": "7.0.0",
"yet-another-react-lightbox": "^3.21.6",
"yet-another-react-lightbox": "^3.21.7",
"zen-observable": "^0.10.0"
},
"devDependencies": {
Expand Down
314 changes: 157 additions & 157 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/lightning/inline-invoice-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function InlineInvoiceCard({

if (!invoice) return <>Loading Invoice...</>;

const isExpired = dayjs(invoice.expiry).isBefore(dayjs());
const isExpired = dayjs.unix(invoice.expiry).isBefore(dayjs());

return (
<Flex
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function InlineInvoiceCard({
</Box>
<Box>
<Text color={isExpired ? "red.400" : undefined}>
{isExpired ? "Expired" : "Expires"}: {dayjs(invoice.expiry).fromNow()}
{isExpired ? "Expired" : "Expires"}: {dayjs.unix(invoice.expiry).fromNow()}
</Text>
</Box>
<ButtonGroup variant="outline">
Expand Down
2 changes: 1 addition & 1 deletion src/components/note/note-zap-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, ButtonProps, IconButton, useDisclosure } from "@chakra-ui/react";
import { getZapSender } from "applesauce-core/helpers";

import { readablizeSats } from "../../helpers/bolt11";
import { totalZaps } from "../../helpers/nostr/zaps";
Expand All @@ -11,7 +12,6 @@ import ZapModal from "../event-zap-modal";
import useUserLNURLMetadata from "../../hooks/use-user-lnurl-metadata";
import { getEventUID } from "../../helpers/nostr/event";
import { useReadRelays } from "../../hooks/use-client-relays";
import { getZapSender } from "applesauce-core/helpers";

export type NoteZapButtonProps = Omit<ButtonProps, "children"> & {
event: NostrEvent;
Expand Down
20 changes: 20 additions & 0 deletions src/queries/dvm-responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Query } from "applesauce-core";
import { NostrEvent } from "nostr-tools";
import { scan } from "rxjs/operators";

export default function DVMResponsesQuery(request: NostrEvent): Query<Record<string, NostrEvent>> {
return {
key: request.id,
run: (events) =>
events.stream([{ kinds: [request.kind + 1000, 7000], "#e": [request.id] }]).pipe(
scan(
(byPubkey, event) => {
if (byPubkey[event.pubkey] && byPubkey[event.pubkey].created_at > event.created_at) return byPubkey;

return { ...byPubkey, [event.pubkey]: event };
},
{} as Record<string, NostrEvent>,
),
),
};
}
65 changes: 43 additions & 22 deletions src/views/discovery/dvm-feed/components/feed-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ import {
CardBody,
CardHeader,
Code,
Flex,
Heading,
Spinner,
Text,
} from "@chakra-ui/react";
import dayjs from "dayjs";
import { NostrEvent } from "nostr-tools";
import { getTagValue } from "applesauce-core/helpers";
import { AddressPointer } from "nostr-tools/nip19";

import {
ChainedDVMJob,
DVM_CONTENT_DISCOVERY_JOB_KIND,
getJobStatusType,
getResponseFromDVM,
} from "../../../../helpers/nostr/dvm";
import { ChainedDVMJob, DVM_CONTENT_DISCOVERY_JOB_KIND, getResponseFromDVM } from "../../../../helpers/nostr/dvm";
import { DraftNostrEvent } from "../../../../types/nostr-event";
import { useReadRelays } from "../../../../hooks/use-client-relays";
import { DVMAvatarLink } from "./dvm-avatar";
import DVMLink from "./dvm-name";
import { AddressPointer } from "nostr-tools/nip19";
import useUserMailboxes from "../../../../hooks/use-user-mailboxes";
import { usePublishEvent } from "../../../../providers/global/publish-provider";
import InlineInvoiceCard from "../../../../components/lightning/inline-invoice-card";
import UserAvatar from "../../../../components/user/user-avatar";
import UserLink from "../../../../components/user/user-link";
import UserDnsIdentity from "../../../../components/user/user-dns-identity";
import DebugEventButton from "../../../../components/debug-modal/debug-event-button";
import NoteZapButton from "../../../../components/note/note-zap-button";

function NextPageButton({ chain, pointer }: { pointer: AddressPointer; chain: ChainedDVMJob[] }) {
const publish = usePublishEvent();
Expand Down Expand Up @@ -68,21 +71,31 @@ function NextPageButton({ chain, pointer }: { pointer: AddressPointer; chain: Ch
);
}

export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[]; pointer: AddressPointer }) {
const lastJob = chain[chain.length - 1];
const response = lastJob.responses.find((r) => r.pubkey === pointer.pubkey);
if (response?.result) return <NextPageButton pointer={pointer} chain={chain} />;

export function DVMStatusCard({ status, pointer }: { status?: NostrEvent; pointer?: AddressPointer }) {
const cardProps = { w: "full", maxW: "2xl", mx: "auto", overflow: "hidden" };
const cardHeader = (
<CardHeader p="4" alignItems="center" display="flex" gap="2">
<DVMAvatarLink pointer={pointer} w="12" />
<DVMLink pointer={pointer} fontWeight="bold" fontSize="lg" />
{pointer ? (
<>
<DVMAvatarLink pointer={pointer} w="12" />
<DVMLink pointer={pointer} fontWeight="bold" fontSize="lg" />
</>
) : (
status && (
<>
<UserAvatar pubkey={status.pubkey} size="md" />
<Flex direction="column">
<UserLink pubkey={status.pubkey} fontWeight="bold" fontSize="lg" />
<UserDnsIdentity pubkey={status.pubkey} />
</Flex>
</>
)
)}
{status && <DebugEventButton ml="auto" event={status} size="sm" variant="ghost" />}
</CardHeader>
);

const statusEvent = response?.status;
if (!statusEvent)
if (!status)
return (
<Card {...cardProps}>
{cardHeader}
Expand All @@ -93,16 +106,16 @@ export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[];
</Card>
);

const statusType = getJobStatusType(lastJob, pointer.pubkey);
const statusType = getTagValue(status, "status");
switch (statusType) {
case "payment-required":
const [_, msats, invoice] = statusEvent.tags.find((t) => t[0] === "amount") ?? [];
const [_, msats, invoice] = status.tags.find((t) => t[0] === "amount") ?? [];

return (
<Card {...cardProps}>
{cardHeader}
<CardBody px="4" pb="4" pt="0" gap="2" display="flex" flexDirection="column">
<Heading size="sm">{statusEvent.content}</Heading>
<Heading size="sm">{status.content}</Heading>
{invoice && <InlineInvoiceCard paymentRequest={invoice} />}
</CardBody>
</Card>
Expand All @@ -113,7 +126,7 @@ export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[];
<AlertIcon boxSize={8} />
<Box>
<AlertTitle>Processing</AlertTitle>
<AlertDescription>{statusEvent.content}</AlertDescription>
<AlertDescription>{status.content}</AlertDescription>
</Box>
</Alert>
);
Expand All @@ -123,7 +136,7 @@ export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[];
<AlertIcon boxSize={8} />
<Box>
<AlertTitle>Error!</AlertTitle>
<AlertDescription>{statusEvent.content}</AlertDescription>
<AlertDescription>{status.content}</AlertDescription>
</Box>
</Alert>
);
Expand All @@ -133,8 +146,16 @@ export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[];
<Text>
Unknown status <Code>{statusType}</Code>
</Text>
<Text>{statusEvent.content}</Text>
<Text>{status.content}</Text>
</>
);
}
}

export default function FeedStatus({ chain, pointer }: { chain: ChainedDVMJob[]; pointer: AddressPointer }) {
const lastJob = chain[chain.length - 1];
const response = lastJob.responses.find((r) => r.pubkey === pointer.pubkey);
if (response?.result) return <NextPageButton pointer={pointer} chain={chain} />;

return <DVMStatusCard status={response?.status} pointer={pointer} />;
}
Loading

0 comments on commit b7bf4a3

Please sign in to comment.