mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-18 11:13:30 +00:00
added current status to user
This commit is contained in:
parent
1796228116
commit
31a3a712ec
@ -5,8 +5,13 @@ import { memo } from 'react';
|
||||
export const Account = memo(function Account({ user, current }: { user: any; current: string }) {
|
||||
const userData = JSON.parse(user.metadata);
|
||||
|
||||
const setCurrentUser = () => {
|
||||
console.log('clicked');
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
<button
|
||||
onClick={() => setCurrentUser()}
|
||||
className={`relative h-11 w-11 shrink overflow-hidden rounded-full ${
|
||||
current === user.pubkey ? 'ring-1 ring-fuchsia-500 ring-offset-4 ring-offset-black' : ''
|
||||
}`}>
|
||||
@ -20,6 +25,6 @@ export const Account = memo(function Account({ user, current }: { user: any; cur
|
||||
) : (
|
||||
<div className="h-11 w-11 animate-pulse rounded-full bg-zinc-700" />
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
});
|
||||
|
@ -13,15 +13,17 @@ export default function CheckAccount() {
|
||||
useEffect(() => {
|
||||
const accounts = async () => {
|
||||
const db = await Database.load('sqlite:lume.db');
|
||||
const result = await db.select('SELECT * FROM accounts ORDER BY id ASC LIMIT 1');
|
||||
const result = await db.select(
|
||||
`SELECT * FROM accounts WHERE current = "1" ORDER BY id ASC LIMIT 1`
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const getFollowings = async (account) => {
|
||||
const getFollows = async (account) => {
|
||||
const db = await Database.load('sqlite:lume.db');
|
||||
const result: any = await db.select(
|
||||
`SELECT pubkey FROM followings WHERE account = "${account.pubkey}"`
|
||||
`SELECT pubkey FROM follows WHERE account = "${account.pubkey}"`
|
||||
);
|
||||
|
||||
const arr = [];
|
||||
@ -43,7 +45,7 @@ export default function CheckAccount() {
|
||||
} else {
|
||||
currentUser.set(res[0]);
|
||||
|
||||
getFollowings(res[0])
|
||||
getFollows(res[0])
|
||||
.then(async (res) => {
|
||||
follows.set(res);
|
||||
|
||||
|
@ -25,10 +25,10 @@ export default function Page() {
|
||||
const initDB = useCallback(async () => {
|
||||
if (db) {
|
||||
await db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, privkey TEXT NOT NULL, pubkey TEXT NOT NULL, npub TEXT, nsec TEXT, metadata JSON, UNIQUE(privkey));'
|
||||
'CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, privkey TEXT NOT NULL, pubkey TEXT NOT NULL, npub TEXT, nsec TEXT, current INTEGER DEFAULT "0" NOT NULL, metadata JSON, UNIQUE(privkey));'
|
||||
);
|
||||
await db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS followings (id INTEGER PRIMARY KEY, pubkey TEXT NOT NULL, account TEXT, UNIQUE(pubkey));'
|
||||
'CREATE TABLE IF NOT EXISTS follows (id INTEGER PRIMARY KEY, pubkey TEXT NOT NULL, account TEXT, UNIQUE(pubkey));'
|
||||
);
|
||||
await db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS note_reactions (id INTEGER PRIMARY KEY, reaction_id TEXT NOT NULL, e TEXT, p TEXT, UNIQUE(reaction_id));'
|
||||
|
@ -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
|
||||
)}')`
|
||||
);
|
||||
|
@ -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}")`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
@ -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}")`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -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
|
||||
)}')`
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user