fixed some bugs
This commit is contained in:
@@ -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