more refactoring

This commit is contained in:
2024-07-02 09:08:49 +02:00
parent de148eaf19
commit 1971966099
27 changed files with 400 additions and 324 deletions
+14 -14
View File
@@ -4,7 +4,13 @@ import EntityManagementTable from "../EntityManagementTable";
import toast from "react-hot-toast";
import { EditorRenderer, EditorState, PostTableCallbacks } from "./PostEditor";
import { Attributes, InferAttributes } from "@sequelize/core";
import { Project, Post, Bucket, User, PostAttributesWithBuckets } from "@/models";
import {
Project,
Post,
Bucket,
User,
PostAttributesWithBuckets,
} from "@/models";
import { handleActionResult } from "@/app/lib/actions/clientActionHandler";
import {
@@ -13,16 +19,15 @@ import {
PostServerActions,
} from "@/app/lib/actions/entityManagement/post/postActions";
import { PostViewProps } from "@/views/admin/ClientPostView";
import { aifa } from "@/util/Utils";
import { StateHook } from "@/util/state/stateUtils";
import { aifa } from "@/util/utils";
import { StateHook } from "@/util/state";
export type PostTableStateProps = {
posts:StateHook<GetPostsAttributes[]>,
editor:StateHook<EditorState>
}
export type PostTableProps = PostViewProps & {state:PostTableStateProps};
posts: StateHook<GetPostsAttributes[]>;
editor: StateHook<EditorState>;
};
export type PostTableProps = PostViewProps & { state: PostTableStateProps };
export default function PostTable({
children,
@@ -32,8 +37,6 @@ export default function PostTable({
actions,
state,
}: PostTableProps) {
// Define editor controls
const editorControls = {
closeEditor: () => {
@@ -93,10 +96,7 @@ export default function PostTable({
};
return (
<EntityManagementTable
entityName="Post"
headings={headings}
>
<EntityManagementTable entityName="Post" headings={headings}>
{state.posts.state.map((post: GetPostsAttributes) => (
<React.Fragment key={`postrow-${post.id}`}>
<tr>
+1 -1
View File
@@ -2,7 +2,7 @@
import { serverAttemptAuthenticateUser } from "@/app/lib/actions/actions";
import { AuthContext } from "@/providers/providers";
import { constructAPIUrl } from "@/util/Utils";
import { constructAPIUrl } from "@/util/url";
import { createContext, useState } from "react";
import { useFormState, useFormStatus } from "react-dom";
@@ -1,20 +1,34 @@
'use client'
"use client";
import { useRef, MutableRefObject, useLayoutEffect, ChangeEventHandler, useState } from "react";
import { StateHook } from '../../../util/types/StateHook';
import {
useRef,
MutableRefObject,
useLayoutEffect,
ChangeEventHandler,
useState,
} from "react";
import { StateHook } from "@/util";
export function EntityEditorTextArea({contentHook, className}: {contentHook:StateHook<string>, className:string}){
// Autosize the text area
function textAreaAutoSize(
textbox: MutableRefObject<HTMLTextAreaElement>
): void {
if (!textbox.current || !textbox.current.style) return;
textbox.current.style.height = "fit-content";
textbox.current.style.height = `${textbox.current.scrollHeight}px`;
}
let textbox: any = useRef(undefined);
type EntityEditorTextAreaProps = {
contentHook: StateHook<string>;
className: string;
};
export function EntityEditorTextArea({
contentHook,
className,
}: EntityEditorTextAreaProps) {
let textbox: any = useRef(undefined);
// Autosize the text area
function textAreaAutoSize(
textbox: MutableRefObject<HTMLTextAreaElement>
): void {
if (!textbox.current || !textbox.current.style) return;
textbox.current.style.height = "fit-content";
textbox.current.style.height = `${textbox.current.scrollHeight}px`;
}
useLayoutEffect(() => textAreaAutoSize(textbox));
// Handle user input on the text area by updating state and autosizing the textfield
@@ -23,12 +37,14 @@ export function EntityEditorTextArea({contentHook, className}: {contentHook:Stat
textAreaAutoSize(textbox); // Autosize the text area
};
return <textarea
key="input-content"
onChange={onTextAreaChange}
ref={textbox}
value={contentHook?.state}
style={{ height: "100%" }}
className={className}
/>
}
return (
<textarea
key="input-content"
onChange={onTextAreaChange}
ref={textbox}
value={contentHook?.state}
style={{ height: "100%" }}
className={className}
/>
);
}
@@ -8,7 +8,7 @@ import Link from "next/link";
import { redirect } from 'next/navigation';
import { Router } from "next/router";
import { useRouter } from 'next/navigation'
import { truncateString } from "@/util/Utils";
import { truncateString } from "@/util/utils";
// @ts-ignore
import { MDXRemote } from "next-mdx-remote/rsc";
import { ExampleComponent } from "./article";