fixed some bugs
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/*
|
||||
|
||||
@@ -24,14 +24,14 @@ export default function UserLayout({ children }: { children: React.ReactNode })
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 text-zinc-500">
|
||||
<ActiveLink
|
||||
href={`/profile/${currentUser.pubkey}`}
|
||||
href={`/profile/${currentUser.id}`}
|
||||
activeClassName="ring-1 ring-white/10 dark:bg-zinc-900 dark:text-white"
|
||||
className="flex h-10 items-center gap-1 rounded-lg px-2.5 text-sm font-medium hover:bg-zinc-900"
|
||||
>
|
||||
<span>Personal Page</span>
|
||||
</ActiveLink>
|
||||
<ActiveLink
|
||||
href={`/profile/update?pubkey=${currentUser.pubkey}`}
|
||||
href={`/profile/update?pubkey=${currentUser.id}`}
|
||||
activeClassName="ring-1 ring-white/10 dark:bg-zinc-900 dark:text-white"
|
||||
className="flex h-10 items-center gap-1 rounded-lg px-2.5 text-sm font-medium hover:bg-zinc-900"
|
||||
>
|
||||
|
||||
@@ -5,26 +5,32 @@ import LumeSymbol from '@assets/icons/Lume';
|
||||
import { useLocalStorage } from '@rehooks/local-storage';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useRouter } from 'next/router';
|
||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useEffect, useState } from 'react';
|
||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useEffect, useRef, useState } from 'react';
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
|
||||
const [currentUser]: any = useLocalStorage('current-user');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const timer = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser) {
|
||||
setTimeout(() => {
|
||||
setLoading(false);
|
||||
router.push('/onboarding');
|
||||
}, 1500);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
if (currentUser) {
|
||||
timer.current = setTimeout(() => {
|
||||
setLoading(false);
|
||||
router.push('/newsfeed/following');
|
||||
}, 1500);
|
||||
}, 1000);
|
||||
} else {
|
||||
timer.current = setTimeout(() => {
|
||||
setLoading(false);
|
||||
router.push('/onboarding');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// clean up
|
||||
return () => {
|
||||
clearTimeout(timer.current);
|
||||
};
|
||||
}, [currentUser, router]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -17,7 +17,7 @@ import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useCon
|
||||
const shuffle = (arr: { name: string; avatar: string; npub: string }[]) => [...arr].sort(() => Math.random() - 0.5);
|
||||
|
||||
export default function Page() {
|
||||
const db: any = useContext(DatabaseContext);
|
||||
const { db }: any = useContext(DatabaseContext);
|
||||
const router = useRouter();
|
||||
|
||||
const [follow, setFollow] = useState([]);
|
||||
@@ -33,12 +33,12 @@ export default function Page() {
|
||||
const insertDB = async () => {
|
||||
// self follow
|
||||
await db.execute(
|
||||
`INSERT INTO follows (pubkey, account, kind) VALUES ("${currentUser.pubkey}", "${currentUser.pubkey}", "0")`
|
||||
`INSERT INTO follows (pubkey, account, kind) VALUES ("${currentUser.id}", "${currentUser.id}", "0")`
|
||||
);
|
||||
// follow selected
|
||||
follow.forEach(async (npub) => {
|
||||
const { data } = nip19.decode(npub);
|
||||
await db.execute(`INSERT INTO follows (pubkey, account, kind) VALUES ("${data}", "${currentUser.pubkey}", "0")`);
|
||||
await db.execute(`INSERT INTO follows (pubkey, account, kind) VALUES ("${data}", "${currentUser.id}", "0")`);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function Page() {
|
||||
content: JSON.stringify(data),
|
||||
created_at: dateToUnix(),
|
||||
kind: 0,
|
||||
pubkey: currentUser.pubkey,
|
||||
pubkey: currentUser.id,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
@@ -59,14 +59,14 @@ export default function Page() {
|
||||
|
||||
// save account to database
|
||||
const db = await Database.load('sqlite:lume.db');
|
||||
await db.execute(`UPDATE accounts SET metadata = '${JSON.stringify(data)}' WHERE pubkey = "${currentUser.pubkey}"`);
|
||||
await db.execute(`UPDATE accounts SET metadata = '${JSON.stringify(data)}' WHERE pubkey = "${currentUser.id}"`);
|
||||
|
||||
// set currentUser in global state
|
||||
currentUser.set({
|
||||
metadata: JSON.stringify(data),
|
||||
npub: currentUser.npub,
|
||||
privkey: currentUser.privkey,
|
||||
pubkey: currentUser.pubkey,
|
||||
pubkey: currentUser.id,
|
||||
});
|
||||
|
||||
// redirect to newsfeed
|
||||
|
||||
Reference in New Issue
Block a user