-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ Add "series" to link related articles #1202
base: develop
Are you sure you want to change the base?
Changes from all commits
b50bb73
490269d
c766749
6a05e9e
03e3161
469610d
e9b3c24
4ae3497
93a83fe
b8603c1
1a2320d
2b75c06
adbf78c
c839c94
454067f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ import { uploadFile } from "@/utils/s3helpers"; | |
import { getUploadUrl } from "@/app/actions/getUploadUrl"; | ||
import EditorNav from "./navigation"; | ||
import { type Session } from "next-auth"; | ||
import { FormDataSchema } from "@/schema/post"; | ||
|
||
const Create = ({ session }: { session: Session | null }) => { | ||
const params = useParams(); | ||
|
@@ -161,6 +162,7 @@ const Create = ({ session }: { session: Session | null }) => { | |
Sentry.captureException(error); | ||
}, | ||
}); | ||
|
||
const { | ||
mutate: create, | ||
data: createData, | ||
|
@@ -212,11 +214,17 @@ const Create = ({ session }: { session: Session | null }) => { | |
|
||
const getFormData = () => { | ||
const data = getValues(); | ||
|
||
const sanitizedSeriesName = FormDataSchema.parse({ | ||
seriesName: data.seriesName, | ||
}); | ||
|
||
const formData = { | ||
...data, | ||
tags, | ||
canonicalUrl: data.canonicalUrl || undefined, | ||
excerpt: data.excerpt || removeMarkdown(data.body, {}).substring(0, 155), | ||
...sanitizedSeriesName | ||
}; | ||
return formData; | ||
}; | ||
|
@@ -229,6 +237,7 @@ const Create = ({ session }: { session: Session | null }) => { | |
await create({ ...formData }); | ||
} else { | ||
await save({ ...formData, id: postId }); | ||
|
||
setSavedTime( | ||
new Date().toLocaleString(undefined, { | ||
dateStyle: "medium", | ||
|
@@ -564,10 +573,24 @@ const Create = ({ session }: { session: Session | null }) => { | |
{copied ? "Copied" : "Copy Link"} | ||
</div> | ||
</button> | ||
<p className="mt-2 text-sm text-neutral-600 dark:text-neutral-400"> | ||
<p className="mt-2 mb-2 text-sm text-neutral-600 dark:text-neutral-400"> | ||
Share this link with others to preview your | ||
draft. Anyone with the link can view your draft. | ||
</p> | ||
|
||
<label htmlFor="seriesName"> | ||
Series Name | ||
</label> | ||
<input | ||
id="seriesName" | ||
type="text" | ||
placeholder="The name of my series" | ||
defaultValue={data?.series?.name || ""} | ||
{...register("seriesName")} | ||
/> | ||
<p className="mt-2 text-sm text-neutral-600 dark:text-neutral-400"> | ||
This text is case-sensitive so make sure you type it exactly as you did in previous articles to ensure they are connected | ||
</p> | ||
Comment on lines
+581
to
+593
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for series name. While the UI implementation is good, consider adding validation to ensure consistent series names. Consider adding validation: <input
id="seriesName"
type="text"
placeholder="The name of my series"
defaultValue={data?.series?.name || ""}
+ pattern="^[a-zA-Z0-9\s-]+$"
+ title="Series name can only contain letters, numbers, spaces, and hyphens"
{...register("seriesName", {
+ validate: {
+ format: (value) =>
+ !value || /^[a-zA-Z0-9\s-]+$/.test(value) ||
+ "Series name can only contain letters, numbers, spaces, and hyphens"
+ }
+ })}
/>
+{errors.seriesName && (
+ <p className="mt-1 text-sm text-red-600">
+ {errors.seriesName.message}
+ </p>
+)}
|
||
</DisclosurePanel> | ||
</> | ||
)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, sorry for the major delay. I've been crazy busy. A few issues are still here. You can't do migrations in older migrations or they'll never run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh.... Sure, |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||
--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
CREATE TABLE IF NOT EXISTS "Series" ( | ||||||||||||||||||||||||||||||||||||
"id" SERIAL PRIMARY KEY, | ||||||||||||||||||||||||||||||||||||
"name" TEXT NOT NULL, | ||||||||||||||||||||||||||||||||||||
"userId" text NOT NULL, | ||||||||||||||||||||||||||||||||||||
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||||||||||||||||||||||||||||||||||||
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL | ||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add necessary indexes and constraints to the Series table Consider the following improvements for better performance and data integrity:
Apply this modification: CREATE TABLE IF NOT EXISTS "Series" (
"id" SERIAL PRIMARY KEY,
- "name" TEXT NOT NULL,
+ "name" VARCHAR(255) NOT NULL,
"userId" text NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
);
+CREATE UNIQUE INDEX "series_name_userid_unique_idx" ON "Series"("name", "userId");
+CREATE INDEX "series_userid_idx" ON "Series"("userId");
+CREATE INDEX "series_createdat_idx" ON "Series"("createdAt"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
-->statement-breakpoint | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
ALTER TABLE "Post" ADD COLUMN "seriesId" INTEGER; | ||||||||||||||||||||||||||||||||||||
--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
DO $$ BEGIN | ||||||||||||||||||||||||||||||||||||
ALTER TABLE "Post" ADD CONSTRAINT "Post_seriesId_fkey" FOREIGN KEY ("seriesId") REFERENCES "public"."Series" ("id") ON DELETE SET NULL; | ||||||||||||||||||||||||||||||||||||
EXCEPTION | ||||||||||||||||||||||||||||||||||||
WHEN duplicate_object THEN null; | ||||||||||||||||||||||||||||||||||||
END $$ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for series name sanitization.
The current implementation has two potential issues:
Consider this safer implementation:
📝 Committable suggestion