From 713f4c3d5ef66f82dd9901c2e1b61508a9437db8 Mon Sep 17 00:00:00 2001 From: Alejandro Gomez Date: Wed, 28 Jun 2023 08:43:33 +0200 Subject: [PATCH] feat: responsible zap modal --- src/element/new-stream.css | 19 ------------------ src/element/new-stream.tsx | 14 ++++++------- src/element/send-zap.css | 3 +-- src/element/send-zap.tsx | 41 +++++++++++++++++++++++++++++--------- src/pages/layout.css | 19 ++++++++++++++++++ src/pages/root.css | 5 +++++ src/pages/stream-page.tsx | 36 ++++++++++----------------------- 7 files changed, 74 insertions(+), 63 deletions(-) diff --git a/src/element/new-stream.css b/src/element/new-stream.css index 629fd25..0c1ef08 100644 --- a/src/element/new-stream.css +++ b/src/element/new-stream.css @@ -49,22 +49,3 @@ color: inherit; background: #353535; } - -.dialog-overlay { - background-color: rgba(0, 0, 0, 0.8); - position: fixed; - inset: 0; -} - -.dialog-content { - background-color: #171717; - border-radius: 6px; - position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - width: 90vw; - max-width: 450px; - max-height: 85vh; - padding: 25px; -} diff --git a/src/element/new-stream.tsx b/src/element/new-stream.tsx index 6ef9bfc..494a7f9 100644 --- a/src/element/new-stream.tsx +++ b/src/element/new-stream.tsx @@ -1,7 +1,7 @@ import "./new-stream.css"; import * as Dialog from "@radix-ui/react-dialog"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useCallback } from "react"; import { EventPublisher, NostrEvent } from "@snort/system"; import { unixNow } from "@snort/shared"; @@ -15,7 +15,7 @@ export function NewStream({ onFinish, }: { ev?: NostrEvent; - onFinish: (ev: NostrEvent) => void; + onFinish?: (ev: NostrEvent) => void; }) { const [title, setTitle] = useState(findTag(ev, "title") ?? ""); const [summary, setSummary] = useState(findTag(ev, "summary") ?? ""); @@ -27,7 +27,7 @@ export function NewStream({ const [start, setStart] = useState(findTag(ev, "starts")); const [isValid, setIsValid] = useState(false); - function validate() { + const validate = useCallback(() => { if (title.length < 2) { return false; } @@ -38,11 +38,11 @@ export function NewStream({ return false; } return true; - } + }, [title, image, stream]); useEffect(() => { setIsValid(validate()); - }, [title, summary, image, stream]); + }, [validate, title, summary, image, stream]); async function publishStream() { const pub = await EventPublisher.nip7(); @@ -67,7 +67,7 @@ export function NewStream({ }); console.debug(evNew); System.BroadcastEvent(evNew); - onFinish(evNew); + onFinish && onFinish(evNew); } } @@ -174,7 +174,7 @@ interface NewStreamDialogProps { text?: string; btnClassName?: string; ev?: NostrEvent; - onFinish: (e: NostrEvent) => void; + onFinish?: (e: NostrEvent) => void; } export function NewStreamDialog({ diff --git a/src/element/send-zap.css b/src/element/send-zap.css index 6a5b46f..96ebb75 100644 --- a/src/element/send-zap.css +++ b/src/element/send-zap.css @@ -1,5 +1,4 @@ .send-zap { - width: inherit; display: flex; gap: 24px; flex-direction: column; @@ -58,4 +57,4 @@ .send-zap .qr { align-self: center; -} \ No newline at end of file +} diff --git a/src/element/send-zap.tsx b/src/element/send-zap.tsx index 87b8de8..84257f0 100644 --- a/src/element/send-zap.tsx +++ b/src/element/send-zap.tsx @@ -1,4 +1,5 @@ import "./send-zap.css"; +import * as Dialog from "@radix-ui/react-dialog"; import { useEffect, useState } from "react"; import { LNURL } from "@snort/shared"; import { NostrEvent, EventPublisher } from "@snort/system"; @@ -9,17 +10,14 @@ import { findTag } from "utils"; import { Relays } from "index"; import QrCode from "./qr-code"; -export function SendZaps({ - lnurl, - ev, - targetName, - onFinish, -}: { +interface SendZapsProps { lnurl: string; ev?: NostrEvent; targetName?: string; onFinish: () => void; -}) { +} + +function SendZaps({ lnurl, ev, targetName, onFinish }: SendZapsProps) { const UsdRate = 30_000; const satsAmounts = [ @@ -152,6 +150,31 @@ export function SendZaps({ ); } -function SendZapDialog() { - return "TODO"; +export function SendZapsDialog({ + lnurl, + ev, + targetName, +}: Omit) { + const [isOpen, setIsOpen] = useState(false); + return ( + + + + + + + + setIsOpen(false)} + /> + + + + ); } diff --git a/src/pages/layout.css b/src/pages/layout.css index 0564fe7..2d207bc 100644 --- a/src/pages/layout.css +++ b/src/pages/layout.css @@ -162,3 +162,22 @@ button span.hide-on-mobile { height: 100vh; width: 100vw; } + +.dialog-overlay { + background-color: rgba(0, 0, 0, 0.8); + position: fixed; + inset: 0; +} + +.dialog-content { + background-color: #171717; + border-radius: 6px; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 90vw; + max-width: 450px; + max-height: 85vh; + padding: 25px; +} diff --git a/src/pages/root.css b/src/pages/root.css index a8c5b2c..c96e21a 100644 --- a/src/pages/root.css +++ b/src/pages/root.css @@ -35,6 +35,11 @@ } } +.homepage { + width: 100%; + grid-area: main-content; +} + .homepage h2 { background: #171717; padding: 40px; diff --git a/src/pages/stream-page.tsx b/src/pages/stream-page.tsx index 334bf42..4db320d 100644 --- a/src/pages/stream-page.tsx +++ b/src/pages/stream-page.tsx @@ -1,5 +1,5 @@ import "./stream-page.css"; -import { useRef, useState } from "react"; +import { useRef } from "react"; import { parseNostrLink, EventPublisher } from "@snort/system"; import { useNavigate, useParams } from "react-router-dom"; import moment from "moment"; @@ -10,11 +10,9 @@ import { findTag } from "utils"; import { Profile, getName } from "element/profile"; import { LiveChat } from "element/live-chat"; import AsyncButton from "element/async-button"; -import { Icon } from "element/icon"; import { useLogin } from "hooks/login"; import { StreamState, System } from "index"; -import Modal from "element/modal"; -import { SendZaps } from "element/send-zap"; +import { SendZapsDialog } from "element/send-zap"; import type { NostrLink } from "@snort/system"; import { useUserProfile } from "@snort/system-react"; import { NewStreamDialog } from "element/new-stream"; @@ -23,7 +21,6 @@ function ProfileInfo({ link }: { link: NostrLink }) { const thisEvent = useEventFeed(link, true); const login = useLogin(); const navigate = useNavigate(); - const [zap, setZap] = useState(false); const profile = useUserProfile(System, thisEvent.data?.pubkey); const zapTarget = profile?.lud16 ?? profile?.lud06; @@ -42,8 +39,6 @@ function ProfileInfo({ link }: { link: NostrLink }) { } } - function onFinish() {} - return ( <>
@@ -69,11 +64,7 @@ function ProfileInfo({ link }: { link: NostrLink }) { {isMine && (
{thisEvent.data && ( - + )}
- + {zapTarget && thisEvent.data && ( + + )}
- {zap && zapTarget && thisEvent.data && ( - setZap(false)}> - setZap(false)} - /> - - )} ); }