From 94a0c9c4c387b27ce3ba15c3828bcf53418154a2 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Tue, 22 Aug 2023 14:50:55 -0500 Subject: [PATCH] add note link to lightbox slide --- src/components/lightbox-provider.tsx | 58 +++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/components/lightbox-provider.tsx b/src/components/lightbox-provider.tsx index ac5078b82..e0091bb57 100644 --- a/src/components/lightbox-provider.tsx +++ b/src/components/lightbox-provider.tsx @@ -10,10 +10,11 @@ import { useRef, useState, } from "react"; -import { useDisclosure } from "@chakra-ui/react"; +import { Button, Flex, FlexProps, Spacer, useDisclosure } from "@chakra-ui/react"; import { useUnmount } from "react-use"; +import { Link as RouterLink } from "react-router-dom"; -import Lightbox, { Slide } from "yet-another-react-lightbox"; +import Lightbox, { RenderSlideContainerProps, Slide } from "yet-another-react-lightbox"; import Zoom from "yet-another-react-lightbox/plugins/zoom"; import Counter from "yet-another-react-lightbox/plugins/counter"; import Download from "yet-another-react-lightbox/plugins/download"; @@ -29,6 +30,11 @@ declare module "yet-another-react-lightbox" { } import { NostrEvent } from "../types/nostr-event"; +import { UserAvatarLink } from "./user-avatar-link"; +import { UserLink } from "./user-link"; +import { UserDnsIdentityIcon } from "./user-dns-identity-icon"; +import styled from "@emotion/styled"; +import { getSharableNoteId } from "../helpers/nip19"; type RefType = MutableRefObject; @@ -94,19 +100,38 @@ function getRefPath(ref: RefType) { return path; } -// function EventSlideHeader({ event }: { event: NostrEvent }) { -// return ( -// -// -// -// -// -// -// {dayjs.unix(event.created_at).fromNow()} -// -// -// ); -// } +function EventSlideHeader({ event, ...props }: { event: NostrEvent } & Omit) { + const encoded = useMemo(() => getSharableNoteId(event.id), [event.id]); + + return ( + + + + + + + + ); +} + +const StyledContainer = styled(Flex)` + & > .yarl__fullsize { + overflow: hidden; + } +`; +export function CustomSlideContainer({ slide, children }: RenderSlideContainerProps) { + if (slide.event) { + return ( + + + {children} + + ); + } + return <>{children}; +} export function LightboxProvider({ children }: PropsWithChildren) { const lightbox = useDisclosure(); @@ -179,6 +204,9 @@ export function LightboxProvider({ children }: PropsWithChildren) { zoom={{ scrollToZoom: true, maxZoomPixelRatio: 4, wheelZoomDistanceFactor: 500 }} controller={{ closeOnBackdropClick: true, closeOnPullDown: true }} on={{ view: handleView }} + render={{ + slideContainer: CustomSlideContainer, + }} /> );