clean up and fix errors
This commit is contained in:
@@ -47,20 +47,20 @@ export default function Page() {
|
||||
);
|
||||
|
||||
const initialData = useCallback(async () => {
|
||||
const result = await getNotes(dateToUnix(now.current), limit.current, offset.current);
|
||||
const result: any = await getNotes(dateToUnix(now.current), limit.current, offset.current);
|
||||
setData((data) => [...data, ...result]);
|
||||
}, [setData]);
|
||||
|
||||
const loadMore = useCallback(async () => {
|
||||
offset.current += limit.current;
|
||||
// query next page
|
||||
const result = await getNotes(dateToUnix(now.current), limit.current, offset.current);
|
||||
const result: any = await getNotes(dateToUnix(now.current), limit.current, offset.current);
|
||||
setData((data) => [...data, ...result]);
|
||||
}, [setData]);
|
||||
|
||||
const loadLatest = useCallback(async () => {
|
||||
// next query
|
||||
const result = await getLatestNotes(dateToUnix(now.current));
|
||||
const result: any = await getLatestNotes(dateToUnix(now.current));
|
||||
// update data
|
||||
setData((data) => [...result, ...data]);
|
||||
// hide newer trigger
|
||||
|
||||
@@ -36,9 +36,8 @@ export default function Page({ params }: { params: { privkey: string } }) {
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
authors: [pubkey],
|
||||
kinds: [0, 3],
|
||||
since: 0,
|
||||
authors: [pubkey],
|
||||
},
|
||||
],
|
||||
relays,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
getActiveAccount,
|
||||
getPlebs,
|
||||
} from '@utils/storage';
|
||||
import { getParentID, nip02ToArray } from '@utils/transform';
|
||||
import { getParentID } from '@utils/transform';
|
||||
|
||||
import LumeSymbol from '@assets/icons/Lume';
|
||||
|
||||
@@ -31,10 +31,11 @@ export default function Page() {
|
||||
const unsubscribe = useRef(null);
|
||||
|
||||
const fetchData = useCallback(
|
||||
async (account: { id: number; pubkey: string; chats: string[] }, follows: any) => {
|
||||
async (account: { id: number; pubkey: string; chats: string[] }, tags: any) => {
|
||||
const notes = await countTotalNotes();
|
||||
const channels = await countTotalChannels();
|
||||
const chats = account.chats?.length || 0;
|
||||
const follows = JSON.parse(tags);
|
||||
|
||||
const query = [];
|
||||
let since: number;
|
||||
@@ -47,7 +48,7 @@ export default function Page() {
|
||||
}
|
||||
query.push({
|
||||
kinds: [1, 6],
|
||||
authors: JSON.parse(follows),
|
||||
authors: follows,
|
||||
since: since,
|
||||
until: dateToUnix(now.current),
|
||||
});
|
||||
|
||||
@@ -15,15 +15,15 @@ export default function ChatList() {
|
||||
|
||||
const [list, setList] = useState([]);
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const profile = activeAccount.metadata ? JSON.parse(activeAccount.metadata) : null;
|
||||
const profile = JSON.parse(activeAccount.metadata);
|
||||
|
||||
const openSelfChat = () => {
|
||||
router.push(`/chats/${activeAccount.pubkey}`);
|
||||
router.push(`/nostr/chats/${activeAccount.pubkey}`);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getChats(activeAccount.id)
|
||||
.then((res) => setList(res))
|
||||
.then((res: any) => setList(res))
|
||||
.catch(console.error);
|
||||
}, [activeAccount.id]);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ export default function EventCollector() {
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const setHasNewerNote = useSetAtom(hasNewerNoteAtom);
|
||||
const follows = JSON.parse(activeAccount.follows);
|
||||
|
||||
const now = useRef(new Date());
|
||||
const unsubscribe = useRef(null);
|
||||
@@ -29,11 +30,11 @@ export default function EventCollector() {
|
||||
[
|
||||
{
|
||||
kinds: [1, 6],
|
||||
authors: activeAccount.follows,
|
||||
authors: follows,
|
||||
since: dateToUnix(now.current),
|
||||
},
|
||||
{
|
||||
kinds: [3],
|
||||
kinds: [0, 3],
|
||||
authors: [activeAccount.pubkey],
|
||||
},
|
||||
{
|
||||
@@ -47,8 +48,12 @@ export default function EventCollector() {
|
||||
},
|
||||
],
|
||||
relays,
|
||||
(event) => {
|
||||
(event: { kind: number; tags: string[]; id: string; pubkey: string; content: string; created_at: number }) => {
|
||||
switch (event.kind) {
|
||||
// metadata
|
||||
case 0:
|
||||
updateAccount('metadata', event.content, event.pubkey);
|
||||
break;
|
||||
// short text note
|
||||
case 1:
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
|
||||
@@ -31,7 +31,7 @@ export default function MultiAccounts() {
|
||||
|
||||
useEffect(() => {
|
||||
getAccounts()
|
||||
.then((res) => setUsers(res))
|
||||
.then((res: any) => setUsers(res))
|
||||
.catch(console.error);
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { RootNote } from '@components/note/rootNote';
|
||||
import { UserQuoteRepost } from '@components/user/quoteRepost';
|
||||
|
||||
import destr from 'destr';
|
||||
import { memo } from 'react';
|
||||
|
||||
export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event: any }) {
|
||||
@@ -8,7 +9,10 @@ export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event:
|
||||
let note = null;
|
||||
|
||||
if (event.content.length > 0) {
|
||||
note = <RootNote event={JSON.parse(event.content)} />;
|
||||
const content = destr(event.content);
|
||||
if (content) {
|
||||
note = <RootNote event={content} />;
|
||||
}
|
||||
} else {
|
||||
note = <RootNote event={event.tags[0][1]} />;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export const fetchProfileMetadata = async (pubkey: string) => {
|
||||
return await result.data;
|
||||
};
|
||||
|
||||
export const useProfileMetadata = (pubkey) => {
|
||||
export const useProfileMetadata = (pubkey: string) => {
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const [plebs] = useLocalStorage('plebs', []);
|
||||
const [profile, setProfile] = useState(null);
|
||||
|
||||
@@ -37,7 +37,7 @@ export const contentParser = (noteContent, noteTags) => {
|
||||
</span>
|
||||
));
|
||||
// handle mentions
|
||||
if (tags.length > 0) {
|
||||
if (tags && tags.length > 0) {
|
||||
parsedContent = reactStringReplace(parsedContent, /\#\[(\d+)\]/gm, (match) => {
|
||||
if (tags[match][0] === 'p') {
|
||||
// @-mentions
|
||||
|
||||
@@ -39,7 +39,11 @@ export async function createAccount(pubkey: string, privkey: string, metadata: s
|
||||
// update account
|
||||
export async function updateAccount(column: string, value: string | string[], pubkey: string) {
|
||||
const db = await connect();
|
||||
return await db.execute(`UPDATE accounts SET ${column} = '${JSON.stringify(value)}' WHERE pubkey = "${pubkey}";`);
|
||||
if (Array.isArray(value)) {
|
||||
return await db.execute(`UPDATE accounts SET ${column} = '${JSON.stringify(value)}' WHERE pubkey = "${pubkey}";`);
|
||||
} else {
|
||||
return await db.execute(`UPDATE accounts SET ${column} = "${value}" WHERE pubkey = "${pubkey}";`);
|
||||
}
|
||||
}
|
||||
|
||||
// get all plebs
|
||||
@@ -77,7 +81,7 @@ export async function getNotes(time: number, limit: number, offset: number) {
|
||||
}
|
||||
|
||||
// get note by id
|
||||
export async function getNoteByID(event_id) {
|
||||
export async function getNoteByID(event_id: string) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM notes WHERE event_id = "${event_id}";`);
|
||||
return result[0];
|
||||
@@ -86,7 +90,7 @@ export async function getNoteByID(event_id) {
|
||||
// get all latest notes
|
||||
export async function getLatestNotes(time: number) {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM cache_notes WHERE created_at > "${time}" ORDER BY created_at DESC;`);
|
||||
return await db.select(`SELECT * FROM notes WHERE created_at > "${time}" ORDER BY created_at DESC;`);
|
||||
}
|
||||
|
||||
// create note
|
||||
|
||||
@@ -38,11 +38,3 @@ export const getParentID = (arr: string[], fallback: string) => {
|
||||
|
||||
return parentID;
|
||||
};
|
||||
|
||||
export const filterDuplicateParentID = (arr) => {
|
||||
const filteredArray = arr.filter(
|
||||
(item, index) => index === arr.findIndex((other) => item.parent_id === other.parent_id)
|
||||
);
|
||||
|
||||
return filteredArray;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user