added current status to user

This commit is contained in:
Ren Amamiya
2023-02-23 14:57:39 +07:00
parent 1796228116
commit 31a3a712ec
7 changed files with 23 additions and 15 deletions

View File

@@ -82,7 +82,7 @@ export default function Page() {
// save account to database
const db = await Database.load('sqlite:lume.db');
await db.execute(
`INSERT INTO accounts (privkey, pubkey, npub, nsec, metadata) VALUES ("${privKey}", "${pubKey}", "${npub}", "${nsec}", '${JSON.stringify(
`INSERT INTO accounts (privkey, pubkey, npub, nsec, current, metadata) VALUES ("${privKey}", "${pubKey}", "${npub}", "${nsec}", "1", '${JSON.stringify(
data
)}')`
);

View File

@@ -34,12 +34,12 @@ export default function Page() {
const insertDB = async () => {
const db = await Database.load('sqlite:lume.db');
await db.execute(
`INSERT INTO followings (pubkey, account) VALUES ("${$currentUser.pubkey}", "${$currentUser.pubkey}")`
`INSERT INTO follows (pubkey, account) VALUES ("${$currentUser.pubkey}", "${$currentUser.pubkey}")`
);
follow.forEach(async (npub) => {
const { data } = nip19.decode(npub);
await db.execute(
`INSERT INTO followings (pubkey, account) VALUES ("${data}", "${$currentUser.pubkey}")`
`INSERT INTO follows (pubkey, account) VALUES ("${data}", "${$currentUser.pubkey}")`
);
});
};

View File

@@ -45,7 +45,7 @@ export default function Page({ pubkey }: { pubkey: string }) {
follows.forEach(async (item) => {
if (item) {
await db.execute(
`INSERT INTO followings (pubkey, account) VALUES ("${item[1]}", "${pubkey}")`
`INSERT INTO follows (pubkey, account) VALUES ("${item[1]}", "${pubkey}")`
);
}
});

View File

@@ -18,11 +18,11 @@ import {
import Database from 'tauri-plugin-sql-api';
export default function Page({ privkey }: { privkey: string }) {
const router = useRouter();
const [account, setAccount] = useState(null);
const [loading, setLoading] = useState(false);
const router = useRouter();
const pubkey = getPublicKey(privkey);
const npub = nip19.npubEncode(pubkey);
const nsec = nip19.nsecEncode(privkey);
@@ -45,11 +45,12 @@ export default function Page({ privkey }: { privkey: string }) {
useEffect(() => {
setLoading(true);
const insertDB = async () => {
// save account to database
const db = await Database.load('sqlite:lume.db');
await db.execute(
`INSERT INTO accounts (privkey, pubkey, npub, nsec, metadata) VALUES ("${privkey}", "${pubkey}", "${npub}", "${nsec}", '${JSON.stringify(
`INSERT INTO accounts (privkey, pubkey, npub, nsec, current, metadata) VALUES ("${privkey}", "${pubkey}", "${npub}", "${nsec}", "1", '${JSON.stringify(
account
)}')`
);