last commit implementation didn't even work properly but now it works
This commit is contained in:
parent
901a569900
commit
a23fbd322b
|
@ -12,7 +12,7 @@ export async function action({ request, params }) {
|
||||||
const clonedData = request.clone();
|
const clonedData = request.clone();
|
||||||
const formData = await clonedData.formData();
|
const formData = await clonedData.formData();
|
||||||
const post = formData.get("post");
|
const post = formData.get("post");
|
||||||
let replying = formData.get("replying");
|
const replying = formData.get("replying");
|
||||||
|
|
||||||
const fileUploadHandler = unstable_createFileUploadHandler({
|
const fileUploadHandler = unstable_createFileUploadHandler({
|
||||||
directory: './public/uploads/',
|
directory: './public/uploads/',
|
||||||
|
@ -41,6 +41,8 @@ export async function action({ request, params }) {
|
||||||
errors.post = "Post too long or short";
|
errors.post = "Post too long or short";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (replying !== "") {
|
||||||
|
let currentThreadreplyids = [];
|
||||||
const currentThread = await prisma.thread.findUnique({
|
const currentThread = await prisma.thread.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: parseInt(threadId),
|
id: parseInt(threadId),
|
||||||
|
@ -49,10 +51,13 @@ export async function action({ request, params }) {
|
||||||
posts: true
|
posts: true
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
currentThread.posts.map(post => currentThreadreplyids.push(post.id));
|
||||||
|
|
||||||
if (typeof replying !== "string" || !parseInt(replying) || parseInt(replying) > currentThread.posts.length ) {
|
if (typeof replying !== "string" || !parseInt(replying) || !currentThreadreplyids.includes(parseInt(replying))) {
|
||||||
replying = ""
|
errors.replying = "bad reply id"
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if (Object.keys(errors).length) {
|
if (Object.keys(errors).length) {
|
||||||
return json(errors, { status: 422 });
|
return json(errors, { status: 422 });
|
||||||
};
|
};
|
||||||
|
@ -66,7 +71,7 @@ export async function action({ request, params }) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return redirect(`/threads/${threadId}#${createPost.id}`);
|
return redirect(`/threads/${threadId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function loader({ params }) {
|
export async function loader({ params }) {
|
||||||
|
@ -101,7 +106,7 @@ export default function Thread() {
|
||||||
return (
|
return (
|
||||||
<Overlay>
|
<Overlay>
|
||||||
<div className="flex flex-col p-12 bg-ctp-crust border outline rounded shadow-ctp-green shadow-lg">
|
<div className="flex flex-col p-12 bg-ctp-crust border outline rounded shadow-ctp-green shadow-lg">
|
||||||
<div className="bg-ctp-base rounded p-4">
|
<div id="OP" className="bg-ctp-base rounded p-4">
|
||||||
<span><strong>{data.title}</strong> Post id: <strong>{data.id}</strong> Created at: <strong>{new Date(data.createdAt).toLocaleString()}</strong> Reply count: <strong>{data.posts.length}</strong></span>
|
<span><strong>{data.title}</strong> Post id: <strong>{data.id}</strong> Created at: <strong>{new Date(data.createdAt).toLocaleString()}</strong> Reply count: <strong>{data.posts.length}</strong></span>
|
||||||
<br />
|
<br />
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
|
|
Loading…
Reference in New Issue