portfolio2023/src/views/admin/ClientPostView.tsx
2024-07-02 09:08:49 +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 { Dispatch, ReactNode, SetStateAction, 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 ClientPostView({
// 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>
</>
);
}