This commit is contained in:
Ren Amamiya
2023-04-05 09:48:57 +07:00
parent fc8dc8fd0d
commit beb622f05e
13 changed files with 23 additions and 233 deletions

View File

@@ -2,12 +2,11 @@ import EmojiPicker from '@components/form/emojiPicker';
import ImagePicker from '@components/form/imagePicker';
import { RelayContext } from '@components/relaysProvider';
import { activeAccountAtom } from '@stores/account';
import { noteContentAtom } from '@stores/note';
import { dateToUnix } from '@utils/getDate';
import { useAtom, useAtomValue } from 'jotai';
import { useAtom } from 'jotai';
import { useResetAtom } from 'jotai/utils';
import { getEventHash, signEvent } from 'nostr-tools';
import { useContext } from 'react';
@@ -15,23 +14,21 @@ import { useContext } from 'react';
export default function FormBase() {
const [pool, relays]: any = useContext(RelayContext);
const activeAccount: any = useAtomValue(activeAccountAtom);
const [value, setValue] = useAtom(noteContentAtom);
const resetValue = useResetAtom(noteContentAtom);
const pubkey = activeAccount.id;
const privkey = activeAccount.privkey;
const submitEvent = () => {
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
const event: any = {
content: value,
created_at: dateToUnix(),
kind: 1,
pubkey: pubkey,
pubkey: activeAccount.pubkey,
tags: [],
};
event.id = getEventHash(event);
event.sig = signEvent(event, privkey);
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);

View File

@@ -23,7 +23,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
content: value,
created_at: dateToUnix(),
kind: 1,
pubkey: activeAccount.id,
pubkey: activeAccount.pubkey,
tags: [['e', eventID]],
};
event.id = getEventHash(event);
@@ -42,7 +42,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
<div className="relative h-11 w-11 shrink-0 overflow-hidden rounded-md border border-white/10">
<ImageWithFallback
src={profile?.picture}
alt={activeAccount.id}
alt={activeAccount.pubkey}
fill={true}
className="rounded-md object-cover"
/>

View File

@@ -19,11 +19,11 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
const userData = JSON.parse(user.metadata);
const openProfilePage = () => {
router.push(`/users/${user.id}`);
router.push(`/users/${user.pubkey}`);
};
const copyPublicKey = async () => {
await writeText(nip19.npubEncode(user.id));
await writeText(nip19.npubEncode(user.pubkey));
};
const insertFollowsToStorage = useCallback(
@@ -46,7 +46,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
[
{
kinds: [3],
authors: [user.id],
authors: [user.pubkey],
},
],
relays,
@@ -65,7 +65,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
return () => {
unsubscribe;
};
}, [insertFollowsToStorage, pool, relays, user.id]);
}, [insertFollowsToStorage, pool, relays, user.pubkey]);
return (
<DropdownMenu.Root>

View File

@@ -12,13 +12,13 @@ import { useCallback, useEffect, useState } from 'react';
export default function MultiAccounts() {
const [users, setUsers] = useState([]);
const renderAccount = useCallback((user: { id: string }) => {
const renderAccount = useCallback((user: { pubkey: string }) => {
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
if (user.id === activeAccount.id) {
return <ActiveAccount key={user.id} user={user} />;
if (user.pubkey === activeAccount.pubkey) {
return <ActiveAccount key={user.pubkey} user={user} />;
} else {
return <InactiveAccount key={user.id} user={user} />;
return <InactiveAccount key={user.pubkey} user={user} />;
}
}, []);

View File

@@ -3,7 +3,6 @@ import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend';
import { activeAccountAtom } from '@stores/account';
import { relaysAtom } from '@stores/relays';
import { dateToUnix } from '@utils/getDate';
@@ -33,11 +32,10 @@ export const NoteComment = memo(function NoteComment({
const router = useRouter();
const [pool, relays]: any = useContext(RelayContext);
const activeAccount: any = useAtomValue(activeAccountAtom);
const [open, setOpen] = useState(false);
const [value, setValue] = useState('');
const activeAccount: any = useAtomValue(activeAccountAtom);
const profile = destr(activeAccount.metadata);
const openThread = () => {
@@ -49,7 +47,7 @@ export const NoteComment = memo(function NoteComment({
content: value,
created_at: dateToUnix(),
kind: 1,
pubkey: activeAccount.id,
pubkey: activeAccount.pubkey,
tags: [['e', eventID]],
};
event.id = getEventHash(event);

View File

@@ -38,7 +38,7 @@ export const NoteReaction = memo(function NoteReaction({
['p', eventPubkey],
],
created_at: dateToUnix(),
pubkey: activeAccount.id,
pubkey: activeAccount.pubkey,
};
event.id = getEventHash(event);
event.sig = signEvent(event, activeAccount.privkey);

View File

@@ -2,8 +2,6 @@ import { NoteComment } from '@components/note/meta/comment';
import { NoteReaction } from '@components/note/meta/reaction';
import { RelayContext } from '@components/relaysProvider';
import { createCacheCommentNote } from '@utils/storage';
import { useContext, useEffect, useState } from 'react';
export default function NoteMetadata({
@@ -39,7 +37,7 @@ export default function NoteMetadata({
// update state
setComments((comments) => (comments += 1));
// save comment to database
createCacheCommentNote(event, eventID);
// createCacheCommentNote(event, eventID);
break;
case 7:
if (event.content === '🤙' || event.content === '+') {

View File

@@ -45,7 +45,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
parent_id: parentID,
parent_comment_id: '',
created_at: event.created_at,
account_id: activeAccount.id,
account_id: activeAccount.pubkey,
}).catch(console.error);
},
undefined,

View File

@@ -41,7 +41,7 @@ export const NoteRepost = memo(function NoteRepost({ id }: { id: string }) {
parent_id: parentID,
parent_comment_id: '',
created_at: event.created_at,
account_id: activeAccount.id,
account_id: activeAccount.pubkey,
}).catch(console.error);
},
undefined,