2024-07-06 23:23:18 +02:00

54 lines
1.2 KiB
TypeScript

"use client";
import PostTable, {
PostTableStateProps,
} from "@/components/client/admin/PostTable";
import {
GetPostsAttributes,
PostServerActions,
} from "@/app/lib/actions/entitymanagement/post/postActions";
import { EditorState } from "@/components/client/admin/PostEditor";
import { Project } from "@/models";
import { ReactNode, useState } from "react";
import { Attributes } from "@sequelize/core";
import { parseStateHook } from "@/util/state";
export type PostViewProps = {
children?: ReactNode;
headings: Array<string>;
posts: GetPostsAttributes[];
projects: Attributes<Project>[];
actions: PostServerActions;
};
export function CPostView({
// children,
headings,
posts,
projects,
actions,
}: PostViewProps) {
// Init editor state. Make sure it is not opened by default
const initEditorState: EditorState = {
isEditorOpen: false,
editorPost: posts[0],
};
// Set up required state hooks
const state: PostTableStateProps = {
posts: parseStateHook(useState(posts)),
editor: parseStateHook(useState(initEditorState)),
};
return (
<>
<PostTable
headings={headings}
posts={posts}
projects={projects}
actions={actions}
state={state}
></PostTable>
</>
);
}