This commit is contained in:
2024-07-06 23:19:42 +02:00
parent 5f97af3f96
commit 20620cff41
13 changed files with 3 additions and 5 deletions
@@ -0,0 +1,53 @@
"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>
</>
);
}
@@ -0,0 +1,60 @@
"use server";
cache: "no-store";
import { ReactNode } from "react";
import {
deletePost,
getPostsWithBucketsAndProject,
updatePost,
GetPostsAttributes,
PostServerActions,
} from "@/app/lib/actions/entityManagement/post/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { handleActionResult } from "@/app/lib/actions/clientActionHandler";
import { CPostView } from "@/views/admin/post";
type Props = {
children?: ReactNode;
};
export async function PostView(props: Props) {
const sync = await dbSync;
const headings: string[] = [
"#",
"Title",
"Content",
"Project",
"CreatedAt",
"UpdatedAt",
];
const actions: PostServerActions = {
deletePost: deletePost,
getPosts: getPostsWithBucketsAndProject,
getProjects: getProjects,
savePost: updatePost,
// uploadAttachment:tryCreateAttachment
};
const posts: GetPostsAttributes[] | undefined = handleActionResult(
await getPostsWithBucketsAndProject()
);
const projects = await Project.findAll().then((projects) =>
projects.map((project) => JSON.parse(JSON.stringify(project)))
);
return (
<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
<div className="w-[100%] m-auto">
<CPostView
posts={posts ? posts : []}
projects={projects}
headings={headings}
actions={actions}
/>
</div>
</div>
);
}
+2
View File
@@ -0,0 +1,2 @@
export * from './CPostView';
export * from './PostView';
@@ -0,0 +1,68 @@
cache: "no-store";
import { ReactNode, useEffect } from "react";
import EntityManagementTable from "../../../components/client/EntityManagementTable";
import PostTable from "@/components/client/admin/PostTable";
import {
deletePost,
getPostsWithBucketsAndProject,
updatePost,
} from "@/app/lib/actions/entityManagement/post/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
import { Attributes } from "@sequelize/core";
import * as util from "util";
type Props = {
children?: ReactNode;
};
async function getHeadings() {
let headings: string[] = [];
for (const key in Project.getAttributes()) {
headings.push(key);
}
return headings;
}
export async function ProjectView(props: Props) {
const sync = await dbSync;
const actions = {
deletePost: deletePost,
getProjects:getProjects,
savePost:updatePost,
// uploadAttachment:tryCreateAttachment
};
const projects: Project[] = await Project.findAll().then((projects) =>
projects.map((e) => JSON.parse(JSON.stringify(e)))
);
return (
<>
<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
<div className="w-[100%] m-auto">
<EntityManagementTable
entityName="Project"
headings={[
'#',
'Title',
'Content',
'Project',
'Date Created',
'Date Modified',
'Edit',
'Delete',
]}>
{""}
</EntityManagementTable>
{/* <PostTable data={posts}
projects={projects}
headings={headings}
actions={actions}>
</PostTable> */}
</div>
</div>
</>
);
}
@@ -0,0 +1,2 @@
export * from './CProjectView';
export * from './ProjectView';
View File