-
-
Notifications
You must be signed in to change notification settings - Fork 146
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 13 commits
b50bb73
490269d
c766749
6a05e9e
03e3161
469610d
e9b3c24
4ae3497
93a83fe
b8603c1
1a2320d
2b75c06
adbf78c
c839c94
454067f
bfcb6cf
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 |
---|---|---|
|
@@ -161,6 +161,7 @@ const Create = ({ session }: { session: Session | null }) => { | |
Sentry.captureException(error); | ||
}, | ||
}); | ||
|
||
const { | ||
mutate: create, | ||
data: createData, | ||
|
@@ -217,6 +218,7 @@ const Create = ({ session }: { session: Session | null }) => { | |
tags, | ||
canonicalUrl: data.canonicalUrl || undefined, | ||
excerpt: data.excerpt || removeMarkdown(data.body, {}).substring(0, 155), | ||
seriesName: data.seriesName || undefined | ||
}; | ||
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 validation and sanitization for series name. The series name is currently accepted without any validation or sanitization. Since series names need to match exactly for articles to be connected (as mentioned in the UI help text), consider adding validation to prevent issues with whitespace, special characters, or case sensitivity. const getFormData = () => {
const data = getValues();
+ const sanitizedSeriesName = data.seriesName?.trim();
const formData = {
...data,
tags,
canonicalUrl: data.canonicalUrl || undefined,
excerpt: data.excerpt || removeMarkdown(data.body, {}).substring(0, 155),
- seriesName: data.seriesName || undefined
+ seriesName: sanitizedSeriesName || undefined
};
return formData;
};
|
||
return formData; | ||
}; | ||
|
@@ -229,6 +231,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 +567,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 | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,8 @@ CREATE TABLE IF NOT EXISTS "Post" ( | |||||||||||||||||||||||||||||||||||
"updatedAt" timestamp(3) with time zone NOT NULL, | ||||||||||||||||||||||||||||||||||||
"slug" text NOT NULL, | ||||||||||||||||||||||||||||||||||||
"userId" text NOT NULL, | ||||||||||||||||||||||||||||||||||||
"showComments" boolean DEFAULT true NOT NULL | ||||||||||||||||||||||||||||||||||||
"showComments" boolean DEFAULT true NOT NULL, | ||||||||||||||||||||||||||||||||||||
"seriesId" INTEGER | ||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||
--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
CREATE TABLE IF NOT EXISTS "PostTag" ( | ||||||||||||||||||||||||||||||||||||
|
@@ -183,6 +184,15 @@ CREATE TABLE IF NOT EXISTS "Membership" ( | |||||||||||||||||||||||||||||||||||
"createdAt" timestamp(3) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL | ||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||
--> 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 | ||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||
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 Consider enhancing the Series table with additional columns and indexes. While the basic structure is correct, consider these improvements for better functionality and performance:
CREATE TABLE IF NOT EXISTS "Series" (
"id" SERIAL PRIMARY KEY,
"name" TEXT NOT NULL,
"userId" text NOT NULL,
+ "orderColumn" INTEGER DEFAULT 0 NOT NULL,
+ "isDeleted" BOOLEAN DEFAULT FALSE NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
);
+CREATE UNIQUE INDEX IF NOT EXISTS "Series_name_userId_key" ON "Series" ("name", "userId") WHERE "isDeleted" = FALSE; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
CREATE UNIQUE INDEX IF NOT EXISTS "Post_id_key" ON "Post" ("id");--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
CREATE UNIQUE INDEX IF NOT EXISTS "Post_slug_key" ON "Post" ("slug");--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
CREATE UNIQUE INDEX IF NOT EXISTS "PostTag_tagId_postId_key" ON "PostTag" ("tagId","postId");--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
|
@@ -208,6 +218,12 @@ EXCEPTION | |||||||||||||||||||||||||||||||||||
WHEN duplicate_object THEN null; | ||||||||||||||||||||||||||||||||||||
END $$; | ||||||||||||||||||||||||||||||||||||
--> 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 $$ | ||||||||||||||||||||||||||||||||||||
--> statement-breakpoint | ||||||||||||||||||||||||||||||||||||
DO $$ BEGIN | ||||||||||||||||||||||||||||||||||||
ALTER TABLE "Post" ADD CONSTRAINT "Post_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade; | ||||||||||||||||||||||||||||||||||||
EXCEPTION | ||||||||||||||||||||||||||||||||||||
|
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.
We should santize this (using trim) on Zod.