diff --git a/src/app/api/attachment/route.ts b/src/app/api/attachment/route.ts index 7469b71..03463ee 100644 --- a/src/app/api/attachment/route.ts +++ b/src/app/api/attachment/route.ts @@ -1,9 +1,9 @@ 'use server' import { APIError, attemptAPIAction } from "@/util/api/error"; -import { sequelize, Bucket, Auth, Post, PostTag, Tag, User, dbSync } from "@/model/Models"; +import { sequelize, Bucket, Auth, Post, PostTag, Tag, User, dbSync } from "@/models"; import { cookies } from "next/headers"; -import { Attachment } from "@/model/Attachment"; +import { Attachment } from "@/models"; import { UUID, randomUUID } from "crypto"; import { mkdir, mkdirSync, writeFile } from "fs"; import { where } from "@sequelize/core"; diff --git a/src/app/api/auth/route.ts b/src/app/api/auth/route.ts index d5829a9..482c112 100644 --- a/src/app/api/auth/route.ts +++ b/src/app/api/auth/route.ts @@ -4,7 +4,7 @@ import { cookies } from "next/headers"; import { APIError} from "@/util/api/error" import { UserAuth, parseBasicAuth, getAssociatedUser } from "@/util/api/user" -import { Auth, User } from "@/model/Models"; +import { Auth, User } from "@/models"; async function tryAuth(request:Request){ diff --git a/src/app/api/auth/validate/route.ts b/src/app/api/auth/validate/route.ts index 3e84ac6..04dd350 100644 --- a/src/app/api/auth/validate/route.ts +++ b/src/app/api/auth/validate/route.ts @@ -4,7 +4,7 @@ import { Model } from "@sequelize/core"; import { cookies } from "next/headers"; -import { Auth } from "@/model/Models"; +import { Auth } from "@/models"; import { APIError} from "@/util/api/error" diff --git a/src/app/api/post/[...slug]/route.ts b/src/app/api/post/[...slug]/route.ts index cc46ab5..0471191 100644 --- a/src/app/api/post/[...slug]/route.ts +++ b/src/app/api/post/[...slug]/route.ts @@ -1,7 +1,7 @@ 'use server' import { APIError } from "@/util/api/error"; -import { Post } from "@/model/Models"; +import { Post } from "@/models"; export async function tryFetchPost(request:Request, { params }: {params:{slug: string}}){ diff --git a/src/app/api/post/route.ts b/src/app/api/post/route.ts index 328b239..0190434 100644 --- a/src/app/api/post/route.ts +++ b/src/app/api/post/route.ts @@ -1,7 +1,7 @@ 'use server' import { APIError, attemptAPIAction } from "@/util/api/error"; -import { Auth, Post, PostTag, Tag, User, dbSync } from "@/model/Models"; +import { Auth, Post, PostTag, Tag, User, dbSync } from "@/models"; import { cookies } from "next/headers"; diff --git a/src/app/api/setupDB/route.ts b/src/app/api/setupDB/route.ts index fd3a842..bb1bfe6 100644 --- a/src/app/api/setupDB/route.ts +++ b/src/app/api/setupDB/route.ts @@ -4,7 +4,7 @@ import { cookies } from "next/headers"; import { APIError} from "@/util/api/error" import { UserAuth, parseBasicAuth, getAssociatedUser } from "@/util/api/user" -import { Attachment, Auth, Bucket, DBState, Post, PostTag, Project, Tag, User, UserPerms,dbSync,sequelize} from "@/model/Models"; +import { Attachment, Auth, Bucket, DBState, Post, PostTag, Project, Tag, User, UserPerms,dbSync,sequelize} from "@/models"; import Sequelize, { DataTypes } from "@sequelize/core"; import { SqliteColumnsDescription, SqliteDialect, SqliteQueryInterface } from "@sequelize/sqlite3"; import { hashPassword } from "@/util/Auth"; diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 1c961fc..0425c1c 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -10,9 +10,8 @@ import { APIError } from "@/util/api/error"; import { UserAuth } from "@/util/api/user"; -import { Attachment, Auth, Bucket, DBState, Post, PostTag, Project, Tag, User, UserPerms,dbSync,sequelize} from "@/model/Models"; +import { Attachment, Auth, Bucket, DBState, Post, PostTag, Project, Tag, User, UserPerms, addUserScopes, dbSync,sequelize} from "@/models"; import { hashPassword } from "@/util/Auth"; -import { addUserScopes } from "@/model/User"; // Attempt to register a new User diff --git a/src/app/article/[...slug]/page.tsx b/src/app/article/[...slug]/page.tsx index b14080e..860a7d9 100644 --- a/src/app/article/[...slug]/page.tsx +++ b/src/app/article/[...slug]/page.tsx @@ -10,7 +10,7 @@ import ReactDOM from "react"; import "/public/global.css" import "@/app/index.css" -import { Post } from "@/model/Post"; +import { Post } from "@/models"; import { Attributes } from "@sequelize/core"; import { DeepPartial } from "@/util/DeepPartial"; diff --git a/src/app/examplepage/page.tsx b/src/app/examplepage/page.tsx index 88f6c81..84df800 100644 --- a/src/app/examplepage/page.tsx +++ b/src/app/examplepage/page.tsx @@ -1,4 +1,5 @@ import type { GetStaticProps } from 'next' +// @ts-ignore import { MDXRemote } from 'next-mdx-remote/rsc' import ExampleComponent from './example.mdx' diff --git a/src/app/lib/actions/actions.ts b/src/app/lib/actions/actions.ts index fd32f6c..ac20a72 100644 --- a/src/app/lib/actions/actions.ts +++ b/src/app/lib/actions/actions.ts @@ -6,9 +6,8 @@ import { parseSetCookie } from "@/util/parseSetCookie"; import makeFetchCookie from 'fetch-cookie'; import fetchCookie from "fetch-cookie"; import { Attribute, Attributes } from "@sequelize/core"; -import { User } from "@/model/User"; +import { User, Auth } from "@/models"; import { AuthProps } from "@/providers/providers"; -import { Auth } from "@/model/Auth"; import { ActionResult } from "./ActionResult"; type LoginReturn = { diff --git a/src/app/lib/actions/entityManagement/postActions.ts b/src/app/lib/actions/entityManagement/postActions.ts index f0b2f10..3eda9ff 100644 --- a/src/app/lib/actions/entityManagement/postActions.ts +++ b/src/app/lib/actions/entityManagement/postActions.ts @@ -1,11 +1,11 @@ 'use server'; import { revalidatePath, revalidateTag } from 'next/cache' -import { Bucket, Post, PostBucket, Project, User, dbSync } from "@/model/Models"; +import { Bucket, Post, PostBucket, Project, User, dbSync } from "@/models"; import { Attributes, where } from "@sequelize/core"; import { getCookieAuth, userIsAdmin } from '../actions'; import { ActionResult } from '../ActionResult'; -import { PostAttributesWithBuckets } from '@/model/Post'; +import { PostAttributesWithBuckets } from '@/models'; export async function deletePost(postID: number): Promise> { await dbSync; diff --git a/src/app/lib/actions/entityManagement/projectActions.ts b/src/app/lib/actions/entityManagement/projectActions.ts index 83bc998..ce34097 100644 --- a/src/app/lib/actions/entityManagement/projectActions.ts +++ b/src/app/lib/actions/entityManagement/projectActions.ts @@ -1,5 +1,5 @@ 'use server'; -import { Project } from "@/model/Project"; +import { Project } from "@/models"; import { ActionResult } from "../ActionResult"; import { Attributes } from "@sequelize/core"; import { userIsAdmin } from "../actions"; diff --git a/src/app/projects/page.tsx b/src/app/projects/page.tsx index 308690c..12d0a4b 100644 --- a/src/app/projects/page.tsx +++ b/src/app/projects/page.tsx @@ -33,9 +33,7 @@ export default function Page(props: Props) {
- - - +
); diff --git a/src/components/client/admin/PostEditor.tsx b/src/components/client/admin/PostEditor.tsx index 3648b88..e443f7b 100644 --- a/src/components/client/admin/PostEditor.tsx +++ b/src/components/client/admin/PostEditor.tsx @@ -1,8 +1,8 @@ import { ActionResult } from "@/app/lib/actions/ActionResult"; import { handleActionResult } from "@/app/lib/actions/clientActionHandler"; import { GetPostsAttributes } from "@/app/lib/actions/entityManagement/postActions"; -import { Post, Project, Bucket, PostBucket, Attachment } from "@/model/Models"; -import { PostAttributesWithBuckets } from "@/model/Post"; +import { Post, Project, Bucket, PostBucket, Attachment } from "@/models" +import { PostAttributesWithBuckets } from "@/models"; import { DeepPartial } from "@/util/DeepPartial"; import { Attributes } from "@sequelize/core"; import { UUID } from "crypto"; @@ -17,9 +17,9 @@ export type PostTableCallbacks = { export type EditorProps = { editorOpenState:boolean; - openedPost:GetPostsAttributes; + openedPost?:GetPostsAttributes; projects?:Attributes[]; - callbacks:PostTableCallbacks; + callbacks?:PostTableCallbacks; } @@ -40,14 +40,14 @@ export default function PostEditor(props:EditorProps){ const onTextAreaChange:ChangeEventHandler = (e) => {setContent(e.target.value);adjustHeight()}; const projectSelectionChange:ChangeEventHandler = (e)=>setProjectID(parseInt(e.target.value)); const onClickSaveButton:MouseEventHandler = (e)=>{ - props.callbacks.savePost({ - id: props.openedPost.id as number, + props.callbacks?.savePost({ + id: props.openedPost?.id as number, content:content as string, title:title as string, project_id: projectID }); } - const onClickCancelButton:MouseEventHandler = (e)=>{props.callbacks.closeEditor();} + const onClickCancelButton:MouseEventHandler = (e)=>{props.callbacks?.closeEditor();} return <>
@@ -81,7 +81,7 @@ export default function PostEditor(props:EditorProps){ { - props.openedPost.buckets + props.openedPost?.buckets ? (()=>{ let bucketMap:Map> = new Map(props.openedPost.buckets.map((b)=>[b.id as UUID,b])); let bucketList = [...props.openedPost.buckets.map((b)=>b.id)]; @@ -124,4 +124,30 @@ export default function PostEditor(props:EditorProps){ +} +type EditorRendererProps = { + postData: GetPostsAttributes, + headings: string[], + editorState: EditorProps, + editorControls: any, + callbacks: any, + projects: any +} +export function EditorRenderer(props:EditorRendererProps){ + const {postData, headings, editorState, editorControls, callbacks, projects} = props + + return (props.editorState.editorOpenState + && editorState.openedPost + && editorState.openedPost.id == postData.id) + + ? + + + + + + : "" } \ No newline at end of file diff --git a/src/components/client/admin/PostTable.tsx b/src/components/client/admin/PostTable.tsx index 47438bd..3f294dd 100644 --- a/src/components/client/admin/PostTable.tsx +++ b/src/components/client/admin/PostTable.tsx @@ -11,17 +11,17 @@ import React, { } from "react"; import EntityManagementTable from "../EntityManagementTable"; import toast from "react-hot-toast"; -import PostEditor, { EditorProps } from "./PostEditor"; +import PostEditor, { EditorProps, EditorRenderer } from "./PostEditor"; import { Attributes, CreationAttributes } from "@sequelize/core"; import { useState } from "react"; -import { Project, Post, Bucket } from "@/model/Models"; +import { Project, Post, Bucket } from "@/models"; import { ActionResult } from "@/app/lib/actions/ActionResult"; import { handleActionResult } from "@/app/lib/actions/clientActionHandler"; import { getPostsWithBucketsAndProject, GetPostsAttributes } from "@/app/lib/actions/entityManagement/postActions"; -import { PostAttributesWithBuckets } from "@/model/Post"; +import { PostAttributesWithBuckets } from "@/models"; export type PostTableActions = { deletePost: (id: number) => Promise> @@ -43,29 +43,34 @@ const aifa = (a: ReactNode, b: ReactNode) => a ? a : b export default function PostTable(props: Props) { - - - const initEditorState: Partial = { - editorOpenState: false - } + const initEditorState: EditorProps = { + ...{ + editorOpenState: false + }, ...{ + callbacks: undefined, + openedPost: undefined, + projects: undefined, + } + }; // Set up required state hooks const [posts, setPosts] = useState(props.data); - const [editor, setEditor] = useState(initEditorState) + const [editorState, setEditorState] = useState(initEditorState) const [projects, setProjects] = useState(props.projects); // Define editor controls - - function closeEditor(): void { - setEditor({ - editorOpenState: false - }) - } - function showEditor(entry: GetPostsAttributes): void { - setEditor({ - editorOpenState: true, - openedPost: entry - }) + const editorControls = { + closeEditor: () => { + setEditorState({ + editorOpenState: false + }) + }, + showEditor: (entry: GetPostsAttributes) => { + setEditorState({ + editorOpenState: true, + openedPost: entry + }) + } } function deletePost(entry: GetPostsAttributes) { @@ -85,7 +90,8 @@ export default function PostTable(props: Props) { .then((p) => { const result = handleActionResult(p) if (result) setPosts(result) - }).then(props.actions.getProjects) + }) + .then(props.actions.getProjects) .then(e => { const result = handleActionResult(e); if (result) setProjects(result) @@ -105,68 +111,61 @@ export default function PostTable(props: Props) { const result = handleActionResult(res); if (result) setPosts(result); }) - closeEditor(); + editorControls.closeEditor(); }; - function TableFields({ postData }: { postData: GetPostsAttributes }) { - return [ - { - key: 'post-title', - content: postData.title - }, { - key: 'post-content', - content: - !postData.content ? "No Content Found" : - postData.content.length < 255 ? postData.content : - `${postData.content.substring(0, 255)}...` - - }, { - key: 'post-project', - content: aifa((projects.find((e) => { - console.log(e.id) - return (e.id == postData.project.id) - })?.readableIdentifier), 'uncategorized') - }, { - key: 'post-createdat', - content: postData.createdAt?.toString() - }, { - key: 'post-updatedat', - content: postData.updatedAt?.toString() - }, { - key: 'post-editbutton', - content: - }, { - key: 'post-deletebutton', - content: - } - ].map(field => - {field.content} - ); - } - - function TableRow(props: { postData: GetPostsAttributes, headings: string | any[] }) { - return <> - {props.postData.id} - - - {(editor.editorOpenState - && editor.openedPost - && editor.openedPost.id == props.postData.id) - - ? - - { } - }} - editorOpenState={editor.editorOpenState} - openedPost={editor.openedPost} - projects={projects} /> - - - - : ""} + function TableRow(props: { postData: GetPostsAttributes, headings: string[] }) { + return <> + + {props.postData.id} + {props.postData.title} + + { + !props.postData.content ? "No Content Found" : + props.postData.content.length < 255 ? props.postData.content : + `${props.postData.content.substring(0, 255)}...` + } + + + { + aifa((projects.find((e) => { + console.log(e.id) + return (e.id == props.postData.project.id) + })?.readableIdentifier), 'uncategorized') + } + + + { + props.postData.createdAt?.toString() + } + + + { + props.postData.updatedAt?.toString() + } + + + { + + } + + + { + + } + + + { } + }} + projects={projects} + /> } diff --git a/src/components/server/admin/serverContextUserTest.tsx b/src/components/server/admin/serverContextUserTest.tsx deleted file mode 100644 index e347983..0000000 --- a/src/components/server/admin/serverContextUserTest.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { AuthContext, AuthProps } from "@/providers/providers"; -import { ReactNode, useContext } from "react"; - -interface Props { - children?: ReactNode; - auth?: AuthProps; -} - -export default function SomeServerSubComponent(props:Props){ - let { test, auth } = useContext(AuthContext); - - - return ( - {test}{JSON.stringify(auth)} - ); -} \ No newline at end of file diff --git a/src/components/server/admin/views/PostView.tsx b/src/components/server/admin/views/PostView.tsx index b468c4a..eaf5885 100644 --- a/src/components/server/admin/views/PostView.tsx +++ b/src/components/server/admin/views/PostView.tsx @@ -7,7 +7,7 @@ import EntityManagementTable from "../../../client/EntityManagementTable"; import PostTable, { PostTableActions } from "@/components/client/admin/PostTable"; import { deletePost, getPostsWithBucketsAndProject, GetPostsAttributes, updatePost } from "@/app/lib/actions/entityManagement/postActions"; import { getProjects } from "@/app/lib/actions/entityManagement/projectActions"; -import { Bucket, Project, Post, dbSync, Attachment } from "@/model/Models"; +import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; import { tryCreateAttachment } from "@/app/api/attachment/route"; import { handleActionResult } from '../../../../app/lib/actions/clientActionHandler'; diff --git a/src/components/server/admin/views/ProjectView.tsx b/src/components/server/admin/views/ProjectView.tsx index d22ad6e..c6a8abd 100644 --- a/src/components/server/admin/views/ProjectView.tsx +++ b/src/components/server/admin/views/ProjectView.tsx @@ -7,7 +7,7 @@ import EntityManagementTable from "../../../client/EntityManagementTable"; import PostTable from "@/components/client/admin/PostTable"; import { deletePost, getPostsWithBucketsAndProject, updatePost } from "@/app/lib/actions/entityManagement/postActions"; import { getProjects } from "@/app/lib/actions/entityManagement/projectActions"; -import { Bucket, Project, Post, dbSync, Attachment } from "@/model/Models"; +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' diff --git a/src/components/shared/news/article-preview.tsx b/src/components/shared/news/article-preview.tsx index a7ee148..9ef7cc2 100644 --- a/src/components/shared/news/article-preview.tsx +++ b/src/components/shared/news/article-preview.tsx @@ -9,15 +9,19 @@ import { redirect } from 'next/navigation'; import { Router } from "next/router"; import { useRouter } from 'next/navigation' import { truncateString } from "@/util/Utils"; +// @ts-ignore import { MDXRemote } from "next-mdx-remote/rsc"; import { ExampleComponent } from "./article"; import ReactDOM from "react-dom"; import renderToString from 'react-dom/server' import { jsxToString } from "@/app/lib/jsxtostring"; +// @ts-ignore import remarkMdx from "remark-mdx"; +// @ts-ignore import { remark } from "remark"; +// @ts-ignore import strip from 'remark-mdx-to-plain-text'; -import { Post } from "@/model/Post"; +import { Post } from "@/models"; import { Attributes } from "@sequelize/core"; type ArticlePreviewPost = Attributes diff --git a/src/model/APIKey.ts b/src/models/APIKey.ts similarity index 100% rename from src/model/APIKey.ts rename to src/models/APIKey.ts diff --git a/src/model/Attachment.ts b/src/models/Attachment.ts similarity index 100% rename from src/model/Attachment.ts rename to src/models/Attachment.ts diff --git a/src/model/Auth.ts b/src/models/Auth.ts similarity index 100% rename from src/model/Auth.ts rename to src/models/Auth.ts diff --git a/src/model/Bucket.ts b/src/models/Bucket.ts similarity index 100% rename from src/model/Bucket.ts rename to src/models/Bucket.ts diff --git a/src/model/DBState.ts b/src/models/DBState.ts similarity index 100% rename from src/model/DBState.ts rename to src/models/DBState.ts diff --git a/src/model/Post.ts b/src/models/Post.ts similarity index 100% rename from src/model/Post.ts rename to src/models/Post.ts diff --git a/src/model/PostTag.ts b/src/models/PostTag.ts similarity index 100% rename from src/model/PostTag.ts rename to src/models/PostTag.ts diff --git a/src/model/Project.ts b/src/models/Project.ts similarity index 100% rename from src/model/Project.ts rename to src/models/Project.ts diff --git a/src/model/Tag.ts b/src/models/Tag.ts similarity index 100% rename from src/model/Tag.ts rename to src/models/Tag.ts diff --git a/src/model/User.ts b/src/models/User.ts similarity index 100% rename from src/model/User.ts rename to src/models/User.ts diff --git a/src/model/UserPerms.ts b/src/models/UserPerms.ts similarity index 100% rename from src/model/UserPerms.ts rename to src/models/UserPerms.ts diff --git a/src/model/Models.ts b/src/models/index.ts similarity index 60% rename from src/model/Models.ts rename to src/models/index.ts index 7ac4249..536255e 100644 --- a/src/model/Models.ts +++ b/src/models/index.ts @@ -1,30 +1,37 @@ -import { Auth } from './Auth'; +import Sequelize from '@sequelize/core'; +import { SqliteDialect } from '@sequelize/sqlite3'; import { Attachment } from './Attachment'; +import { Auth } from './Auth'; import { Bucket } from './Bucket'; import { DBState } from './DBState'; -import { addPostScopes, Post, PostBucket } from './Post'; +import { Post, PostBucket, addPostScopes } from './Post'; import { PostTag } from './PostTag'; import { Project } from './Project'; import { Tag } from './Tag'; import { User, addUserScopes } from './User'; import { UserPerms, addUserPermsScopes } from './UserPerms'; -import { SqliteDialect } from '@sequelize/sqlite3'; -import Sequelize from '@sequelize/core'; +export * from './APIKey'; +export * from './Attachment'; +export * from './Auth'; +export * from './Bucket'; +export * from './DBState'; +export * from './Post'; +export * from './PostTag'; +export * from './Project'; +export * from './Tag'; +export * from './User'; +export * from './UserPerms'; -const sequelize = new Sequelize({ +export const sequelize = new Sequelize({ dialect: SqliteDialect, storage: 'db.sqlite', models: [Auth, Attachment, Bucket, DBState, Post, PostBucket, PostTag, Project, Tag, User, UserPerms], - }); -const dbSync = (async ()=> await sequelize.sync())().then(()=>{ +export const dbSync = (async ()=> await sequelize.sync())().then(()=>{ addUserScopes(); addUserPermsScopes(); addPostScopes(); }); - - -export { sequelize, dbSync, Auth, Attachment, Bucket, DBState, Post, PostBucket, PostTag, Project, Tag, User, UserPerms } \ No newline at end of file