mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-25 01:08:50 +01:00
Cache search enabled check
This commit is contained in:
parent
8ddc44fba6
commit
137ad7f4dd
1 changed files with 15 additions and 7 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue