enhance(frontend): cache user lists / antennas

This commit is contained in:
syuilo 2023-09-10 17:40:59 +09:00
parent b434beb5e2
commit 85078601c2
3 changed files with 26 additions and 2 deletions

View file

@ -43,6 +43,7 @@
- Playの操作を行うAPI TokenをAPIコンソールから発行できるように - Playの操作を行うAPI TokenをAPIコンソールから発行できるように
- リアクションの表示サイズをより大きくできるように - リアクションの表示サイズをより大きくできるように
- ノート詳細ページ読み込み時のパフォーマンスを改善 - ノート詳細ページ読み込み時のパフォーマンスを改善
- タイムラインでリスト/アンテナ選択時のパフォーマンスを改善
- Fix: サーバー情報画面(`/instance-info/{domain}`)でブロックができないのを修正 - Fix: サーバー情報画面(`/instance-info/{domain}`)でブロックができないのを修正
- Fix: 未読のお知らせの「わかった」をクリック・タップしてもその場で「わかった」が消えない問題を修正 - Fix: 未読のお知らせの「わかった」をクリック・タップしてもその場で「わかった」が消えない問題を修正
- Fix: iOSで画面を回転させるとテキストサイズが変わる問題を修正 - Fix: iOSで画面を回転させるとテキストサイズが変わる問題を修正

View file

@ -30,6 +30,8 @@ type Keys =
'message_drafts' | 'message_drafts' |
'scratchpad' | 'scratchpad' |
'debug' | 'debug' |
'userListsCache' |
'antennasCache' |
`miux:${string}` | `miux:${string}` |
`ui:folder:${string}` | `ui:folder:${string}` |
`themes:${string}` | `themes:${string}` |
@ -41,4 +43,12 @@ export const miLocalStorage = {
getItem: (key: Keys): string | null => window.localStorage.getItem(key), getItem: (key: Keys): string | null => window.localStorage.getItem(key),
setItem: (key: Keys, value: string): void => window.localStorage.setItem(key, value), setItem: (key: Keys, value: string): void => window.localStorage.setItem(key, value),
removeItem: (key: Keys): void => window.localStorage.removeItem(key), removeItem: (key: Keys): void => window.localStorage.removeItem(key),
getItemAsJson: (key: Keys): any | undefined => {
const item = miLocalStorage.getItem(key);
if (item === null) {
return undefined;
}
return JSON.parse(item);
},
setItemAsJson: (key: Keys, value: any): void => window.localStorage.setItem(key, JSON.stringify(value)),
}; };

View file

@ -38,6 +38,7 @@ import { i18n } from '@/i18n';
import { instance } from '@/instance'; import { instance } from '@/instance';
import { $i } from '@/account'; import { $i } from '@/account';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { miLocalStorage } from '@/local-storage';
provide('shouldOmitHeaderTitle', true); provide('shouldOmitHeaderTitle', true);
@ -67,17 +68,24 @@ function top(): void {
} }
async function chooseList(ev: MouseEvent): Promise<void> { async function chooseList(ev: MouseEvent): Promise<void> {
const lists = await os.api('users/lists/list'); const cachedLists = miLocalStorage.getItemAsJson('userListsCache');
const lists = cachedLists ?? await os.api('users/lists/list');
const items = lists.map(list => ({ const items = lists.map(list => ({
type: 'link' as const, type: 'link' as const,
text: list.name, text: list.name,
to: `/timeline/list/${list.id}`, to: `/timeline/list/${list.id}`,
})); }));
os.popupMenu(items, ev.currentTarget ?? ev.target); 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> { async function chooseAntenna(ev: MouseEvent): Promise<void> {
const antennas = await os.api('antennas/list'); const cachedAntennas = miLocalStorage.getItemAsJson('antennasCache');
const antennas = cachedAntennas ?? await os.api('antennas/list');
const items = antennas.map(antenna => ({ const items = antennas.map(antenna => ({
type: 'link' as const, type: 'link' as const,
text: antenna.name, text: antenna.name,
@ -85,6 +93,11 @@ async function chooseAntenna(ev: MouseEvent): Promise<void> {
to: `/timeline/antenna/${antenna.id}`, to: `/timeline/antenna/${antenna.id}`,
})); }));
os.popupMenu(items, ev.currentTarget ?? ev.target); 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> { async function chooseChannel(ev: MouseEvent): Promise<void> {