This commit is contained in:
smolgrrr 2024-08-16 14:09:40 +10:00
parent 178b95de1d
commit e8e1a51518
11 changed files with 8 additions and 186 deletions

View File

@ -1,4 +1,4 @@
import PostCard from "../modals/NoteCard.jsx"; import PostCard from "../modals/PostCard.jsx";
import { verifyPow } from "../../utils/mine.js"; import { verifyPow } from "../../utils/mine.js";
import { Event } from "nostr-tools"; import { Event } from "nostr-tools";
import NewNoteCard from "../forms/PostFormCard.jsx"; import NewNoteCard from "../forms/PostFormCard.jsx";

View File

@ -4,7 +4,7 @@ import NewNoteCard from "../forms/PostFormCard";
import RepostCard from "../modals/RepostCard"; import RepostCard from "../modals/RepostCard";
import { DEFAULT_DIFFICULTY } from "../../config"; import { DEFAULT_DIFFICULTY } from "../../config";
import { useUniqEvents } from "../../hooks/useUniqEvents"; import { useUniqEvents } from "../../hooks/useUniqEvents";
import PostCard from "../modals/NoteCard"; import PostCard from "../modals/PostCard";
const Home = () => { const Home = () => {
const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY;

View File

@ -1,5 +1,5 @@
import { useState, useCallback } from "react"; import { useState, useCallback } from "react";
import PostCard from "../modals/NoteCard.jsx"; import PostCard from "../modals/PostCard.jsx";
import { Event } from "nostr-tools"; import { Event } from "nostr-tools";
import RepostCard from "../modals/RepostCard.jsx"; import RepostCard from "../modals/RepostCard.jsx";
import { useUniqEvents } from "../../hooks/useUniqEvents.js"; import { useUniqEvents } from "../../hooks/useUniqEvents.js";

View File

@ -5,10 +5,10 @@ import { subNote, subNotesOnce } from '../../utils/subscriptions';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { uniqBy } from '../../utils/otherUtils'; import { uniqBy } from '../../utils/otherUtils';
import { DocumentTextIcon, FolderPlusIcon, DocumentDuplicateIcon, ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline'; import { DocumentTextIcon, FolderPlusIcon, DocumentDuplicateIcon, ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline';
import PostCard from '../modals/NoteCard';
import Placeholder from '../modals/Placeholder'; import Placeholder from '../modals/Placeholder';
import NewNoteCard from '../forms/PostFormCard'; import NewNoteCard from '../forms/PostFormCard';
import RepostNote from '../forms/RepostNote'; import RepostNote from '../forms/RepostNote';
import PostCard from '../modals/PostCard';
type PostType = "" | "Reply" | "Quote" | undefined; type PostType = "" | "Reply" | "Quote" | undefined;

View File

@ -1,89 +0,0 @@
import { FolderIcon, CpuChipIcon } from "@heroicons/react/24/outline";
// import { parseContent } from "../../utils/content";
import { Event, nip19 } from "nostr-tools";
import { getMetadata } from "../../utils/getMetadata";
// import { renderMedia } from "../../utils/FileUpload";
import { getIconFromHash, timeAgo } from "../../utils/cardUtils";
import { verifyPow } from "../../utils/mine";
import { uniqBy } from "../../utils/otherUtils";
import ContentPreview from "./CardModals/TextModal";
import CardContainer from "./CardContainer";
interface CardProps {
key?: string | number;
event: Event;
metadata: Event | null;
replies: Event[];
repliedTo?: Event[]
type?: 'OP' | 'Reply' | 'Post';
}
const PostCard = ({
key,
event,
metadata,
replies,
repliedTo,
type
}: CardProps) => {
// const { files } = parseContent(event);
const icon = getIconFromHash(event.pubkey);
const metadataParsed = metadata ? getMetadata(metadata) : null;
const handleClick = () => {
if (type !== "OP") {
window.location.href = `/thread/${nip19.noteEncode(event.id)}`;
}
};
return (
<CardContainer>
<div className={`flex flex-col gap-2`}>
<div className={`flex flex-col break-words ${type !== "OP" ? 'hover:cursor-pointer' : ''}`} onClick={handleClick}>
<ContentPreview key={event.id} eventdata={event} />
</div>
{repliedTo && <div className="flex items-center mt-1" >
<span className="text-xs text-gray-500">Reply to: </span>
{uniqBy(repliedTo, 'pubkey').map((event, index) => (
<div key={index}>
{event.kind === 0 ? (
<img className={`h-5 w-5 rounded-full`} src={getMetadata(event)?.picture} />
) : (
<div className={`h-4 w-4 ${getIconFromHash(event.pubkey)} rounded-full`} />
)}
</div>
))}
</div>}
<div className={`flex justify-between items-center ${type !== "OP" ? 'hover:cursor-pointer' : ''}`} onClick={handleClick}>
{metadataParsed ?
<img
key = {key}
className={`h-5 w-5 rounded-full`}
src={metadataParsed?.picture ?? icon}
alt=""
loading="lazy"
decoding="async"/>
:
<div className={`h-4 w-4 ${icon} rounded-full`} />
}
<div className="flex items-center ml-auto gap-2.5">
<div className="inline-flex text-xs text-neutral-600 gap-0.5">
<CpuChipIcon className="h-4 w-4" /> {verifyPow(event)}
</div>
<span className="text-neutral-700">·</span>
<div className="text-xs font-semibold text-neutral-600">
{timeAgo(event.created_at)}
</div>
<span className="text-neutral-700">·</span>
<div className="inline-flex items-center gap-1">
<FolderIcon className="h-4 w-4 text-neutral-600" />
<span className="text-xs text-neutral-600">{replies.length}</span>
</div>
</div>
</div>
</div>
</CardContainer>
);
};
export default PostCard;

View File

@ -1,89 +0,0 @@
import { FolderIcon, CpuChipIcon } from "@heroicons/react/24/outline";
// import { parseContent } from "../../utils/content";
import { Event, nip19 } from "nostr-tools";
import { getMetadata } from "../../utils/getMetadata";
// import { renderMedia } from "../../utils/FileUpload";
import { getIconFromHash, timeAgo } from "../../utils/cardUtils";
import { verifyPow } from "../../utils/mine";
import { uniqBy } from "../../utils/otherUtils";
import ContentPreview from "./CardModals/TextModal";
import CardContainer from "./CardContainer";
interface CardProps {
key?: string | number;
event: Event;
metadata: Event | null;
replies: Event[];
repliedTo?: Event[]
type?: 'OP' | 'Reply' | 'Post';
}
const PostCard = ({
key,
event,
metadata,
replies,
repliedTo,
type
}: CardProps) => {
// const { files } = parseContent(event);
const icon = getIconFromHash(event.pubkey);
const metadataParsed = metadata ? getMetadata(metadata) : null;
const handleClick = () => {
if (type !== "OP") {
window.location.href = `/thread/${nip19.noteEncode(event.id)}`;
}
};
return (
<CardContainer>
<div className={`flex flex-col gap-2`}>
<div className={`flex flex-col break-words ${type !== "OP" ? 'hover:cursor-pointer' : ''}`} onClick={handleClick}>
<ContentPreview key={event.id} eventdata={event} />
</div>
{repliedTo && <div className="flex items-center mt-1" >
<span className="text-xs text-gray-500">Reply to: </span>
{uniqBy(repliedTo, 'pubkey').map((event, index) => (
<div key={index}>
{event.kind === 0 ? (
<img className={`h-5 w-5 rounded-full`} src={getMetadata(event)?.picture} />
) : (
<div className={`h-4 w-4 ${getIconFromHash(event.pubkey)} rounded-full`} />
)}
</div>
))}
</div>}
<div className={`flex justify-between items-center ${type !== "OP" ? 'hover:cursor-pointer' : ''}`} onClick={handleClick}>
{metadataParsed ?
<img
key = {key}
className={`h-5 w-5 rounded-full`}
src={metadataParsed?.picture ?? icon}
alt=""
loading="lazy"
decoding="async"/>
:
<div className={`h-4 w-4 ${icon} rounded-full`} />
}
<div className="flex items-center ml-auto gap-2.5">
<div className="inline-flex text-xs text-neutral-600 gap-0.5">
<CpuChipIcon className="h-4 w-4" /> {verifyPow(event)}
</div>
<span className="text-neutral-700">·</span>
<div className="text-xs font-semibold text-neutral-600">
{timeAgo(event.created_at)}
</div>
<span className="text-neutral-700">·</span>
<div className="inline-flex items-center gap-1">
<FolderIcon className="h-4 w-4 text-neutral-600" />
<span className="text-xs text-neutral-600">{replies.length}</span>
</div>
</div>
</div>
</div>
</CardContainer>
);
};
export default PostCard;

View File

@ -1,4 +1,4 @@
import PostCard from "../modals/NoteCard.jsx"; import PostCard from "../modals/PostCard.jsx";
import { verifyPow } from "../../utils/mine.js"; import { verifyPow } from "../../utils/mine.js";
import { Event } from "nostr-tools"; import { Event } from "nostr-tools";
import NewNoteCard from "../forms/PostFormCard.jsx"; import NewNoteCard from "../forms/PostFormCard.jsx";

View File

@ -4,7 +4,7 @@ import NewNoteCard from "../forms/PostFormCard";
import RepostCard from "../modals/RepostCard"; import RepostCard from "../modals/RepostCard";
import { DEFAULT_DIFFICULTY } from "../../config"; import { DEFAULT_DIFFICULTY } from "../../config";
import { useUniqEvents } from "../../hooks/useUniqEvents"; import { useUniqEvents } from "../../hooks/useUniqEvents";
import PostCard from "../modals/NoteCard"; import PostCard from "../modals/PostCard";
const Home = () => { const Home = () => {
const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY;

View File

@ -1,5 +1,5 @@
import { useState, useCallback } from "react"; import { useState, useCallback } from "react";
import PostCard from "../modals/NoteCard.jsx"; import PostCard from "../modals/PostCard.jsx";
import { Event } from "nostr-tools"; import { Event } from "nostr-tools";
import RepostCard from "../modals/RepostCard.jsx"; import RepostCard from "../modals/RepostCard.jsx";
import { useUniqEvents } from "../../hooks/useUniqEvents.js"; import { useUniqEvents } from "../../hooks/useUniqEvents.js";

View File

@ -5,10 +5,10 @@ import { subNote, subNotesOnce } from '../../utils/subscriptions';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { uniqBy } from '../../utils/otherUtils'; import { uniqBy } from '../../utils/otherUtils';
import { DocumentTextIcon, FolderPlusIcon, DocumentDuplicateIcon, ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline'; import { DocumentTextIcon, FolderPlusIcon, DocumentDuplicateIcon, ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline';
import PostCard from '../modals/NoteCard';
import Placeholder from '../modals/Placeholder'; import Placeholder from '../modals/Placeholder';
import NewNoteCard from '../forms/PostFormCard'; import NewNoteCard from '../forms/PostFormCard';
import RepostNote from '../forms/RepostNote'; import RepostNote from '../forms/RepostNote';
import PostCard from '../modals/PostCard';
type PostType = "" | "Reply" | "Quote" | undefined; type PostType = "" | "Reply" | "Quote" | undefined;