From 137ad7f4dd19041d258145ffcd9cf49a32158b95 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 20 Oct 2023 20:48:30 +0800 Subject: [PATCH] Cache search enabled check --- src/pages/account-statuses.jsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pages/account-statuses.jsx b/src/pages/account-statuses.jsx index 4f9d936e..f24a416a 100644 --- a/src/pages/account-statuses.jsx +++ b/src/pages/account-statuses.jsx @@ -10,6 +10,7 @@ import Link from '../components/link'; import Menu2 from '../components/menu2'; import Timeline from '../components/timeline'; import { api } from '../utils/api'; +import pmem from '../utils/pmem'; import showToast from '../utils/show-toast'; import states from '../utils/states'; import { saveStatus } from '../utils/states'; @@ -29,6 +30,17 @@ const supportsInputMonth = (() => { } })(); +function _isSearchEnabled(instance) { + const { masto } = api({ instance }); + const results = masto.v2.search.fetch({ + q: 'from:me', + type: 'statuses', + limit: 1, + }); + return !!results?.statuses?.length; +} +const isSearchEnabled = pmem(_isSearchEnabled); + function AccountStatuses() { const snapStates = useSnapshot(states); const { id, ...params } = useParams(); @@ -59,14 +71,10 @@ function AccountStatuses() { if (!sameCurrentInstance) return; if (!account?.acct) return; (async () => { - const results = await masto.v2.search.fetch({ - q: `from:${account?.acct}`, - type: 'statuses', - limit: 1, - }); - setSearchEnabled(!!results?.statuses?.length); + const enabled = await isSearchEnabled(instance); + setSearchEnabled(enabled); })(); - }, [sameCurrentInstance, account?.acct]); + }, [instance, sameCurrentInstance, account?.acct]); async function fetchAccountStatuses(firstLoad) { const isValidMonth = /^\d{4}-[01]\d$/.test(month);