Refactoring

This commit is contained in:
2024-06-28 08:16:28 +02:00
parent 665da4be29
commit 51c9c1f4f3
5 changed files with 23 additions and 28 deletions
+4 -13
View File
@@ -3,7 +3,6 @@
import PostTable, {
PostTableStateProps,
} from "@/components/client/admin/PostTable";
import { PostTableProps } from "../../components/client/admin/PostTable";
import {
GetPostsAttributes,
PostServerActions,
@@ -12,7 +11,7 @@ import { EditorState } from "@/components/client/admin/PostEditor";
import { Project } from "@/models";
import { Dispatch, ReactNode, SetStateAction, useState } from "react";
import { Attributes } from "@sequelize/core";
import { StateHookArray } from "@/util/types/StateHook";
import { parseStateHook, StateHookArray } from "@/util/state/stateUtils";
export type PostViewProps = {
children?: ReactNode;
@@ -23,7 +22,7 @@ export type PostViewProps = {
};
export function ClientPostView({
children,
// children,
headings,
posts,
projects,
@@ -35,17 +34,9 @@ export function ClientPostView({
editorPost: posts[0],
};
// Set up required state hooks
const [postsState, setPostsState]: StateHookArray<GetPostsAttributes[]> = useState(posts);
const [editorState, setEditorState]: StateHookArray<EditorState> = useState(initEditorState);
const state: PostTableStateProps = {
posts: {
state: postsState,
setState: setPostsState,
},
editor: {
state: editorState,
setState: setEditorState,
},
posts: parseStateHook(useState(posts)),
editor: parseStateHook(useState(initEditorState)),
};
return (
+3 -5
View File
@@ -14,8 +14,6 @@ import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { handleActionResult } from "../../app/lib/actions/clientActionHandler";
import { ClientPostView } from "./ClientPostView";
import { readFileSync } from "fs";
import path from "path";
type Props = {
children?: ReactNode;
@@ -41,11 +39,11 @@ export default async function PostView(props: Props) {
// uploadAttachment:tryCreateAttachment
};
const posts: GetPostsAttributes[] | undefined = handleActionResult(
const posts: GetPostsAttributes[]| undefined = handleActionResult(
await getPostsWithBucketsAndProject()
);
const projects = await Project.findAll().then((projects) =>
projects.map((e) => JSON.parse(JSON.stringify(e)))
projects.map((project) => JSON.parse(JSON.stringify(project)))
);
return (
@@ -56,7 +54,7 @@ export default async function PostView(props: Props) {
projects={projects}
headings={headings}
actions={actions}
></ClientPostView>
/>
</div>
</div>
);