mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 09:21:25 +00:00
add pinned posts
This commit is contained in:
parent
325edbee8b
commit
5661d9da0e
@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import PostCard from "./Modals/NoteCard";
|
import PostCard from "./Modals/NoteCard";
|
||||||
import { uniqBy } from "../utils/otherUtils"; // Assume getPow is a correct import now
|
import { uniqBy } from "../utils/otherUtils"; // Assume getPow is a correct import now
|
||||||
import { subBoardFeed } from "../utils/subscriptions";
|
import { subBoardFeed, subProfile} from "../utils/subscriptions";
|
||||||
import { verifyPow } from "../utils/mine";
|
import { verifyPow } from "../utils/mine";
|
||||||
import { Event, nip19 } from "nostr-tools";
|
import { Event, nip19 } from "nostr-tools";
|
||||||
import NewNoteCard from "./Forms/PostFormCard";
|
import NewNoteCard from "./Forms/PostFormCard";
|
||||||
@ -26,8 +26,9 @@ const Board = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]);
|
const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]);
|
||||||
console.log(events[events.length])
|
console.log(events)
|
||||||
const unsubscribe = subBoardFeed(pubkey, onEvent);
|
const unsubscribe = subBoardFeed(pubkey, onEvent);
|
||||||
|
subProfile(pubkey, onEvent)
|
||||||
|
|
||||||
return unsubscribe;
|
return unsubscribe;
|
||||||
}, [pubkey]);
|
}, [pubkey]);
|
||||||
@ -58,6 +59,8 @@ const Board = () => {
|
|||||||
sortByTime ? b.created_at - a.created_at : verifyPow(b) - verifyPow(a)
|
sortByTime ? b.created_at - a.created_at : verifyPow(b) - verifyPow(a)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pinnedEvents = uniqEvents.filter(event => event.pubkey === pubkey && !event.tags.some((tag) => tag[0] === "e"));
|
||||||
|
|
||||||
if (delayedSort) {
|
if (delayedSort) {
|
||||||
sortedEvents = sortedEvents.filter(
|
sortedEvents = sortedEvents.filter(
|
||||||
!setAnon ? (e) => !metadataEvents.some((metadataEvent) => metadataEvent.pubkey === e.pubkey) : () => true
|
!setAnon ? (e) => !metadataEvents.some((metadataEvent) => metadataEvent.pubkey === e.pubkey) : () => true
|
||||||
@ -94,6 +97,15 @@ const Board = () => {
|
|||||||
</div>
|
</div>
|
||||||
<OptionsBar sortByTime={sortByTime} setAnon={setAnon} toggleSort={toggleSort} toggleAnon={toggleAnon} />
|
<OptionsBar sortByTime={sortByTime} setAnon={setAnon} toggleSort={toggleSort} toggleAnon={toggleAnon} />
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-4 p-4">
|
<div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-4 p-4">
|
||||||
|
{pinnedEvents.map((event) => (
|
||||||
|
<div className="rounded-lg border border-red-900">
|
||||||
|
<PostCard
|
||||||
|
event={event}
|
||||||
|
metadata={metadataEvents.find((e) => e.pubkey === event.pubkey && e.kind === 0) || null}
|
||||||
|
replyCount={countReplies(event)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
{sortedEvents.map((event) => (
|
{sortedEvents.map((event) => (
|
||||||
event.kind === 1 ?
|
event.kind === 1 ?
|
||||||
<PostCard
|
<PostCard
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
export const DefaultBoards = [
|
export const DefaultBoards = [
|
||||||
['Politically Incorrect', 'npub19znf32s8s7qpkpfrck0suyym3m3wtrwpnldj76u0qwjtms3dcftsqs6r87', 'pol'],
|
|
||||||
['Bitcoin', 'npub19nrn4l0s39kpwww7pgk9jddj8lzekqxmtrll8r2a57chtq3zx6sq00vetn', 'btc'],
|
['Bitcoin', 'npub19nrn4l0s39kpwww7pgk9jddj8lzekqxmtrll8r2a57chtq3zx6sq00vetn', 'btc'],
|
||||||
['Vidya', 'npub19t2dt6deqaleq59fdaq576tnqdzwkyzwptxfa2tck0v66w29xagqe7yqll', 'v'],
|
['Technology', 'npub1mltf3r3tskdxfjlq6ltt2n73xs29wcza3sjfw75ggxz3p8fpcg4qe44h9v', 'g'],
|
||||||
['Television & Film', 'npub1cpeuaea3cymx42fmmx2ur82t5qnckqv85qy5q2nhzhxwzael5v4sksfe29', 'tv'],
|
['Television & Film', 'npub1cpeuaea3cymx42fmmx2ur82t5qnckqv85qy5q2nhzhxwzael5v4sksfe29', 'tv'],
|
||||||
['Technology', 'npub1qd7pdtkrdgd0239d7jtvjcdjtryy4vn98cnqhzl8pt9pcnt3u2eqll2sdz', 'g']
|
['Vidya', 'npub19t2dt6deqaleq59fdaq576tnqdzwkyzwptxfa2tck0v66w29xagqe7yqll', 'v'],
|
||||||
|
['Politically Incorrect', 'npub19znf32s8s7qpkpfrck0suyym3m3wtrwpnldj76u0qwjtms3dcftsqs6r87', 'pol']
|
||||||
];
|
];
|
||||||
|
|
||||||
const Boards = () => {
|
const Boards = () => {
|
||||||
|
@ -19,11 +19,6 @@ interface FormProps {
|
|||||||
board?: string;
|
board?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagMapping = {
|
|
||||||
'Reply': ['e', 'p'],
|
|
||||||
'Quote': ['q', 'p']
|
|
||||||
};
|
|
||||||
|
|
||||||
const NewNoteCard = ({
|
const NewNoteCard = ({
|
||||||
refEvent,
|
refEvent,
|
||||||
tagType,
|
tagType,
|
||||||
@ -51,14 +46,13 @@ const NewNoteCard = ({
|
|||||||
const [uploadingFile, setUploadingFile] = useState(false);
|
const [uploadingFile, setUploadingFile] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (refEvent && tagType && unsigned.tags.length === 1) {
|
if (refEvent && tagType) {
|
||||||
if (tagType === 'Reply') {
|
unsigned.tags = Array.from(new Set(unsigned.tags.concat(refEvent.tags)));
|
||||||
unsigned.tags.push(['p', refEvent.pubkey]);
|
|
||||||
unsigned.tags.push(['e', refEvent.id, 'root']);
|
|
||||||
} else {
|
|
||||||
unsigned.tags = refEvent.tags
|
|
||||||
unsigned.tags.push(['p', refEvent.pubkey]);
|
unsigned.tags.push(['p', refEvent.pubkey]);
|
||||||
|
|
||||||
|
if (tagType === 'Reply') {
|
||||||
|
unsigned.tags.push(['e', refEvent.id, refEvent.tags.some(tag => tag[0] === 'e') ? 'root' : '']);
|
||||||
|
} else {
|
||||||
if (tagType === 'Quote') {
|
if (tagType === 'Quote') {
|
||||||
setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id));
|
setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id));
|
||||||
unsigned.tags.push(['q', refEvent.id]);
|
unsigned.tags.push(['q', refEvent.id]);
|
||||||
|
@ -213,40 +213,6 @@ export const subNotesOnce = (
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
// /** quick subscribe to a note id (nip-19) */
|
|
||||||
// export const subNotifications = (
|
|
||||||
// pubkeys: string[],
|
|
||||||
// onEvent: SubCallback,
|
|
||||||
// ) => {
|
|
||||||
// const replyPubkeys = new Set<string>();
|
|
||||||
// sub({
|
|
||||||
// cb: (evt, relay) => {
|
|
||||||
// replyPubkeys.add(evt.pubkey);
|
|
||||||
// onEvent(evt, relay);
|
|
||||||
// },
|
|
||||||
// filter: {
|
|
||||||
// "#p": pubkeys,
|
|
||||||
// kinds: [1],
|
|
||||||
// limit: 50,
|
|
||||||
// },
|
|
||||||
// unsub: true,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// setTimeout(() => {
|
|
||||||
// // get profile info
|
|
||||||
// sub({
|
|
||||||
// cb: onEvent,
|
|
||||||
// filter: {
|
|
||||||
// authors: Array.from(replyPubkeys),
|
|
||||||
// kinds: [0],
|
|
||||||
// limit: replyPubkeys.size,
|
|
||||||
// },
|
|
||||||
// unsub: true,
|
|
||||||
// });
|
|
||||||
// replyPubkeys.clear();
|
|
||||||
// }, 2000);
|
|
||||||
// };
|
|
||||||
|
|
||||||
const hasEventTag = (tag: string[]) => tag[0] === 'e';
|
const hasEventTag = (tag: string[]) => tag[0] === 'e';
|
||||||
const isReply = ([tag, , , marker]: string[]) => tag === 'e' && marker !== 'mention';
|
const isReply = ([tag, , , marker]: string[]) => tag === 'e' && marker !== 'mention';
|
||||||
|
|
||||||
@ -342,3 +308,22 @@ export const subBoardFeed = (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const subProfile = (
|
||||||
|
pubkey: string,
|
||||||
|
onEvent: SubCallback,
|
||||||
|
) => {
|
||||||
|
unsubAll();
|
||||||
|
|
||||||
|
sub({
|
||||||
|
cb: (evt, relay) => {
|
||||||
|
onEvent(evt, relay);
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
authors: [pubkey],
|
||||||
|
kinds: [1, 7],
|
||||||
|
limit: 25,
|
||||||
|
},
|
||||||
|
unsub: true,
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user