enhance(frontend): improve some caches
This commit is contained in:
@@ -28,18 +28,17 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onActivated } from 'vue';
|
||||
import MkButton from '@/components/MkButton.vue';
|
||||
import { i18n } from '@/i18n';
|
||||
import { definePageMetadata } from '@/scripts/page-metadata';
|
||||
import { antennasCache } from '@/cache';
|
||||
import { api } from '@/os';
|
||||
import { onActivated } from 'vue';
|
||||
import { infoImageUrl } from '@/instance';
|
||||
|
||||
const antennas = $computed(() => antennasCache.value.value ?? []);
|
||||
|
||||
function fetch() {
|
||||
antennasCache.fetch(() => api('antennas/list'));
|
||||
antennasCache.fetch();
|
||||
}
|
||||
|
||||
fetch();
|
||||
@@ -62,7 +61,7 @@ definePageMetadata({
|
||||
});
|
||||
|
||||
onActivated(() => {
|
||||
antennasCache.fetch(() => api('antennas/list'));
|
||||
antennasCache.fetch();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@@ -42,7 +42,7 @@ import { $i } from '@/account';
|
||||
const items = $computed(() => userListsCache.value.value ?? []);
|
||||
|
||||
function fetch() {
|
||||
userListsCache.fetch(() => os.api('users/lists/list'));
|
||||
userListsCache.fetch();
|
||||
}
|
||||
|
||||
fetch();
|
||||
|
@@ -39,6 +39,7 @@ import { instance } from '@/instance';
|
||||
import { $i } from '@/account';
|
||||
import { definePageMetadata } from '@/scripts/page-metadata';
|
||||
import { miLocalStorage } from '@/local-storage';
|
||||
import { antennasCache, userListsCache } from '@/cache';
|
||||
|
||||
provide('shouldOmitHeaderTitle', true);
|
||||
|
||||
@@ -68,24 +69,17 @@ function top(): void {
|
||||
}
|
||||
|
||||
async function chooseList(ev: MouseEvent): Promise<void> {
|
||||
const cachedLists = miLocalStorage.getItemAsJson('userListsCache');
|
||||
const lists = cachedLists ?? await os.api('users/lists/list');
|
||||
const lists = await userListsCache.fetch();
|
||||
const items = lists.map(list => ({
|
||||
type: 'link' as const,
|
||||
text: list.name,
|
||||
to: `/timeline/list/${list.id}`,
|
||||
}));
|
||||
os.popupMenu(items, ev.currentTarget ?? ev.target);
|
||||
if (cachedLists == null) {
|
||||
miLocalStorage.setItemAsJson('userListsCache', lists);
|
||||
} else {
|
||||
miLocalStorage.setItemAsJson('userListsCache', await os.api('users/lists/list'));
|
||||
}
|
||||
}
|
||||
|
||||
async function chooseAntenna(ev: MouseEvent): Promise<void> {
|
||||
const cachedAntennas = miLocalStorage.getItemAsJson('antennasCache');
|
||||
const antennas = cachedAntennas ?? await os.api('antennas/list');
|
||||
const antennas = await antennasCache.fetch();
|
||||
const items = antennas.map(antenna => ({
|
||||
type: 'link' as const,
|
||||
text: antenna.name,
|
||||
@@ -93,11 +87,6 @@ async function chooseAntenna(ev: MouseEvent): Promise<void> {
|
||||
to: `/timeline/antenna/${antenna.id}`,
|
||||
}));
|
||||
os.popupMenu(items, ev.currentTarget ?? ev.target);
|
||||
if (cachedAntennas == null) {
|
||||
miLocalStorage.setItemAsJson('antennasCache', antennas);
|
||||
} else {
|
||||
miLocalStorage.setItemAsJson('antennasCache', await os.api('antennas/list'));
|
||||
}
|
||||
}
|
||||
|
||||
async function chooseChannel(ev: MouseEvent): Promise<void> {
|
||||
|
Reference in New Issue
Block a user