feat: add widget preview pages (#9)
* feat: add widget definition system * fix: wrong typecheck command in turbo generator * chore: fix formatting * feat: add widget preview page * chore: fix formatting and type errors * chore: fix from widget edit modal and remove some never casts * chore: address pull request feedback
This commit is contained in:
27
apps/nextjs/src/app/[locale]/widgets/[sort]/layout.tsx
Normal file
27
apps/nextjs/src/app/[locale]/widgets/[sort]/layout.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { PropsWithChildren } from "react";
|
||||
|
||||
import { widgetImports } from "@homarr/widgets";
|
||||
|
||||
import { MainNavigation } from "~/components/layout/navigation";
|
||||
import { ClientShell } from "~/components/layout/shell";
|
||||
|
||||
const getLinks = () => {
|
||||
return Object.entries(widgetImports).map(([key, value]) => {
|
||||
return {
|
||||
href: `/widgets/${key}`,
|
||||
icon: value.definition.icon,
|
||||
label: value.definition.sort,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export default function WidgetPreviewLayout({ children }: PropsWithChildren) {
|
||||
const links = getLinks();
|
||||
|
||||
return (
|
||||
<ClientShell hasHeader={false}>
|
||||
<MainNavigation links={links} />
|
||||
{children}
|
||||
</ClientShell>
|
||||
);
|
||||
}
|
||||
48
apps/nextjs/src/app/[locale]/widgets/[sort]/page.tsx
Normal file
48
apps/nextjs/src/app/[locale]/widgets/[sort]/page.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { useState } from "react";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { ActionIcon, Affix, Center, IconPencil } from "@homarr/ui";
|
||||
import type { WidgetSort } from "@homarr/widgets";
|
||||
import { loadWidgetDynamic, widgetImports } from "@homarr/widgets";
|
||||
|
||||
import { modalEvents } from "../../modals";
|
||||
|
||||
type Props = PropsWithChildren<{ params: { sort: string } }>;
|
||||
|
||||
export default function WidgetPreview(props: Props) {
|
||||
const [options, setOptions] = useState<Record<string, unknown>>({});
|
||||
if (!(props.params.sort in widgetImports)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const sort = props.params.sort as WidgetSort;
|
||||
const Comp = loadWidgetDynamic(sort);
|
||||
|
||||
return (
|
||||
<Center h="100vh">
|
||||
<Comp options={options as never} integrations={[]} />
|
||||
<Affix bottom={12} right={72}>
|
||||
<ActionIcon
|
||||
size={48}
|
||||
variant="default"
|
||||
radius="xl"
|
||||
onClick={() => {
|
||||
return modalEvents.openManagedModal({
|
||||
modal: "widgetEditModal",
|
||||
innerProps: {
|
||||
sort,
|
||||
definition: widgetImports[sort].definition.options,
|
||||
state: [options, setOptions],
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<IconPencil size={24} />
|
||||
</ActionIcon>
|
||||
</Affix>
|
||||
</Center>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user