diff --git a/src/components/accountBar/account.tsx b/src/components/accountBar/account.tsx index b1ebb046..c5c13690 100644 --- a/src/components/accountBar/account.tsx +++ b/src/components/accountBar/account.tsx @@ -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 ( -
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 ) : (
)} -
+ ); }); diff --git a/src/components/checkAccount.tsx b/src/components/checkAccount.tsx index e45c78e8..c4d13705 100644 --- a/src/components/checkAccount.tsx +++ b/src/components/checkAccount.tsx @@ -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); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 8c8aef36..05d6bbda 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -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));' diff --git a/src/pages/onboarding/create.tsx b/src/pages/onboarding/create.tsx index d5ba257e..da276175 100644 --- a/src/pages/onboarding/create.tsx +++ b/src/pages/onboarding/create.tsx @@ -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 )}')` ); diff --git a/src/pages/onboarding/following.tsx b/src/pages/onboarding/following.tsx index f201cbba..e0ad2eba 100644 --- a/src/pages/onboarding/following.tsx +++ b/src/pages/onboarding/following.tsx @@ -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}")` ); }); }; diff --git a/src/pages/onboarding/follows/[pubkey].tsx b/src/pages/onboarding/follows/[pubkey].tsx index c3048219..195c05d2 100644 --- a/src/pages/onboarding/follows/[pubkey].tsx +++ b/src/pages/onboarding/follows/[pubkey].tsx @@ -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}")` ); } }); diff --git a/src/pages/onboarding/profile/[privkey].tsx b/src/pages/onboarding/profile/[privkey].tsx index 8e11f2a8..2f9feab4 100644 --- a/src/pages/onboarding/profile/[privkey].tsx +++ b/src/pages/onboarding/profile/[privkey].tsx @@ -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 )}')` );