From 10a18cd514e8c493ed2899b20d11910bb8401b72 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Jun 2022 17:38:49 +0900 Subject: [PATCH] refactor(client): Refine routing (#8846) --- packages/client/package.json | 1 - packages/client/src/account.ts | 34 +- packages/client/src/components/chart.vue | 94 +-- .../src/components/drive-file-thumbnail.vue | 2 +- .../client/src/components/form/folder.vue | 4 +- packages/client/src/components/global/a.vue | 31 +- .../client/src/components/global/header.vue | 361 --------- .../src/components/global/page-header.vue | 300 ++++++++ .../src/components/global/router-view.vue | 39 + packages/client/src/components/index.ts | 9 +- .../src/components/modal-page-window.vue | 225 +++--- packages/client/src/components/note.vue | 2 +- .../client/src/components/page-window.vue | 257 +++---- packages/client/src/components/ui/window.vue | 69 +- packages/client/src/init.ts | 14 +- packages/client/src/menu.ts | 31 +- packages/client/src/nirax.ts | 200 +++++ packages/client/src/os.ts | 7 - packages/client/src/pages/_error_.vue | 14 +- packages/client/src/pages/about-misskey.vue | 131 ++-- packages/client/src/pages/about.vue | 153 ++-- packages/client/src/pages/admin-file.vue | 69 +- packages/client/src/pages/admin/_header_.vue | 249 +++++++ packages/client/src/pages/admin/abuses.vue | 80 +- packages/client/src/pages/admin/ads.vue | 103 +-- .../client/src/pages/admin/announcements.vue | 81 +- .../client/src/pages/admin/bot-protection.vue | 1 - packages/client/src/pages/admin/database.vue | 23 +- .../client/src/pages/admin/email-settings.vue | 121 +-- packages/client/src/pages/admin/emojis.vue | 184 ++--- packages/client/src/pages/admin/files.vue | 119 +-- packages/client/src/pages/admin/index.vue | 50 +- .../client/src/pages/admin/instance-block.vue | 38 +- .../client/src/pages/admin/integrations.vue | 27 +- .../client/src/pages/admin/object-storage.vue | 143 ++-- .../client/src/pages/admin/other-settings.vue | 41 +- packages/client/src/pages/admin/overview.vue | 22 +- .../client/src/pages/admin/proxy-account.vue | 23 +- packages/client/src/pages/admin/queue.vue | 57 +- packages/client/src/pages/admin/relays.vue | 63 +- packages/client/src/pages/admin/security.vue | 70 +- packages/client/src/pages/admin/settings.vue | 301 ++++---- packages/client/src/pages/admin/users.vue | 174 ++--- packages/client/src/pages/announcements.vue | 86 +-- .../client/src/pages/antenna-timeline.vue | 135 ++-- packages/client/src/pages/api-console.vue | 65 +- packages/client/src/pages/auth.vue | 18 +- packages/client/src/pages/channel-editor.vue | 207 +++-- packages/client/src/pages/channel.vue | 147 ++-- packages/client/src/pages/channels.vue | 149 ++-- packages/client/src/pages/clip.vue | 130 ++-- packages/client/src/pages/drive.vue | 20 +- packages/client/src/pages/emojis.category.vue | 1 - packages/client/src/pages/emojis.vue | 36 +- packages/client/src/pages/explore.vue | 243 +++--- packages/client/src/pages/favorites.vue | 45 +- packages/client/src/pages/featured.vue | 21 +- packages/client/src/pages/federation.vue | 201 ++--- packages/client/src/pages/follow-requests.vue | 20 +- packages/client/src/pages/follow.vue | 15 +- packages/client/src/pages/gallery/edit.vue | 169 ++--- packages/client/src/pages/gallery/index.vue | 205 +++-- packages/client/src/pages/gallery/post.vue | 199 +++-- packages/client/src/pages/instance-info.vue | 39 +- packages/client/src/pages/mentions.vue | 23 +- packages/client/src/pages/messages.vue | 25 +- packages/client/src/pages/messaging/index.vue | 288 +++---- .../src/pages/messaging/messaging-room.vue | 18 +- packages/client/src/pages/mfm-cheat-sheet.vue | 596 ++++++++------- packages/client/src/pages/miauth.vue | 26 +- .../client/src/pages/my-antennas/create.vue | 24 +- .../client/src/pages/my-antennas/edit.vue | 22 +- .../client/src/pages/my-antennas/index.vue | 23 +- packages/client/src/pages/my-clips/index.vue | 29 +- packages/client/src/pages/my-groups/group.vue | 178 ----- packages/client/src/pages/my-groups/index.vue | 147 ---- packages/client/src/pages/my-lists/index.vue | 29 +- packages/client/src/pages/my-lists/list.vue | 161 ++-- packages/client/src/pages/not-found.vue | 16 +- packages/client/src/pages/note.vue | 196 +++-- packages/client/src/pages/notifications.vue | 77 +- .../src/pages/page-editor/page-editor.vue | 705 +++++++++--------- packages/client/src/pages/page.vue | 215 +++--- packages/client/src/pages/pages.vue | 149 ++-- packages/client/src/pages/preview.vue | 18 +- packages/client/src/pages/reset-password.vue | 43 +- packages/client/src/pages/scratchpad.vue | 26 +- packages/client/src/pages/search.vue | 29 +- .../src/pages/settings/account-info.vue | 18 +- .../client/src/pages/settings/accounts.vue | 26 +- packages/client/src/pages/settings/api.vue | 20 +- packages/client/src/pages/settings/apps.vue | 24 +- .../client/src/pages/settings/custom-css.vue | 18 +- packages/client/src/pages/settings/deck.vue | 20 +- .../src/pages/settings/delete-account.vue | 21 +- packages/client/src/pages/settings/drive.vue | 26 +- packages/client/src/pages/settings/email.vue | 24 +- .../client/src/pages/settings/general.vue | 23 +- .../src/pages/settings/import-export.vue | 18 +- packages/client/src/pages/settings/index.vue | 95 +-- .../src/pages/settings/instance-mute.vue | 16 +- .../client/src/pages/settings/integration.vue | 22 +- packages/client/src/pages/settings/menu.vue | 26 +- .../client/src/pages/settings/mute-block.vue | 20 +- .../src/pages/settings/notifications.vue | 22 +- packages/client/src/pages/settings/other.vue | 20 +- .../src/pages/settings/plugin.install.vue | 36 +- packages/client/src/pages/settings/plugin.vue | 20 +- .../client/src/pages/settings/privacy.vue | 16 +- .../client/src/pages/settings/profile.vue | 16 +- .../client/src/pages/settings/reaction.vue | 26 +- .../client/src/pages/settings/security.vue | 35 +- packages/client/src/pages/settings/sounds.vue | 40 +- .../src/pages/settings/theme.install.vue | 24 +- .../src/pages/settings/theme.manage.vue | 18 +- packages/client/src/pages/settings/theme.vue | 23 +- .../src/pages/settings/webhook.edit.vue | 22 +- .../client/src/pages/settings/webhook.new.vue | 16 +- .../client/src/pages/settings/webhook.vue | 18 +- .../client/src/pages/settings/word-mute.vue | 20 +- packages/client/src/pages/share.vue | 254 +++---- packages/client/src/pages/signup-complete.vue | 14 +- packages/client/src/pages/tag.vue | 18 +- packages/client/src/pages/theme-editor.vue | 44 +- packages/client/src/pages/timeline.vue | 138 ++-- packages/client/src/pages/user-info.vue | 409 +++++----- .../client/src/pages/user-list-timeline.vue | 128 ++-- packages/client/src/pages/user/index.vue | 465 ++++++------ packages/client/src/pages/welcome.vue | 16 +- packages/client/src/router.ts | 372 +++++---- packages/client/src/scripts/get-user-menu.ts | 58 +- packages/client/src/scripts/navigate.ts | 34 - packages/client/src/scripts/page-metadata.ts | 41 + packages/client/src/scripts/search.ts | 16 +- .../client/src/scripts/use-leave-guard.ts | 1 - packages/client/src/symbols.ts | 1 - packages/client/src/ui/_common_/sw-inject.ts | 15 +- packages/client/src/ui/classic.side.vue | 148 ---- packages/client/src/ui/classic.vue | 267 +++---- packages/client/src/ui/deck.vue | 33 +- packages/client/src/ui/deck/main-column.vue | 40 +- packages/client/src/ui/desktop.vue | 70 -- packages/client/src/ui/universal.vue | 89 +-- packages/client/src/ui/visitor/a.vue | 25 +- packages/client/src/ui/visitor/b.vue | 146 ++-- packages/client/src/ui/zen.vue | 99 +-- packages/client/tsconfig.json | 3 +- packages/client/vite.config.ts | 6 +- packages/client/yarn.lock | 12 - 149 files changed, 6312 insertions(+), 6670 deletions(-) delete mode 100644 packages/client/src/components/global/header.vue create mode 100644 packages/client/src/components/global/page-header.vue create mode 100644 packages/client/src/components/global/router-view.vue create mode 100644 packages/client/src/nirax.ts create mode 100644 packages/client/src/pages/admin/_header_.vue delete mode 100644 packages/client/src/pages/my-groups/group.vue delete mode 100644 packages/client/src/pages/my-groups/index.vue delete mode 100644 packages/client/src/scripts/navigate.ts create mode 100644 packages/client/src/scripts/page-metadata.ts delete mode 100644 packages/client/src/symbols.ts delete mode 100644 packages/client/src/ui/classic.side.vue delete mode 100644 packages/client/src/ui/desktop.vue diff --git a/packages/client/package.json b/packages/client/package.json index 83c8086e2..f1ab23a55 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -77,7 +77,6 @@ "vite": "2.9.10", "vue": "3.2.37", "vue-prism-editor": "2.0.0-alpha.2", - "vue-router": "4.0.16", "vuedraggable": "4.0.1", "websocket": "1.0.34", "ws": "8.8.0" diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index ce4af61f1..2b07dd199 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -1,11 +1,11 @@ -import { del, get, set } from '@/scripts/idb-proxy'; import { defineAsyncComponent, reactive } from 'vue'; import * as misskey from 'misskey-js'; +import { showSuspendedDialog } from './scripts/show-suspended-dialog'; +import { i18n } from './i18n'; +import { del, get, set } from '@/scripts/idb-proxy'; import { apiUrl } from '@/config'; import { waiting, api, popup, popupMenu, success, alert } from '@/os'; import { unisonReload, reloadChannel } from '@/scripts/unison-reload'; -import { showSuspendedDialog } from './scripts/show-suspended-dialog'; -import { i18n } from './i18n'; // TODO: 他のタブと永続化されたstateを同期 @@ -22,13 +22,7 @@ export async function signout() { waiting(); localStorage.removeItem('account'); - //#region Remove account - const accounts = await getAccounts(); - accounts.splice(accounts.findIndex(x => x.id === $i.id), 1); - - if (accounts.length > 0) await set('accounts', accounts); - else await del('accounts'); - //#endregion + await removeAccount($i.id); //#region Remove service worker registration try { @@ -55,7 +49,7 @@ export async function signout() { } catch (err) {} //#endregion - document.cookie = `igi=; path=/`; + document.cookie = 'igi=; path=/'; if (accounts.length > 0) login(accounts[0].token); else unisonReload('/'); @@ -72,14 +66,22 @@ export async function addAccount(id: Account['id'], token: Account['token']) { } } +export async function removeAccount(id: Account['id']) { + const accounts = await getAccounts(); + accounts.splice(accounts.findIndex(x => x.id === id), 1); + + if (accounts.length > 0) await set('accounts', accounts); + else await del('accounts'); +} + function fetchAccount(token: string): Promise { return new Promise((done, fail) => { // Fetch user fetch(`${apiUrl}/i`, { method: 'POST', body: JSON.stringify({ - i: token - }) + i: token, + }), }) .then(res => res.json()) .then(res => { @@ -216,13 +218,13 @@ export async function openAccountMenu(opts: { type: 'link', icon: 'fas fa-users', text: i18n.ts.manageAccounts, - to: `/settings/accounts`, + to: '/settings/accounts', }]], ev.currentTarget ?? ev.target, { - align: 'left' + align: 'left', }); } else { popupMenu([...(opts.includeCurrentAccount ? [createItem($i)] : []), ...accountItemPromises], ev.currentTarget ?? ev.target, { - align: 'left' + align: 'left', }); } } diff --git a/packages/client/src/components/chart.vue b/packages/client/src/components/chart.vue index 4e9c4e587..5e9c2f03b 100644 --- a/packages/client/src/components/chart.vue +++ b/packages/client/src/components/chart.vue @@ -13,7 +13,7 @@ id-denylist violation when setting it. This is causing about 60+ lint issues. As this is part of Chart.js's API it makes sense to disable the check here. */ -import { defineProps, onMounted, ref, watch, PropType, onUnmounted } from 'vue'; +import { onMounted, ref, watch, PropType, onUnmounted } from 'vue'; import { Chart, ArcElement, @@ -53,7 +53,7 @@ const props = defineProps({ limit: { type: Number, required: false, - default: 90 + default: 90, }, span: { type: String as PropType<'hour' | 'day'>, @@ -62,22 +62,22 @@ const props = defineProps({ detailed: { type: Boolean, required: false, - default: false + default: false, }, stacked: { type: Boolean, required: false, - default: false + default: false, }, bar: { type: Boolean, required: false, - default: false + default: false, }, aspectRatio: { type: Number, required: false, - default: null + default: null, }, }); @@ -156,7 +156,7 @@ const getDate = (ago: number) => { const format = (arr) => { return arr.map((v, i) => ({ x: getDate(i).getTime(), - y: v + y: v, })); }; @@ -343,7 +343,7 @@ const render = () => { min: 'original', max: 'original', }, - } + }, } : undefined, //gradient, }, @@ -367,8 +367,8 @@ const render = () => { ctx.stroke(); ctx.restore(); } - } - }] + }, + }], }); }; @@ -433,18 +433,18 @@ const fetchApRequestChart = async (): Promise => { name: 'In', type: 'area', color: '#008FFB', - data: format(raw.inboxReceived) + data: format(raw.inboxReceived), }, { name: 'Out (succ)', type: 'area', color: '#00E396', - data: format(raw.deliverSucceeded) + data: format(raw.deliverSucceeded), }, { name: 'Out (fail)', type: 'area', color: '#FEB019', - data: format(raw.deliverFailed) - }] + data: format(raw.deliverFailed), + }], }; }; @@ -456,7 +456,7 @@ const fetchNotesChart = async (type: string): Promise => { type: 'line', data: format(type === 'combined' ? sum(raw.local.inc, negate(raw.local.dec), raw.remote.inc, negate(raw.remote.dec)) - : sum(raw[type].inc, negate(raw[type].dec)) + : sum(raw[type].inc, negate(raw[type].dec)), ), color: '#888888', }, { @@ -464,7 +464,7 @@ const fetchNotesChart = async (type: string): Promise => { type: 'area', data: format(type === 'combined' ? sum(raw.local.diffs.renote, raw.remote.diffs.renote) - : raw[type].diffs.renote + : raw[type].diffs.renote, ), color: colors.green, }, { @@ -472,7 +472,7 @@ const fetchNotesChart = async (type: string): Promise => { type: 'area', data: format(type === 'combined' ? sum(raw.local.diffs.reply, raw.remote.diffs.reply) - : raw[type].diffs.reply + : raw[type].diffs.reply, ), color: colors.yellow, }, { @@ -480,7 +480,7 @@ const fetchNotesChart = async (type: string): Promise => { type: 'area', data: format(type === 'combined' ? sum(raw.local.diffs.normal, raw.remote.diffs.normal) - : raw[type].diffs.normal + : raw[type].diffs.normal, ), color: colors.blue, }, { @@ -488,7 +488,7 @@ const fetchNotesChart = async (type: string): Promise => { type: 'area', data: format(type === 'combined' ? sum(raw.local.diffs.withFile, raw.remote.diffs.withFile) - : raw[type].diffs.withFile + : raw[type].diffs.withFile, ), color: colors.purple, }], @@ -522,21 +522,21 @@ const fetchUsersChart = async (total: boolean): Promise => { type: 'line', data: format(total ? sum(raw.local.total, raw.remote.total) - : sum(raw.local.inc, negate(raw.local.dec), raw.remote.inc, negate(raw.remote.dec)) + : sum(raw.local.inc, negate(raw.local.dec), raw.remote.inc, negate(raw.remote.dec)), ), }, { name: 'Local', type: 'area', data: format(total ? raw.local.total - : sum(raw.local.inc, negate(raw.local.dec)) + : sum(raw.local.inc, negate(raw.local.dec)), ), }, { name: 'Remote', type: 'area', data: format(total ? raw.remote.total - : sum(raw.remote.inc, negate(raw.remote.dec)) + : sum(raw.remote.inc, negate(raw.remote.dec)), ), }], }; @@ -607,8 +607,8 @@ const fetchDriveChart = async (): Promise => { raw.local.incSize, negate(raw.local.decSize), raw.remote.incSize, - negate(raw.remote.decSize) - ) + negate(raw.remote.decSize), + ), ), }, { name: 'Local +', @@ -642,8 +642,8 @@ const fetchDriveFilesChart = async (): Promise => { raw.local.incCount, negate(raw.local.decCount), raw.remote.incCount, - negate(raw.remote.decCount) - ) + negate(raw.remote.decCount), + ), ), }, { name: 'Local +', @@ -672,18 +672,18 @@ const fetchInstanceRequestsChart = async (): Promise => { name: 'In', type: 'area', color: '#008FFB', - data: format(raw.requests.received) + data: format(raw.requests.received), }, { name: 'Out (succ)', type: 'area', color: '#00E396', - data: format(raw.requests.succeeded) + data: format(raw.requests.succeeded), }, { name: 'Out (fail)', type: 'area', color: '#FEB019', - data: format(raw.requests.failed) - }] + data: format(raw.requests.failed), + }], }; }; @@ -696,9 +696,9 @@ const fetchInstanceUsersChart = async (total: boolean): Promise = color: '#008FFB', data: format(total ? raw.following.total - : sum(raw.following.inc, negate(raw.following.dec)) - ) + : sum(raw.following.inc, negate(raw.following.dec)), + ), }, { name: 'Followers', type: 'area', color: '#00E396', data: format(total ? raw.followers.total - : sum(raw.followers.inc, negate(raw.followers.dec)) - ) - }] + : sum(raw.followers.inc, negate(raw.followers.dec)), + ), + }], }; }; @@ -750,9 +750,9 @@ const fetchInstanceDriveUsageChart = async (total: boolean): Promise { .zdjebgpv { position: relative; display: flex; - background: #e1e1e1; + background: var(--panel); border-radius: 8px; overflow: clip; diff --git a/packages/client/src/components/form/folder.vue b/packages/client/src/components/form/folder.vue index 1b960657d..a9d8bd97b 100644 --- a/packages/client/src/components/form/folder.vue +++ b/packages/client/src/components/form/folder.vue @@ -9,13 +9,13 @@ - +
-
+ diff --git a/packages/client/src/components/global/a.vue b/packages/client/src/components/global/a.vue index 5287d59b3..c7cf12e8c 100644 --- a/packages/client/src/components/global/a.vue +++ b/packages/client/src/components/global/a.vue @@ -5,13 +5,13 @@ diff --git a/packages/client/src/components/global/header.vue b/packages/client/src/components/global/header.vue deleted file mode 100644 index 63db19a52..000000000 --- a/packages/client/src/components/global/header.vue +++ /dev/null @@ -1,361 +0,0 @@ - - - - - diff --git a/packages/client/src/components/global/page-header.vue b/packages/client/src/components/global/page-header.vue new file mode 100644 index 000000000..c01631c6a --- /dev/null +++ b/packages/client/src/components/global/page-header.vue @@ -0,0 +1,300 @@ + + + + + diff --git a/packages/client/src/components/global/router-view.vue b/packages/client/src/components/global/router-view.vue new file mode 100644 index 000000000..393ba30c3 --- /dev/null +++ b/packages/client/src/components/global/router-view.vue @@ -0,0 +1,39 @@ + + + diff --git a/packages/client/src/components/index.ts b/packages/client/src/components/index.ts index 26bac6324..aa8a591e5 100644 --- a/packages/client/src/components/index.ts +++ b/packages/client/src/components/index.ts @@ -10,15 +10,17 @@ import MkEllipsis from './global/ellipsis.vue'; import MkTime from './global/time.vue'; import MkUrl from './global/url.vue'; import I18n from './global/i18n'; +import RouterView from './global/router-view.vue'; import MkLoading from './global/loading.vue'; import MkError from './global/error.vue'; import MkAd from './global/ad.vue'; -import MkHeader from './global/header.vue'; +import MkPageHeader from './global/page-header.vue'; import MkSpacer from './global/spacer.vue'; import MkStickyContainer from './global/sticky-container.vue'; export default function(app: App) { app.component('I18n', I18n); + app.component('RouterView', RouterView); app.component('Mfm', Mfm); app.component('MkA', MkA); app.component('MkAcct', MkAcct); @@ -31,7 +33,7 @@ export default function(app: App) { app.component('MkLoading', MkLoading); app.component('MkError', MkError); app.component('MkAd', MkAd); - app.component('MkHeader', MkHeader); + app.component('MkPageHeader', MkPageHeader); app.component('MkSpacer', MkSpacer); app.component('MkStickyContainer', MkStickyContainer); } @@ -39,6 +41,7 @@ export default function(app: App) { declare module '@vue/runtime-core' { export interface GlobalComponents { I18n: typeof I18n; + RouterView: typeof RouterView; Mfm: typeof Mfm; MkA: typeof MkA; MkAcct: typeof MkAcct; @@ -51,7 +54,7 @@ declare module '@vue/runtime-core' { MkLoading: typeof MkLoading; MkError: typeof MkError; MkAd: typeof MkAd; - MkHeader: typeof MkHeader; + MkPageHeader: typeof MkPageHeader; MkSpacer: typeof MkSpacer; MkStickyContainer: typeof MkStickyContainer; } diff --git a/packages/client/src/components/modal-page-window.vue b/packages/client/src/components/modal-page-window.vue index 21bdb657b..aef70f113 100644 --- a/packages/client/src/components/modal-page-window.vue +++ b/packages/client/src/components/modal-page-window.vue @@ -1,163 +1,118 @@ - diff --git a/packages/client/src/pages/admin/abuses.vue b/packages/client/src/pages/admin/abuses.vue index e1d0361c0..2b6dadf7c 100644 --- a/packages/client/src/pages/admin/abuses.vue +++ b/packages/client/src/pages/admin/abuses.vue @@ -1,28 +1,31 @@ diff --git a/packages/client/src/pages/admin/ads.vue b/packages/client/src/pages/admin/ads.vue index b18e08db9..05557469e 100644 --- a/packages/client/src/pages/admin/ads.vue +++ b/packages/client/src/pages/admin/ads.vue @@ -1,21 +1,23 @@ diff --git a/packages/client/src/pages/admin/announcements.vue b/packages/client/src/pages/admin/announcements.vue index 97774975d..025897d09 100644 --- a/packages/client/src/pages/admin/announcements.vue +++ b/packages/client/src/pages/admin/announcements.vue @@ -1,34 +1,40 @@ diff --git a/packages/client/src/pages/admin/bot-protection.vue b/packages/client/src/pages/admin/bot-protection.vue index 30fee5015..d2e7919b4 100644 --- a/packages/client/src/pages/admin/bot-protection.vue +++ b/packages/client/src/pages/admin/bot-protection.vue @@ -51,7 +51,6 @@ import FormButton from '@/components/ui/button.vue'; import FormSuspense from '@/components/form/suspense.vue'; import FormSlot from '@/components/form/slot.vue'; import * as os from '@/os'; -import * as symbols from '@/symbols'; import { fetchInstance } from '@/instance'; const MkCaptcha = defineAsyncComponent(() => import('@/components/captcha.vue')); diff --git a/packages/client/src/pages/admin/database.vue b/packages/client/src/pages/admin/database.vue index d3519922b..b9c5f9e39 100644 --- a/packages/client/src/pages/admin/database.vue +++ b/packages/client/src/pages/admin/database.vue @@ -1,12 +1,13 @@ -