mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 04:15:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { useCallback, useSyncExternalStore } from 'react';
|
|
import { getSlotComponents, subscribeExtensionRegistry, type SlotProps } from '@/extensions/registry';
|
|
import ExtensionMount from '@/extensions/ExtensionMount';
|
|
|
|
export default function Slot({ name, data }: SlotProps) {
|
|
const subscribe = useCallback(
|
|
(listener: () => void) => subscribeExtensionRegistry(`slot:${name}`, listener),
|
|
[name]
|
|
);
|
|
const snapshot = useCallback(() => getSlotComponents(name), [name]);
|
|
const registrations = useSyncExternalStore(subscribe, snapshot);
|
|
const resetKey =
|
|
data && 'resource' in data
|
|
? `${data.kind}:${data.resource.attributes.id}`
|
|
: data && 'directory' in data
|
|
? `${data.server.attributes.uuid}:${data.directory}`
|
|
: data && 'attributes' in data
|
|
? data.attributes.uuid
|
|
: data && 'pathname' in data
|
|
? data.pathname
|
|
: name;
|
|
return (
|
|
<>
|
|
{registrations.map(({ id, extensionId, component: Component }) => (
|
|
<ExtensionMount
|
|
isSlot
|
|
key={id}
|
|
extensionId={extensionId}
|
|
context={`slot "${name}"`}
|
|
resetKey={resetKey}
|
|
>
|
|
<Component data={data} />
|
|
</ExtensionMount>
|
|
))}
|
|
</>
|
|
);
|
|
}
|