mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 16:13:15 +00:00
21 lines
877 B
TypeScript
21 lines
877 B
TypeScript
"use client";
|
|
|
|
import { useSyncExternalStore } from 'react';
|
|
import { allPages, subscribePages, type RegisteredPage } from '@/lib/plugin-sandbox/pages';
|
|
|
|
/** Pages plugins registered with api.ui.setPages, in install order. */
|
|
export function usePluginPages(): RegisteredPage[] {
|
|
return useSyncExternalStore(subscribePages, allPages, allPages);
|
|
}
|
|
|
|
/** The in-app route of a plugin page: /apps/<pluginId>/<pageId>. */
|
|
export function pluginPageHref(page: Pick<RegisteredPage, 'pluginId' | 'id'>): string {
|
|
return `/apps/${encodeURIComponent(page.pluginId)}/${encodeURIComponent(page.id)}`;
|
|
}
|
|
|
|
/** Whether `pathname` (locale already stripped) shows this page. */
|
|
export function isPluginPageActive(pathname: string, page: Pick<RegisteredPage, 'pluginId' | 'id'>): boolean {
|
|
const href = pluginPageHref(page);
|
|
return pathname === href || pathname.startsWith(`${href}/`);
|
|
}
|