mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-25 09:18:51 +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 Menu2 from '../components/menu2';
|
||||||
import Timeline from '../components/timeline';
|
import Timeline from '../components/timeline';
|
||||||
import { api } from '../utils/api';
|
import { api } from '../utils/api';
|
||||||
|
import pmem from '../utils/pmem';
|
||||||
import showToast from '../utils/show-toast';
|
import showToast from '../utils/show-toast';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
import { saveStatus } 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() {
|
function AccountStatuses() {
|
||||||
const snapStates = useSnapshot(states);
|
const snapStates = useSnapshot(states);
|
||||||
const { id, ...params } = useParams();
|
const { id, ...params } = useParams();
|
||||||
|
@ -59,14 +71,10 @@ function AccountStatuses() {
|
||||||
if (!sameCurrentInstance) return;
|
if (!sameCurrentInstance) return;
|
||||||
if (!account?.acct) return;
|
if (!account?.acct) return;
|
||||||
(async () => {
|
(async () => {
|
||||||
const results = await masto.v2.search.fetch({
|
const enabled = await isSearchEnabled(instance);
|
||||||
q: `from:${account?.acct}`,
|
setSearchEnabled(enabled);
|
||||||
type: 'statuses',
|
|
||||||
limit: 1,
|
|
||||||
});
|
|
||||||
setSearchEnabled(!!results?.statuses?.length);
|
|
||||||
})();
|
})();
|
||||||
}, [sameCurrentInstance, account?.acct]);
|
}, [instance, sameCurrentInstance, account?.acct]);
|
||||||
|
|
||||||
async function fetchAccountStatuses(firstLoad) {
|
async function fetchAccountStatuses(firstLoad) {
|
||||||
const isValidMonth = /^\d{4}-[01]\d$/.test(month);
|
const isValidMonth = /^\d{4}-[01]\d$/.test(month);
|
||||||
|
|
Loading…
Reference in a new issue