changed stuff
This commit is contained in:
parent
de212c367f
commit
2dca4a5a80
@ -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";
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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}}){
|
||||
|
||||
@ -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";
|
||||
|
||||
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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";
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type { GetStaticProps } from 'next'
|
||||
// @ts-ignore
|
||||
import { MDXRemote } from 'next-mdx-remote/rsc'
|
||||
import ExampleComponent from './example.mdx'
|
||||
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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<ActionResult<boolean>> {
|
||||
await dbSync;
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -33,9 +33,7 @@ export default function Page(props: Props) {
|
||||
<ul><li>filter 1</li><li>filter 2</li><li>filter 3</li></ul>
|
||||
</Sidebar>
|
||||
<main>
|
||||
<ArticlePreview />
|
||||
<ArticlePreview />
|
||||
<ArticlePreview />
|
||||
|
||||
</main>
|
||||
</PageContainer>
|
||||
</div>);
|
||||
|
||||
@ -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<Project>[];
|
||||
callbacks:PostTableCallbacks;
|
||||
callbacks?:PostTableCallbacks;
|
||||
}
|
||||
|
||||
|
||||
@ -40,14 +40,14 @@ export default function PostEditor(props:EditorProps){
|
||||
const onTextAreaChange:ChangeEventHandler<HTMLTextAreaElement> = (e) => {setContent(e.target.value);adjustHeight()};
|
||||
const projectSelectionChange:ChangeEventHandler<HTMLSelectElement> = (e)=>setProjectID(parseInt(e.target.value));
|
||||
const onClickSaveButton:MouseEventHandler<HTMLButtonElement> = (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<HTMLButtonElement> = (e)=>{props.callbacks.closeEditor();}
|
||||
const onClickCancelButton:MouseEventHandler<HTMLButtonElement> = (e)=>{props.callbacks?.closeEditor();}
|
||||
|
||||
return <>
|
||||
<form className="bg-light w-[100%] h-content p-1">
|
||||
@ -81,7 +81,7 @@ export default function PostEditor(props:EditorProps){
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
props.openedPost.buckets
|
||||
props.openedPost?.buckets
|
||||
? (()=>{
|
||||
let bucketMap:Map<UUID,Attributes<Bucket>> = new Map(props.openedPost.buckets.map((b)=>[b.id as UUID,b]));
|
||||
let bucketList = [...props.openedPost.buckets.map((b)=>b.id)];
|
||||
@ -125,3 +125,29 @@ export default function PostEditor(props:EditorProps){
|
||||
</form>
|
||||
</>
|
||||
}
|
||||
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)
|
||||
|
||||
? <tr>
|
||||
<th scope="row" colSpan={headings.length}>
|
||||
<PostEditor callbacks={callbacks}
|
||||
editorOpenState={editorState.editorOpenState}
|
||||
openedPost={editorState.openedPost}
|
||||
projects={projects} />
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
: ""
|
||||
}
|
||||
@ -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<ActionResult<boolean>>
|
||||
@ -43,29 +43,34 @@ const aifa = (a: ReactNode, b: ReactNode) => a ? a : b
|
||||
|
||||
export default function PostTable(props: Props) {
|
||||
|
||||
|
||||
|
||||
const initEditorState: Partial<EditorProps> = {
|
||||
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: <button key="editbutton" type="button" className="btn btn-primary" onClick={() => showEditor(postData)}>Edit</button>
|
||||
}, {
|
||||
key: 'post-deletebutton',
|
||||
content: <button key="deletebutton" type="button" className="btn btn-danger" onClick={() => deletePost(postData)}> Delete</button>
|
||||
}
|
||||
].map(field =>
|
||||
<td key={field.key}>{field.content}</td>
|
||||
);
|
||||
}
|
||||
|
||||
function TableRow(props: { postData: GetPostsAttributes, headings: string | any[] }) {
|
||||
return <><tr key={props.postData.id}>
|
||||
<th key={`rowheading-post-${props.postData.id}`} scope="row">{props.postData.id}</th>
|
||||
<TableFields key={`tableFields-${props.postData.id}`} postData={props.postData} />
|
||||
</tr>
|
||||
{(editor.editorOpenState
|
||||
&& editor.openedPost
|
||||
&& editor.openedPost.id == props.postData.id)
|
||||
|
||||
? <tr>
|
||||
<th scope="row" colSpan={props.headings.length}>
|
||||
<PostEditor callbacks={{
|
||||
savePost: savePost,
|
||||
closeEditor: closeEditor,
|
||||
uploadAttachment: () => { }
|
||||
}}
|
||||
editorOpenState={editor.editorOpenState}
|
||||
openedPost={editor.openedPost}
|
||||
projects={projects} />
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
: ""}
|
||||
function TableRow(props: { postData: GetPostsAttributes, headings: string[] }) {
|
||||
return <>
|
||||
<tr key={props.postData.id}>
|
||||
<th key={`rowheading-post-${props.postData.id}`} scope="row">{props.postData.id}</th>
|
||||
<td key='title'>{props.postData.title}</td>
|
||||
<td key='content'>
|
||||
{
|
||||
!props.postData.content ? "No Content Found" :
|
||||
props.postData.content.length < 255 ? props.postData.content :
|
||||
`${props.postData.content.substring(0, 255)}...`
|
||||
}
|
||||
</td>
|
||||
<td key='project'>
|
||||
{
|
||||
aifa((projects.find((e) => {
|
||||
console.log(e.id)
|
||||
return (e.id == props.postData.project.id)
|
||||
})?.readableIdentifier), 'uncategorized')
|
||||
}
|
||||
</td>
|
||||
<td key='createdAt'>
|
||||
{
|
||||
props.postData.createdAt?.toString()
|
||||
}
|
||||
</td>
|
||||
<td key='updatedAt'>
|
||||
{
|
||||
props.postData.updatedAt?.toString()
|
||||
}
|
||||
</td>
|
||||
<td key='edit'>
|
||||
{
|
||||
<button key="editbutton" type="button" className="btn btn-primary" onClick={() => editorControls.showEditor(props.postData)}>Edit</button>
|
||||
}
|
||||
</td>
|
||||
<td key='delete'>
|
||||
{
|
||||
<button key="deletebutton" type="button" className="btn btn-danger" onClick={() => deletePost(props.postData)}> Delete</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
<EditorRenderer headings={props.headings}
|
||||
postData={props.postData}
|
||||
editorControls={editorControls}
|
||||
editorState={editorState}
|
||||
callbacks={{
|
||||
savePost: savePost,
|
||||
closeEditor: editorControls.closeEditor,
|
||||
uploadAttachment: () => { }
|
||||
}}
|
||||
projects={projects}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
|
||||
@ -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 (
|
||||
<span>{test}{JSON.stringify(auth)}</span>
|
||||
);
|
||||
}
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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<Post>
|
||||
|
||||
@ -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 }
|
||||
Loading…
x
Reference in New Issue
Block a user