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

69 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 { IWidget, IWidgetDefinition } from '../../../widgets/widgets';
import { WidgetWrapper } from '../../../widgets/WidgetWrapper';
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-06 22:46:07 +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) => {
const definition = Widgets[widget.id as keyof typeof Widgets] as
| 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]}
id={definition.id}
{...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} widgetId={widget.id}>
<definition.component className="grid-stack-item-content" widget={widget} />
</WidgetWrapper>
</GridstackTileWrapper>
);
})}
</>
);
}