import React, { useState, useEffect } from "react"; import { checkForLUDS, convertDate, getParsedRepEvent, minimizeKey, removeDuplicants, } from "@/Helpers/Encryptions"; import Date_ from "@/Components/Date_"; import UserProfilePic from "@/Components/UserProfilePic"; import LoadingDots from "@/Components/LoadingDots"; import ZapTip from "@/Components/ZapTip"; import ShowUsersList from "@/Components/ShowUsersList"; import RepEventPreviewCard from "@/Components/RepEventPreviewCard"; import CheckNOSTRClient from "@/Components/CheckNOSTRClient"; import { useDispatch, useSelector } from "react-redux"; import { setToast } from "@/Store/Slides/Publishers"; import { getSubData } from "@/Helpers/Controlers"; import { saveUsers } from "@/Helpers/DB"; import useRepEventStats from "@/Hooks/useRepEventStats"; import Follow from "@/Components/Follow"; import RepEventCommentsSection from "@/Components/RepEventCommentsSection"; import Backbar from "@/Components/Backbar"; import DynamicIndicator from "@/Components/DynamicIndicator"; import { useTranslation } from "react-i18next"; import PagePlaceholder from "@/Components/PagePlaceholder"; import ZapAd from "@/Components/ZapAd"; import EventOptions from "@/Components/ElementOptions/EventOptions"; import useIsMute from "@/Hooks/useIsMute"; import Link from "next/link"; import PostReaction from "@/Components/PostReaction"; export default function Curation({ event, userProfile }) { const { t } = useTranslation(); const dispatch = useDispatch(); const userKeys = useSelector((state) => state.userKeys); const [isArtsLoaded, setIsArtsLoaded] = useState(false); const curation = event; const [articlesOnCuration, setArticlesOnCuration] = useState([]); const [usersList, setUsersList] = useState(false); const [showCommentsSection, setShowCommentsSections] = useState(false); const [morePosts, setMorePosts] = useState([]); const { muteUnmute, isMuted } = useIsMute(curation.pubkey); const { postActions } = useRepEventStats(curation?.aTag, curation?.pubkey); useEffect(() => { const fetchData = async () => { try { let authPubkeys = removeDuplicants( getAuthPubkeys(curation?.tags || []) ); saveUsers(authPubkeys); let dRefs = getDRef(curation?.tags || []); if (dRefs.length === 0) setIsArtsLoaded(true); let data = await getSubData( [ { kinds: curation.kind === 30004 ? [30023] : [34235, 21, 22], "#d": dRefs, }, ], 100 ); let posts = sortPostsOnCuration( dRefs, data.data.map((post) => getParsedRepEvent(post)) ); setArticlesOnCuration(posts); setIsArtsLoaded(true); } catch (err) { console.log(err); dispatch( setToast({ type: 2, desc: t("AAZJZMU"), }) ); return; } }; if (curation) fetchData(); }, []); useEffect(() => { const fetchMoreCurations = async () => { try { let data = await getSubData( [ { kinds: [30004, 30005], limit: 5, }, ], 100 ); let posts = data.data .splice(0, 5) .map((event) => getParsedRepEvent(event)) .filter((_) => _.id !== curation.id); setMorePosts(posts); saveUsers(data.pubkeys); } catch (err) { console.log(err); } }; fetchMoreCurations(); }, []); const getDRef = (tags) => { let tempArray = []; for (let tag of tags) { if (tag[0] === "a") { tempArray.push(tag[1].split(":").splice(2, 100).join(":")); } } return tempArray; }; const getAuthPubkeys = (tags) => { let tempArray = []; for (let tag of tags) { if (tag[0] === "a") { tempArray.push(tag[1].split(":")[1]); } } return tempArray; }; const sortPostsOnCuration = (original, toSort) => { let tempArray = []; for (let post of original) { tempArray.push(toSort.find((item) => item.d === post)); } return tempArray.filter((item) => item); }; return ( <> {usersList && ( setUsersList(false)} title={usersList.title} list={usersList.list} extras={usersList.extras} extrasType={usersList.extrasType} /> )}
{isMuted && ( )} {!isMuted && (
{showCommentsSection && ( setShowCommentsSections(false)} kind={curation.kind} event={curation} /> )} {!showCommentsSection && ( <>

{t("AVG3Uga")}

{userProfile.display_name || userProfile.name || minimizeKey(curation.pubkey)}

{curation.title}

{t("AHhPGax", { date: convertDate( new Date(curation.published_at * 1000) ), })}

{curation.description && (
{curation.description}
)}
{curation.image && (
)}
{!articlesOnCuration.length && !isArtsLoaded && (

{t("AKvHyxG")}

)} {articlesOnCuration.length > 0 && isArtsLoaded && (

{t("A04okTg", { count: articlesOnCuration.length, })}

)}
0 ? "1px solid var(--very-dim-gray)" : "", }} > {articlesOnCuration.length > 0 && (
{articlesOnCuration.map((item, index) => { return ( ); })}
)} {articlesOnCuration.length === 0 && isArtsLoaded && (

{t("AghKyAt")}

)}
{morePosts.length > 0 && (

{t("Aag9u1h")}

{morePosts.map((curation_) => { if ( curation_.id !== curation.id && curation_.items.length > 0 ) return (

{curation_.title || t("AMvUjqZ")}

); })}
)} )}
)}
{!showCommentsSection && !isMuted && (
{postActions?.zaps?.zaps?.length > 0 && (
setUsersList({ title: t("AVDZ5cJ"), list: postActions.zaps.zaps.map((item) => item.pubkey), extras: postActions.zaps.zaps, }) } margin={false} />
)}
setShowCommentsSections({ comment: false }) } setOpenComment={() => setShowCommentsSections({ comment: true }) } />
)}
); }