mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-30 00:41:09 +00:00
Reply to article
This commit is contained in:
parent
5b5afea786
commit
ebdda42433
@ -16,7 +16,7 @@ import styles from './BookmarkNote.module.scss';
|
||||
import { saveBookmarks } from '../../lib/localStore';
|
||||
import { importEvents, triggerImportEvents } from '../../lib/notes';
|
||||
|
||||
const BookmarkArticle: Component<{ note: PrimalArticle, large?: boolean }> = (props) => {
|
||||
const BookmarkArticle: Component<{ note: PrimalArticle | undefined, large?: boolean }> = (props) => {
|
||||
const account = useAccountContext();
|
||||
const app = useAppContext();
|
||||
const intl = useIntl();
|
||||
@ -24,8 +24,13 @@ const BookmarkArticle: Component<{ note: PrimalArticle, large?: boolean }> = (pr
|
||||
const [isBookmarked, setIsBookmarked] = createSignal(false);
|
||||
const [bookmarkInProgress, setBookmarkInProgress] = createSignal(false);
|
||||
|
||||
|
||||
createEffect(() => {
|
||||
setIsBookmarked(() => account?.bookmarks.includes(props.note?.id) || false);
|
||||
const note = props.note;
|
||||
|
||||
if (note) {
|
||||
setIsBookmarked(() => account?.bookmarks.includes(note.id) || false);
|
||||
}
|
||||
})
|
||||
|
||||
const updateBookmarks = async (bookmarkTags: string[][]) => {
|
||||
@ -47,7 +52,7 @@ const BookmarkArticle: Component<{ note: PrimalArticle, large?: boolean }> = (pr
|
||||
};
|
||||
|
||||
const addBookmark = async (bookmarkTags: string[][]) => {
|
||||
if (account && !bookmarkTags.find(b => b[0] === 'e' && b[1] === props.note.id)) {
|
||||
if (account && props.note && !bookmarkTags.find(b => b[0] === 'e' && b[1] === props.note?.id)) {
|
||||
const bookmarksToAdd = [...bookmarkTags, ['e', props.note.id]];
|
||||
|
||||
if (bookmarksToAdd.length < 2) {
|
||||
@ -73,8 +78,8 @@ const BookmarkArticle: Component<{ note: PrimalArticle, large?: boolean }> = (pr
|
||||
}
|
||||
|
||||
const removeBookmark = async (bookmarks: string[][]) => {
|
||||
if (account && bookmarks.find(b => b[0] === 'e' && b[1] === props.note.id)) {
|
||||
const bookmarksToAdd = bookmarks.filter(b => b[0] !== 'e' || b[1] !== props.note.id);
|
||||
if (account && bookmarks.find(b => b[0] === 'e' && b[1] === props.note?.id)) {
|
||||
const bookmarksToAdd = bookmarks.filter(b => b[0] !== 'e' || b[1] !== props.note?.id);
|
||||
|
||||
if (bookmarksToAdd.length < 1) {
|
||||
logWarning('BOOKMARK ISSUE: ', `before_bookmark_${APP_ID}`);
|
||||
|
@ -13,7 +13,7 @@ import { getUserProfiles } from "../../../lib/profile";
|
||||
import { subscribeTo } from "../../../sockets";
|
||||
import { convertToNotes, referencesToTags } from "../../../stores/note";
|
||||
import { convertToUser, nip05Verification, truncateNpub, userName } from "../../../stores/profile";
|
||||
import { EmojiOption, FeedPage, NostrMentionContent, NostrNoteContent, NostrStatsContent, NostrUserContent, PrimalNote, PrimalUser, SendNoteResult } from "../../../types/primal";
|
||||
import { EmojiOption, FeedPage, NostrMentionContent, NostrNoteContent, NostrStatsContent, NostrUserContent, PrimalArticle, PrimalNote, PrimalUser, SendNoteResult } from "../../../types/primal";
|
||||
import { debounce, getScreenCordinates, isVisibleInContainer, uuidv4 } from "../../../utils";
|
||||
import Avatar from "../../Avatar/Avatar";
|
||||
import EmbeddedNote from "../../EmbeddedNote/EmbeddedNote";
|
||||
@ -52,7 +52,7 @@ type AutoSizedTextArea = HTMLTextAreaElement & { _baseScrollHeight: number };
|
||||
|
||||
const EditBox: Component<{
|
||||
id?: string,
|
||||
replyToNote?: PrimalNote,
|
||||
replyToNote?: PrimalNote | PrimalArticle,
|
||||
onClose?: () => void,
|
||||
onSuccess?: (note: SendNoteResult) => void,
|
||||
open?: boolean,
|
||||
@ -587,8 +587,8 @@ const EditBox: Component<{
|
||||
|
||||
createEffect(() => {
|
||||
if (props.open) {
|
||||
const draft = readNoteDraft(account?.publicKey, props.replyToNote?.post.noteId);
|
||||
const draftUserRefs = readNoteDraftUserRefs(account?.publicKey, props.replyToNote?.post.noteId);
|
||||
const draft = readNoteDraft(account?.publicKey, props.replyToNote?.noteId);
|
||||
const draftUserRefs = readNoteDraftUserRefs(account?.publicKey, props.replyToNote?.noteId);
|
||||
|
||||
setUserRefs(reconcile(draftUserRefs));
|
||||
|
||||
@ -618,8 +618,8 @@ const EditBox: Component<{
|
||||
if (message().length === 0) return;
|
||||
|
||||
// save draft just in case there is an unintended interuption
|
||||
saveNoteDraft(account?.publicKey, message(), props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.post.noteId);
|
||||
saveNoteDraft(account?.publicKey, message(), props.replyToNote?.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.noteId);
|
||||
});
|
||||
|
||||
const onEscape = (e: KeyboardEvent) => {
|
||||
@ -667,8 +667,8 @@ const EditBox: Component<{
|
||||
return;
|
||||
}
|
||||
|
||||
saveNoteDraft(account?.publicKey, '', props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, {}, props.replyToNote?.post.noteId);
|
||||
saveNoteDraft(account?.publicKey, '', props.replyToNote?.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, {}, props.replyToNote?.noteId);
|
||||
clearEditor();
|
||||
};
|
||||
|
||||
@ -680,8 +680,8 @@ const EditBox: Component<{
|
||||
};
|
||||
|
||||
const persistNote = (note: string) => {
|
||||
saveNoteDraft(account?.publicKey, note, props.replyToNote?.post.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.post.noteId);
|
||||
saveNoteDraft(account?.publicKey, note, props.replyToNote?.noteId);
|
||||
saveNoteDraftUserRefs(account?.publicKey, userRefs, props.replyToNote?.noteId);
|
||||
clearEditor();
|
||||
};
|
||||
|
||||
@ -721,10 +721,10 @@ const EditBox: Component<{
|
||||
const rep = props.replyToNote;
|
||||
|
||||
if (rep) {
|
||||
let rootTag = rep.post.tags.find(t => t[0] === 'e' && t[3] === 'root');
|
||||
let rootTag = rep.msg.tags.find(t => t[0] === 'e' && t[3] === 'root');
|
||||
|
||||
const rHints = (rep.post.relayHints && rep.post.relayHints[rep.post.id]) ?
|
||||
rep.post.relayHints[rep.post.id] :
|
||||
const rHints = (rep.relayHints && rep.relayHints[rep.id]) ?
|
||||
rep.relayHints[rep.id] :
|
||||
'';
|
||||
|
||||
// If the note has a root tag, that meens it is not a root note itself
|
||||
@ -735,26 +735,26 @@ const EditBox: Component<{
|
||||
v,
|
||||
);
|
||||
tags.push([...tagWithHint]);
|
||||
tags.push(['e', rep.post.id, rHints, 'reply']);
|
||||
tags.push(['e', rep.id, rHints, 'reply']);
|
||||
}
|
||||
// Otherwise, add the note as the root tag for this reply
|
||||
else {
|
||||
tags.push([
|
||||
'e',
|
||||
rep.post.id,
|
||||
rep.id,
|
||||
rHints,
|
||||
'root',
|
||||
]);
|
||||
}
|
||||
|
||||
// Copy all `p` tags from the note we are repling to
|
||||
const repPeople = rep.post.tags.filter(t => t[0] === 'p');
|
||||
const repPeople = rep.msg.tags.filter(t => t[0] === 'p');
|
||||
|
||||
tags = [...tags, ...(unwrap(repPeople))];
|
||||
|
||||
// If the author of the note is missing, add them
|
||||
if (!tags.find(t => t[0] === 'p' && t[1] === rep.post.pubkey)) {
|
||||
tags.push(['p', rep.post.pubkey]);
|
||||
if (!tags.find(t => t[0] === 'p' && t[1] === rep.pubkey)) {
|
||||
tags.push(['p', rep.pubkey]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -772,7 +772,7 @@ const EditBox: Component<{
|
||||
toast?.sendSuccess(intl.formatMessage(tToast.publishNoteSuccess));
|
||||
props.onSuccess && props.onSuccess({ success, reasons, note });
|
||||
setIsPostingInProgress(false);
|
||||
saveNoteDraft(account.publicKey, '', rep?.post.noteId)
|
||||
saveNoteDraft(account.publicKey, '', rep?.noteId)
|
||||
clearEditor();
|
||||
}
|
||||
unsub();
|
||||
@ -1046,7 +1046,7 @@ const EditBox: Component<{
|
||||
|
||||
// // setNoteRefs((refs) => ({
|
||||
// // ...refs,
|
||||
// // [newNote.post.noteId]: newNote
|
||||
// // [newNote.noteId]: newNote
|
||||
// // }));
|
||||
|
||||
subUserRef(hex);
|
||||
@ -1107,10 +1107,10 @@ const EditBox: Component<{
|
||||
|
||||
setNoteRefs((refs) => ({
|
||||
...refs,
|
||||
[newNote.post.noteId]: newNote
|
||||
[newNote.noteId]: newNote
|
||||
}));
|
||||
|
||||
subNoteRef(newNote.post.noteId);
|
||||
subNoteRef(newNote.noteId);
|
||||
|
||||
unsub();
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import { SolidMarkdown } from "solid-markdown";
|
||||
|
||||
import styles from './Longform.module.scss';
|
||||
import Loader from "../components/Loader/Loader";
|
||||
import { FeedPage, NostrEventContent, NostrMentionContent, NostrNoteActionsContent, NostrNoteContent, NostrStatsContent, NostrUserContent, NoteActions, PrimalArticle, PrimalNote, PrimalUser, TopZap, ZapOption } from "../types/primal";
|
||||
import { FeedPage, NostrEventContent, NostrMentionContent, NostrNoteActionsContent, NostrNoteContent, NostrStatsContent, NostrUserContent, NoteActions, PrimalArticle, PrimalNote, PrimalUser, SendNoteResult, TopZap, ZapOption } from "../types/primal";
|
||||
import { getUserProfileInfo, getUserProfiles } from "../lib/profile";
|
||||
import { convertToUser, nip05Verification, userName } from "../stores/profile";
|
||||
import Avatar from "../components/Avatar/Avatar";
|
||||
@ -46,6 +46,8 @@ import Wormhole from "../components/Wormhole/Wormhole";
|
||||
import Search from "../components/Search/Search";
|
||||
import ArticleSidebar from "../components/HomeSidebar/ArticleSidebar";
|
||||
import ReplyToNote from "../components/ReplyToNote/ReplyToNote";
|
||||
import { sanitize } from "dompurify";
|
||||
import { fetchNotes } from "../handleNotes";
|
||||
|
||||
export type LongFormData = {
|
||||
title: string,
|
||||
@ -777,6 +779,17 @@ const Longform: Component< { naddr: string } > = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const onReplyPosted = async (result: SendNoteResult) => {
|
||||
const { success, note } = result;
|
||||
|
||||
if (!success || !note || !account) return;
|
||||
|
||||
const replies = await fetchNotes(account.publicKey, [note.id], `reads_reply_${APP_ID}`);
|
||||
|
||||
updateStore('replies', (reps) => [ ...replies, ...reps]);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Wormhole
|
||||
@ -897,7 +910,7 @@ const Longform: Component< { naddr: string } > = (props) => {
|
||||
<Show when={store.article}>
|
||||
<ReplyToNote
|
||||
note={store.article}
|
||||
onNotePosted={() => {}}
|
||||
onNotePosted={onReplyPosted}
|
||||
/>
|
||||
</Show>
|
||||
|
||||
|
@ -370,6 +370,7 @@ export const convertToNotes: ConvertToNotes = (page, topZaps) => {
|
||||
pubkey: msg.pubkey,
|
||||
topZaps: [ ...tz ],
|
||||
content: sanitize(msg.content),
|
||||
relayHints: page.relayHints,
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -486,6 +487,7 @@ export const convertToArticles: ConvertToArticles = (page, topZaps) => {
|
||||
score: stat?.score || 0,
|
||||
score24h: stat?.score24h || 0,
|
||||
satszapped: stat?.satszapped || 0,
|
||||
relayHints: page.relayHints,
|
||||
};
|
||||
|
||||
msg.tags.forEach(tag => {
|
||||
|
2
src/types/primal.d.ts
vendored
2
src/types/primal.d.ts
vendored
@ -502,6 +502,7 @@ export type PrimalNote = {
|
||||
tags: string[][],
|
||||
topZaps: TopZap[],
|
||||
content: string,
|
||||
relayHints?: Record<string, string>,
|
||||
};
|
||||
|
||||
|
||||
@ -534,6 +535,7 @@ export type PrimalArticle = {
|
||||
score24h: number,
|
||||
satszapped: number,
|
||||
client?: string,
|
||||
relayHints?: Record<string, string>,
|
||||
};
|
||||
|
||||
export type PrimalFeed = {
|
||||
|
Loading…
Reference in New Issue
Block a user