ya yeet
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './CPostView';
|
||||
export * from './PostView';
|
||||
Reference in New Issue
Block a user