clean up and fix errors

This commit is contained in:
Ren Amamiya
2023-04-19 08:50:32 +07:00
parent c72798507e
commit 697caca77b
13 changed files with 83 additions and 78 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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;
};