2024-02-12 16:40:46 +01:00
|
|
|
import type { entities } from "firefish-js";
|
2023-09-02 01:27:33 +02:00
|
|
|
import type { ComputedRef, Ref } from "vue";
|
|
|
|
import { inject, isRef, onActivated, onMounted, provide, ref } from "vue";
|
2023-01-13 05:40:33 +01:00
|
|
|
|
|
|
|
export const setPageMetadata = Symbol("setPageMetadata");
|
|
|
|
export const pageMetadataProvider = Symbol("pageMetadataProvider");
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
export interface PageMetadata {
|
2022-06-20 10:38:49 +02:00
|
|
|
title: string;
|
|
|
|
subtitle?: string;
|
|
|
|
icon?: string | null;
|
2024-04-04 10:53:02 +02:00
|
|
|
avatar?: entities.UserDetailed | null;
|
2024-02-12 16:40:46 +01:00
|
|
|
userName?: entities.User | null;
|
2022-06-20 10:38:49 +02:00
|
|
|
bg?: string;
|
2024-04-12 05:31:11 +02:00
|
|
|
hideHeader?: boolean;
|
2023-09-02 01:27:33 +02:00
|
|
|
}
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
export function definePageMetadata(
|
|
|
|
metadata:
|
|
|
|
| PageMetadata
|
|
|
|
| null
|
|
|
|
| Ref<PageMetadata | null>
|
|
|
|
| ComputedRef<PageMetadata | null>,
|
|
|
|
): void {
|
2022-06-20 10:38:49 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
export function provideMetadataReceiver(
|
|
|
|
callback: (info: ComputedRef<PageMetadata>) => void,
|
|
|
|
): void {
|
2022-06-20 10:38:49 +02:00
|
|
|
provide(setPageMetadata, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function injectPageMetadata(): PageMetadata | undefined {
|
|
|
|
return inject(pageMetadataProvider);
|
|
|
|
}
|