Files
Homarr/src/components/Dashboard/Wrappers/WrapperContent.tsx

72 lines
2.3 KiB
TypeScript
Raw Normal View History

import { GridStack } from 'fily-publish-gridstack';
import { MutableRefObject, RefObject } from 'react';
import { AppType } from '../../../types/app';
import Widgets from '../../../widgets';
import { WidgetWrapper } from '../../../widgets/WidgetWrapper';
import { IWidget, IWidgetDefinition } from '../../../widgets/widgets';
import { appTileDefinition } from '../Tiles/Apps/AppTile';
import { GridstackTileWrapper } from '../Tiles/TileWrapper';
2023-01-06 22:46:07 +01:00
import { useGridstackStore } from './gridstack/store';
interface WrapperContentProps {
apps: AppType[];
widgets: IWidget<string, any>[];
refs: {
wrapper: RefObject<HTMLDivElement>;
items: MutableRefObject<Record<string, RefObject<HTMLDivElement>>>;
gridstack: MutableRefObject<GridStack | undefined>;
};
}
2022-12-22 11:29:51 +09:00
export function WrapperContent({ apps, refs, widgets }: WrapperContentProps) {
2023-01-07 09:45:00 +01:00
const shapeSize = useGridstackStore((x) => x.currentShapeSize);
2023-01-06 22:46:07 +01:00
2023-01-07 09:45:00 +01:00
if (!shapeSize) return null;
2023-01-06 22:46:07 +01:00
2022-12-22 11:29:51 +09:00
return (
<>
{apps?.map((app) => {
const { component: TileComponent, ...tile } = appTileDefinition;
2022-12-22 11:29:51 +09:00
return (
<GridstackTileWrapper
id={app.id}
type="app"
key={app.id}
itemRef={refs.items.current[app.id]}
{...tile}
2023-01-07 23:25:13 +01:00
{...(app.shape[shapeSize]?.location ?? {})}
{...(app.shape[shapeSize]?.size ?? {})}
2022-12-22 11:29:51 +09:00
>
<TileComponent className="grid-stack-item-content" app={app} />
</GridstackTileWrapper>
);
})}
{widgets.map((widget) => {
2023-03-30 21:54:44 +02:00
const definition = Widgets[widget.type as keyof typeof Widgets] as
2022-12-22 11:29:51 +09:00
| IWidgetDefinition
| undefined;
if (!definition) return null;
2022-12-22 11:29:51 +09:00
return (
<GridstackTileWrapper
type="widget"
key={widget.id}
itemRef={refs.items.current[widget.id]}
2023-03-30 21:54:44 +02:00
id={widget.id}
2022-12-22 11:29:51 +09:00
{...definition.gridstack}
2023-01-06 22:46:07 +01:00
{...widget.shape[shapeSize]?.location}
{...widget.shape[shapeSize]?.size}
2022-12-22 11:29:51 +09:00
>
<WidgetWrapper
className="grid-stack-item-content"
widget={widget}
2023-03-30 21:54:44 +02:00
widgetType={widget.type}
WidgetComponent={definition.component}
/>
2022-12-22 11:29:51 +09:00
</GridstackTileWrapper>
);
})}
</>
);
}