2023-10-10 23:28:06 +09:00
|
|
|
import type * as firefish from "firefish-js";
|
2023-09-04 17:47:24 +09:00
|
|
|
import type { ComputedRef, Ref } from "vue";
|
|
|
|
import { inject, isRef, onActivated, onMounted, provide, ref } from "vue";
|
2023-07-20 04:17:05 +09:00
|
|
|
|
|
|
|
export const setPageMetadata = Symbol("setPageMetadata");
|
|
|
|
export const pageMetadataProvider = Symbol("pageMetadataProvider");
|
|
|
|
|
2023-09-04 17:47:24 +09:00
|
|
|
export interface PageMetadata {
|
2023-07-20 04:17:05 +09:00
|
|
|
title: string;
|
|
|
|
subtitle?: string;
|
|
|
|
icon?: string | null;
|
2023-10-10 23:28:06 +09:00
|
|
|
avatar?: firefish.entities.User | null;
|
|
|
|
userName?: firefish.entities.User | null;
|
2023-07-20 04:17:05 +09:00
|
|
|
bg?: string;
|
2023-09-04 17:47:24 +09:00
|
|
|
}
|
2023-07-20 04:17:05 +09: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);
|
|
|
|
}
|