Skip to content

Commit

Permalink
enh(ui): 描画しているUIをprovide/injectする
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed May 4, 2024
1 parent a3f979f commit 774bdd1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/frontend/src/scripts/tms/provide-ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { inject, provide } from 'vue';

type Ui = (
| 'universal'
| 'deck'
| 'classic'
| 'visitor'
| 'zen'
| 'minimum'
);

const UI_PROVIDE_KEY = Symbol('UiProvideKey');

export const provideUi = (ui: Ui): void => {
provide(UI_PROVIDE_KEY, ui);
};

export const injectUi = (): Ui | undefined => {
return inject<Ui>(UI_PROVIDE_KEY);
};
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/classic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js';
import { miLocalStorage } from '@/local-storage.js';
import { mainRouter } from '@/router/main.js';
import { provideUi } from '@/scripts/tms/provide-ui.js';
const XHeaderMenu = defineAsyncComponent(() => import('./classic.header.vue'));
const XWidgets = defineAsyncComponent(() => import('./universal.widgets.vue'));

provideUi('classic');

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

const DESKTOP_THRESHOLD = 1100;
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/deck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import XDirectColumn from '@/ui/deck/direct-column.vue';
import XRoleTimelineColumn from '@/ui/deck/role-timeline-column.vue';
import { mainRouter } from '@/router/main.js';
import { MenuItem } from '@/types/menu.js';
import { provideUi } from '@/scripts/tms/provide-ui.js';
const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue'));
const XAnnouncements = defineAsyncComponent(() => import('@/ui/_common_/announcements.vue'));

Expand All @@ -134,6 +135,8 @@ const columnComponents = {
roleTimeline: XRoleTimelineColumn,
};

provideUi('deck');

mainRouter.navHook = (path, flag): boolean => {
if (flag === 'forcePage') return false;
const noMainColumn = !deckStore.state.columns.some(x => x.type === 'main');
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/minimum.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import XCommon from './_common_/common.vue';
import { PageMetadata, provideMetadataReceiver, provideReactiveMetadata } from '@/scripts/page-metadata.js';
import { instanceName } from '@/config.js';
import { mainRouter } from '@/router/main.js';
import { provideUi } from '@/scripts/tms/provide-ui.js';

provideUi('minimum');

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/universal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ import { miLocalStorage } from '@/local-storage.js';
import { CURRENT_STICKY_BOTTOM } from '@/const.js';
import { useScrollPositionManager } from '@/nirax.js';
import { mainRouter } from '@/router/main.js';
import { provideUi } from '@/scripts/tms/provide-ui.js';

const XWidgets = defineAsyncComponent(() => import('./universal.widgets.vue'));
const XSidebar = defineAsyncComponent(() => import('@/ui/_common_/navbar.vue'));
const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue'));
const XAnnouncements = defineAsyncComponent(() => import('@/ui/_common_/announcements.vue'));

provideUi('universal');

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

const DESKTOP_THRESHOLD = 1100;
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/visitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ import MkVisitorDashboard from '@/components/MkVisitorDashboard.vue';
import XSigninDialog from '@/components/MkSigninDialog.vue';
import XSignupDialog from '@/components/MkSignupDialog.vue';
import XCommon from './_common_/common.vue';
import { provideUi } from '@/scripts/tms/provide-ui.js';

provideUi('visitor');

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/ui/zen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { PageMetadata, provideMetadataReceiver, provideReactiveMetadata } from '
import { instanceName, ui } from '@/config.js';
import { i18n } from '@/i18n.js';
import { mainRouter } from '@/router/main.js';
import { provideUi } from '@/scripts/tms/provide-ui.js';

provideUi('zen');

const isRoot = computed(() => mainRouter.currentRoute.value.name === 'index');

Expand Down

0 comments on commit 774bdd1

Please sign in to comment.