2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-09-04 06:33:38 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { ComputedRef, inject, isRef, onActivated, onMounted, provide, ref, Ref } from 'vue';
|
|
|
|
|
|
|
|
export const setPageMetadata = Symbol('setPageMetadata');
|
|
|
|
export const pageMetadataProvider = Symbol('pageMetadataProvider');
|
|
|
|
|
|
|
|
export type PageMetadata = {
|
|
|
|
title: string;
|
|
|
|
subtitle?: string;
|
|
|
|
icon?: string | null;
|
2023-09-04 06:33:38 +02:00
|
|
|
avatar?: Misskey.entities.User | null;
|
|
|
|
userName?: Misskey.entities.User | null;
|
2023-12-08 05:06:42 +01:00
|
|
|
needWideArea?: boolean;
|
2022-06-20 10:38:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export function definePageMetadata(metadata: PageMetadata | null | Ref<PageMetadata | null> | ComputedRef<PageMetadata | null>): void {
|
|
|
|
const _metadata = isRef(metadata) ? metadata : ref(metadata);
|
|
|
|
|
|
|
|
provide(pageMetadataProvider, _metadata);
|
|
|
|
|
|
|
|
const set = inject(setPageMetadata) as any;
|
|
|
|
if (set) {
|
|
|
|
set(_metadata);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
set(_metadata);
|
|
|
|
});
|
|
|
|
|
|
|
|
onActivated(() => {
|
|
|
|
set(_metadata);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function provideMetadataReceiver(callback: (info: ComputedRef<PageMetadata>) => void): void {
|
|
|
|
provide(setPageMetadata, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function injectPageMetadata(): PageMetadata | undefined {
|
|
|
|
return inject(pageMetadataProvider);
|
|
|
|
}
|