fixed some bugs

This commit is contained in:
Ren Amamiya
2023-03-10 09:30:13 +07:00
parent 42f4c8339e
commit c77c08675a
11 changed files with 269 additions and 251 deletions

View File

@@ -26,7 +26,7 @@ export default function AccountColumn() {
<div className="flex h-full flex-col items-center justify-between px-2 pt-12 pb-4">
<div className="flex flex-col gap-4">
{users.map((user, index) => (
<Account key={index} user={user} current={currentUser.pubkey} />
<Account key={index} user={user} current={currentUser.id} />
))}
<Link
href="/onboarding"

View File

@@ -20,7 +20,7 @@ export default function CreatePost() {
const [value, setValue] = useState('');
const [currentUser]: any = useLocalStorage('current-user');
const pubkey = currentUser.pubkey;
const pubkey = currentUser.id;
const privkey = currentUser.privkey;
const postButton = {

View File

@@ -17,7 +17,7 @@ export default function NavigatorColumn() {
<div className="flex flex-col p-2">
<div className="flex items-center justify-between">
<h5 className="font-semibold leading-tight text-zinc-100">{profile.display_name || ''}</h5>
<UserDropdownMenu pubkey={currentUser.pubkey} />
<UserDropdownMenu pubkey={currentUser.id} />
</div>
<span className="text-sm leading-tight text-zinc-500">@{profile.username || ''}</span>
</div>

View File

@@ -1,5 +1,5 @@
import { writeStorage } from '@rehooks/local-storage';
import { createContext, useEffect, useState } from 'react';
import { deleteFromStorage, writeStorage } from '@rehooks/local-storage';
import { createContext, useCallback, useEffect, useState } from 'react';
import Database from 'tauri-plugin-sql-api';
export const DatabaseContext = createContext({});
@@ -9,36 +9,46 @@ const db = typeof window !== 'undefined' ? await Database.load('sqlite:lume.db')
export default function DatabaseProvider({ children }: { children: React.ReactNode }) {
const [done, setDone] = useState(false);
useEffect(() => {
const getRelays = async () => {
const arr = [];
const result: any[] = await db.select('SELECT relay_url FROM relays WHERE relay_status = "1"');
const getRelays = useCallback(async () => {
const result: any[] = await db.select('SELECT relay_url FROM relays WHERE relay_status = "1"');
const arr = [];
result.forEach((item: { relay_url: string }) => {
arr.push(item.relay_url);
});
// delete old item then save new item to local storage
deleteFromStorage('relays');
writeStorage('relays', arr);
// return
return;
}, []);
result.forEach((item: { relay_url: string }) => {
arr.push(item.relay_url);
});
writeStorage('relays', arr);
};
const getAccount = async () => {
const result = await db.select(`SELECT * FROM accounts LIMIT 1`);
const getAccount = useCallback(async () => {
const result = await db.select(`SELECT * FROM accounts LIMIT 1`);
// delete old item then save new item to local storage
deleteFromStorage('current-user');
if (result[0]) {
writeStorage('current-user', result[0]);
} else {
writeStorage('current-user', null);
}
// return first record
return result[0];
}, []);
return result[0];
};
const getFollows = async (id: string) => {
const arr = [];
const result: any[] = await db.select(`SELECT pubkey FROM follows WHERE account = "${id}"`);
result.forEach((item: { pubkey: string }) => {
arr.push(item.pubkey);
});
writeStorage('follows', arr);
};
const getFollows = useCallback(async (id: string) => {
const result: any[] = await db.select(`SELECT pubkey FROM follows WHERE account = "${id}"`);
const arr = [];
result.forEach((item: { pubkey: string }) => {
arr.push(item.pubkey);
});
// delete old item then save new item to local storage
deleteFromStorage('follows');
writeStorage('follows', arr);
// return
return;
}, []);
useEffect(() => {
getRelays().catch(console.error);
getAccount()
.then((res) => {
@@ -48,9 +58,11 @@ export default function DatabaseProvider({ children }: { children: React.ReactNo
setDone(true);
})
.catch(console.error);
}, []);
}, [getAccount, getFollows, getRelays]);
if (done === true) {
return <DatabaseContext.Provider value={{ db }}>{children}</DatabaseContext.Provider>;
if (!done) {
return <></>;
}
return <DatabaseContext.Provider value={{ db }}>{children}</DatabaseContext.Provider>;
}

View File

@@ -15,7 +15,7 @@ export default function Reaction({ eventID, eventPubkey }: { eventID: string; ev
const [isReact, setIsReact] = useState(false);
const [currentUser]: any = useLocalStorage('current-user');
const pubkey = currentUser.pubkey;
const pubkey = currentUser.id;
const privkey = currentUser.privkey;
/*