From 7759851541f9f6ef68ebf104bfb85c6c81402b6b Mon Sep 17 00:00:00 2001 From: reya Date: Sun, 26 Nov 2023 07:21:24 +0700 Subject: [PATCH] clean up --- src/app/auth/components/features/followList.tsx | 16 ++++------------ src/libs/storage/instance.ts | 11 ++++++++++- src/shared/titleBar.tsx | 6 +++--- src/shared/widgets/article.tsx | 2 +- src/shared/widgets/file.tsx | 2 +- src/shared/widgets/newsfeed.tsx | 2 +- src/shared/widgets/other/addGroupFeeds.tsx | 2 +- src/shared/widgets/other/liveUpdater.tsx | 4 ++-- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/app/auth/components/features/followList.tsx b/src/app/auth/components/features/followList.tsx index 769c1f520..03a7c29f4 100644 --- a/src/app/auth/components/features/followList.tsx +++ b/src/app/auth/components/features/followList.tsx @@ -13,21 +13,13 @@ export function FollowList() { queryKey: ['follows'], queryFn: async () => { const user = ndk.getUser({ pubkey: db.account.pubkey }); - const follows = await user.follows(); - const followsAsArr = []; - - follows.forEach((user) => { - followsAsArr.push(user.pubkey); - }); + const follows = [...(await user.follows())].map((user) => user.pubkey); // update db - await db.updateAccount('follows', JSON.stringify(followsAsArr)); - await db.updateAccount('circles', JSON.stringify(followsAsArr)); - - db.account.follows = followsAsArr; - db.account.circles = followsAsArr; + await db.updateAccount('follows', JSON.stringify(follows)); + db.account.follows = follows; - return followsAsArr; + return follows; }, refetchOnWindowFocus: false, }); diff --git a/src/libs/storage/instance.ts b/src/libs/storage/instance.ts index 23b184029..200b02a38 100644 --- a/src/libs/storage/instance.ts +++ b/src/libs/storage/instance.ts @@ -451,7 +451,7 @@ export class LumeStorage { } public async createSetting(key: string, value: string) { - const currentSetting = await this.getSettingValue(key); + const currentSetting = await this.checkSettingValue(key); if (!currentSetting) return await this.db.execute( @@ -475,6 +475,15 @@ export class LumeStorage { return results; } + public async checkSettingValue(key: string) { + const results: { key: string; value: string }[] = await this.db.select( + 'SELECT * FROM settings WHERE key = $1 ORDER BY id DESC LIMIT 1;', + [key] + ); + if (!results.length) return false; + return results[0].value; + } + public async getSettingValue(key: string) { const results: { key: string; value: string }[] = await this.db.select( 'SELECT * FROM settings WHERE key = $1 ORDER BY id DESC LIMIT 1;', diff --git a/src/shared/titleBar.tsx b/src/shared/titleBar.tsx index 36575caed..fa038ffd3 100644 --- a/src/shared/titleBar.tsx +++ b/src/shared/titleBar.tsx @@ -33,13 +33,13 @@ export function TitleBar({
{id === '9999' ? (
- {db.account.circles + {db.account.follows ?.slice(0, 8) .map((item) => )} - {db.account.circles?.length > 8 ? ( + {db.account.follows?.length > 8 ? (
- +{db.account.circles?.length - 8} + +{db.account.follows?.length - 8}
) : null} diff --git a/src/shared/widgets/article.tsx b/src/shared/widgets/article.tsx index abacbbfda..aeeb62277 100644 --- a/src/shared/widgets/article.tsx +++ b/src/shared/widgets/article.tsx @@ -40,7 +40,7 @@ export function ArticleWidget({ widget }: { widget: Widget }) { } else { filter = { kinds: [NDKKind.Article], - authors: db.account.circles, + authors: db.account.follows, }; } diff --git a/src/shared/widgets/file.tsx b/src/shared/widgets/file.tsx index a64cf62d2..bd60adcfb 100644 --- a/src/shared/widgets/file.tsx +++ b/src/shared/widgets/file.tsx @@ -40,7 +40,7 @@ export function FileWidget({ widget }: { widget: Widget }) { } else { filter = { kinds: [1063], - authors: db.account.circles, + authors: db.account.follows, }; } diff --git a/src/shared/widgets/newsfeed.tsx b/src/shared/widgets/newsfeed.tsx index d3d5704f3..5c0e9a490 100644 --- a/src/shared/widgets/newsfeed.tsx +++ b/src/shared/widgets/newsfeed.tsx @@ -39,7 +39,7 @@ export function NewsfeedWidget() { relayUrls, { kinds: [NDKKind.Text, NDKKind.Repost], - authors: db.account.circles, + authors: db.account.follows, }, FETCH_LIMIT, { asOf: pageParam === 0 ? undefined : pageParam, abortSignal: signal } diff --git a/src/shared/widgets/other/addGroupFeeds.tsx b/src/shared/widgets/other/addGroupFeeds.tsx index 4141a8d75..270628cd7 100644 --- a/src/shared/widgets/other/addGroupFeeds.tsx +++ b/src/shared/widgets/other/addGroupFeeds.tsx @@ -96,7 +96,7 @@ export function AddGroupFeeds({ currentWidgetId }: { currentWidgetId: string }) Users
- {db.account.circles.map((item: string) => ( + {db.account.follows.map((item: string) => (