2024-04-01 18:13:38 -05:00
|
|
|
"use client";
|
2024-03-16 14:56:58 -05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useNostr } from '@/hooks/useNostr';
|
2024-03-16 16:37:47 -05:00
|
|
|
import { parseEvent, findKind0Fields, hexToNpub } from '@/utils/nostr';
|
2024-03-16 14:56:58 -05:00
|
|
|
import { useImageProxy } from '@/hooks/useImageProxy';
|
2024-03-16 16:37:47 -05:00
|
|
|
import { Button } from 'primereact/button';
|
|
|
|
import { Tag } from 'primereact/tag';
|
2024-03-16 14:56:58 -05:00
|
|
|
import Image from 'next/image';
|
2024-04-01 18:13:38 -05:00
|
|
|
import dynamic from 'next/dynamic';
|
2024-03-16 14:56:58 -05:00
|
|
|
import 'primeicons/primeicons.css';
|
|
|
|
|
2024-03-19 12:32:05 -05:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
import rehypeRaw from 'rehype-raw';
|
|
|
|
|
|
|
|
const MarkdownContent = ({ content }) => {
|
|
|
|
return (
|
|
|
|
<div>
|
2024-03-19 13:04:46 -05:00
|
|
|
<ReactMarkdown rehypePlugins={[rehypeRaw]} className='markdown-content'>
|
2024-03-19 12:32:05 -05:00
|
|
|
{content}
|
|
|
|
</ReactMarkdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-04-01 18:13:38 -05:00
|
|
|
const BitcoinConnectPayButton = dynamic(
|
|
|
|
() => import('@getalby/bitcoin-connect-react').then((mod) => mod.PayButton),
|
|
|
|
{
|
|
|
|
ssr: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-03-16 14:56:58 -05:00
|
|
|
export default function Details() {
|
|
|
|
const [event, setEvent] = useState(null);
|
|
|
|
const [processedEvent, setProcessedEvent] = useState({});
|
2024-03-16 16:37:47 -05:00
|
|
|
const [author, setAuthor] = useState(null);
|
2024-04-01 18:13:38 -05:00
|
|
|
const [bitcoinConnect, setBitcoinConnect] = useState(false);
|
2024-03-16 14:56:58 -05:00
|
|
|
|
|
|
|
const { returnImageProxy } = useImageProxy();
|
2024-03-27 18:12:17 -05:00
|
|
|
const { fetchSingleEvent, fetchKind0, zapEvent } = useNostr();
|
2024-03-16 14:56:58 -05:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
2024-03-27 18:12:17 -05:00
|
|
|
const handleZapEvent = async () => {
|
|
|
|
if (!event) return;
|
|
|
|
|
|
|
|
const response = await zapEvent(event);
|
|
|
|
|
|
|
|
console.log('zap response:', response);
|
|
|
|
}
|
|
|
|
|
2024-04-01 18:13:38 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (typeof window === 'undefined') return;
|
|
|
|
|
|
|
|
const bitcoinConnectConfig = window.localStorage.getItem('bc:config');
|
|
|
|
|
|
|
|
if (bitcoinConnectConfig) {
|
|
|
|
setBitcoinConnect(true);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2024-03-16 14:56:58 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (router.isReady) {
|
|
|
|
const { slug } = router.query;
|
|
|
|
|
|
|
|
const fetchEvent = async (slug) => {
|
|
|
|
const event = await fetchSingleEvent(slug);
|
|
|
|
if (event) {
|
|
|
|
setEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchEvent(slug);
|
|
|
|
}
|
|
|
|
}, [router.isReady, router.query]);
|
|
|
|
|
2024-03-16 16:37:47 -05:00
|
|
|
useEffect(() => {
|
|
|
|
const fetchAuthor = async (pubkey) => {
|
2024-04-20 17:42:00 -05:00
|
|
|
const author = await fetchKind0(pubkey);
|
2024-03-16 16:37:47 -05:00
|
|
|
const fields = await findKind0Fields(author);
|
2024-04-20 17:42:00 -05:00
|
|
|
console.log('fields:', fields);
|
2024-03-16 16:37:47 -05:00
|
|
|
if (fields) {
|
|
|
|
setAuthor(fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event) {
|
|
|
|
fetchAuthor(event.pubkey);
|
|
|
|
}
|
2024-04-20 17:42:00 -05:00
|
|
|
}, [fetchKind0, event]);
|
2024-03-16 16:37:47 -05:00
|
|
|
|
2024-03-16 14:56:58 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (event) {
|
2024-03-16 16:37:47 -05:00
|
|
|
const { id, pubkey, content, title, summary, image, published_at } = parseEvent(event);
|
|
|
|
setProcessedEvent({ id, pubkey, content, title, summary, image, published_at });
|
2024-03-16 14:56:58 -05:00
|
|
|
}
|
|
|
|
}, [event]);
|
|
|
|
|
|
|
|
return (
|
2024-03-19 13:04:46 -05:00
|
|
|
<div className='w-full px-24 pt-12 mx-auto mt-4 max-tab:px-0 max-mob:px-0 max-tab:pt-2 max-mob:pt-2'>
|
|
|
|
<div className='w-full flex flex-row justify-between max-tab:flex-col max-mob:flex-col'>
|
|
|
|
{/* <i className='pi pi-arrow-left pl-8 cursor-pointer hover:opacity-75 max-tab:pl-2 max-mob:pl-2' onClick={() => router.push('/')} /> */}
|
|
|
|
<div className='w-[75vw] mx-auto flex flex-row items-start justify-between max-tab:flex-col max-mob:flex-col max-tab:w-[95vw] max-mob:w-[95vw]'>
|
|
|
|
<div className='flex flex-col items-start max-w-[45vw] max-tab:max-w-[100vw] max-mob:max-w-[100vw]'>
|
2024-03-19 12:32:05 -05:00
|
|
|
<div className='pt-2 flex flex-row justify-start w-full'>
|
|
|
|
<Tag className='mr-2' value="Primary"></Tag>
|
|
|
|
<Tag className='mr-2' severity="success" value="Success"></Tag>
|
|
|
|
<Tag className='mr-2' severity="info" value="Info"></Tag>
|
|
|
|
<Tag className='mr-2' severity="warning" value="Warning"></Tag>
|
|
|
|
<Tag className='mr-2' severity="danger" value="Danger"></Tag>
|
|
|
|
</div>
|
|
|
|
<h1 className='text-4xl mt-6'>{processedEvent?.title}</h1>
|
|
|
|
<p className='text-xl mt-6'>{processedEvent?.summary}</p>
|
|
|
|
<div className='flex flex-row w-full mt-6 items-center'>
|
|
|
|
<Image
|
|
|
|
alt="resource thumbnail"
|
|
|
|
src={returnImageProxy(author?.avatar)}
|
|
|
|
width={50}
|
|
|
|
height={50}
|
|
|
|
className="rounded-full mr-4"
|
|
|
|
/>
|
|
|
|
<p className='text-lg'>
|
|
|
|
Created by{' '}
|
|
|
|
<a rel='noreferrer noopener' target='_blank' className='text-blue-500 hover:underline'>
|
|
|
|
{author?.username}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-19 13:04:46 -05:00
|
|
|
<div className='flex flex-col max-tab:mt-12 max-mob:mt-12'>
|
2024-03-19 12:32:05 -05:00
|
|
|
{processedEvent && (
|
|
|
|
<div className='flex flex-col items-center justify-between rounded-lg h-72 p-4 bg-gray-700 drop-shadow-md'>
|
|
|
|
<Image
|
|
|
|
alt="resource thumbnail"
|
|
|
|
src={returnImageProxy(processedEvent.image)}
|
|
|
|
width={344}
|
|
|
|
height={194}
|
|
|
|
className="object-cover object-center rounded-lg"
|
|
|
|
/>
|
2024-04-01 18:13:38 -05:00
|
|
|
{bitcoinConnect ? (
|
|
|
|
<BitcoinConnectPayButton onClick={handleZapEvent} />
|
|
|
|
) : (
|
|
|
|
|
|
|
|
<Button
|
|
|
|
icon="pi pi-bolt"
|
|
|
|
label="Zap"
|
|
|
|
severity="success"
|
|
|
|
outlined
|
|
|
|
onClick={handleZapEvent}
|
|
|
|
pt={{
|
|
|
|
button: {
|
|
|
|
icon: ({ context }) => ({
|
|
|
|
className: 'bg-yellow-500'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2024-03-19 12:32:05 -05:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-03-16 16:37:47 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-28 20:11:51 -05:00
|
|
|
<div className='w-[75vw] mx-auto mt-12 p-12 border-t-2 border-gray-300 max-tab:p-0 max-mob:p-0 max-tab:max-w-[100vw] max-mob:max-w-[100vw]'>
|
2024-03-19 13:04:46 -05:00
|
|
|
{
|
2024-03-19 12:32:05 -05:00
|
|
|
processedEvent?.content && <MarkdownContent content={processedEvent.content} />
|
|
|
|
}
|
2024-03-16 14:56:58 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|