Skip to content

Commit bd240d6

Browse files
committed
Refactor package.json scripts for database management and update ArticleEditor to handle optional SEO metadata. Remove unused canonical URL handling and improve loading state for save button. Enhance type definitions for better clarity on optional fields.
1 parent 27346cf commit bd240d6

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"migrate:generate": "npx drizzle-kit generate",
11-
"migrate:push-db": "npx drizzle-kit push"
10+
"db:generate": "npx drizzle-kit generate",
11+
"db:push": "npx drizzle-kit push",
12+
"db:studio": "npx drizzle-kit studio"
1213
},
1314
"dependencies": {
1415
"@cloudinary/react": "^1.14.1",
@@ -32,7 +33,6 @@
3233
"@tailwindcss/postcss": "^4.1.1",
3334
"@tailwindcss/typography": "^0.5.16",
3435
"@tanstack/react-query": "^5.69.0",
35-
"badge": "^1.0.3",
3636
"class-variance-authority": "^0.7.1",
3737
"cloudinary": "^2.6.0",
3838
"clsx": "^2.1.1",
@@ -48,10 +48,7 @@
4848
"react": "^19",
4949
"react-dom": "^19",
5050
"react-hook-form": "^7.55.0",
51-
"react-icons": "^5.5.0",
52-
"react-mde": "^12.0.8",
5351
"recharts": "^2.15.1",
54-
"sass": "^1.86.0",
5552
"schema-dts": "^1.1.5",
5653
"tailwind-merge": "^3.0.2",
5754
"tw-animate-css": "^1.2.4",

src/backend/models/domain-models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export interface IServerFile {
4343
}
4444

4545
export interface ArticleMetadata {
46-
seo: {
46+
seo?: {
4747
title?: string;
4848
description?: string;
4949
keywords?: string[];
5050
canonical_url?: string;
51-
};
51+
} | null;
5252
}
5353

5454
export interface Article {

src/backend/services/article.actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export async function updateMyArticle(
223223
cover_image: input.cover_image,
224224
is_published: input.is_published,
225225
published_at: input.is_published ? new Date() : null,
226+
metadata: input.metadata,
226227
},
227228
});
228229
return article;

src/backend/services/inputs/article.input.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ export const ArticleRepositoryInput = {
7575
description: z.string().optional(),
7676
keywords: z.array(z.string()).optional(),
7777
// canonical_url: z.string().url().nullable().optional(),
78-
canonical_url: z
79-
.union([z.string().url(), z.literal(""), z.null()])
80-
.optional()
81-
.nullable()
82-
.transform((val) => (val === "" ? null : val)),
78+
// canonical_url: z
79+
// .union([z.string().url(), z.literal(""), z.null()])
80+
// .optional()
81+
// .nullable()
82+
// .transform((val) => (val === "" ? null : val)),
8383
})
8484
.nullable()
8585
.optional(),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { color } from "@cloudinary/url-gen/qualifiers/background";
2+
import { z } from "zod";
3+
4+
export const TagRepositoryInput = {
5+
findAllInput: z.object({
6+
page: z.number().default(1),
7+
limit: z.number().default(10),
8+
}),
9+
createInput: z.object({
10+
name: z.string(),
11+
icon: z.string().optional().nullable(),
12+
color: z.string().optional().nullable(),
13+
description: z.string().optional().nullable(),
14+
}),
15+
updateInput: z.object({
16+
tag_id: z.string(),
17+
name: z.string().optional(),
18+
icon: z.string().optional().nullable(),
19+
color: z.string().optional().nullable(),
20+
description: z.string().optional().nullable(),
21+
}),
22+
deleteInput: z.object({
23+
tag_id: z.string(),
24+
}),
25+
};

src/backend/services/tag.action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/components/Editor/ArticleEditorDrawer.tsx

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useTranslation } from "@/i18n/use-translation";
99
import { useSession } from "@/store/session.atom";
1010
import { zodResolver } from "@hookform/resolvers/zod";
1111
import { useMutation } from "@tanstack/react-query";
12-
import { LinkIcon } from "lucide-react";
12+
import { LinkIcon, Loader } from "lucide-react";
1313
import { useRouter } from "next/navigation";
1414
import React from "react";
1515
import { SubmitHandler, useForm } from "react-hook-form";
@@ -75,7 +75,6 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
7575
title: article?.metadata?.seo?.title ?? "",
7676
description: article?.metadata?.seo?.description ?? "",
7777
keywords: article?.metadata?.seo?.keywords ?? [],
78-
canonical_url: article?.metadata?.seo?.canonical_url ?? "",
7978
},
8079
},
8180
},
@@ -85,6 +84,8 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
8584
const handleOnSubmit: SubmitHandler<
8685
z.infer<typeof ArticleRepositoryInput.updateMyArticleInput>
8786
> = (payload) => {
87+
console.log(payload);
88+
8889
updateMyArticleMutation.mutate({
8990
article_id: article?.id ?? "",
9091
excerpt: payload.excerpt,
@@ -94,7 +95,6 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
9495
title: payload.metadata?.seo?.title ?? "",
9596
description: payload.metadata?.seo?.description ?? "",
9697
keywords: payload.metadata?.seo?.keywords ?? [],
97-
canonical_url: payload.metadata?.seo?.canonical_url ?? "",
9898
},
9999
},
100100
});
@@ -109,7 +109,7 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
109109
onSubmit={form.handleSubmit(handleOnSubmit)}
110110
className="flex flex-col gap-2"
111111
>
112-
{JSON.stringify(form.formState.errors)}
112+
{/* {JSON.stringify(form.formState.errors)} */}
113113

114114
<FormField
115115
control={form.control}
@@ -181,21 +181,6 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
181181
)}
182182
/>
183183

184-
{/* <FormField
185-
control={form.control}
186-
name="metadata.seo.canonical_url"
187-
render={({ field }) => (
188-
<FormItem>
189-
<FormLabel>{_t("Are you republishing")}?</FormLabel>
190-
<FormDescription className="text-xs"></FormDescription>
191-
<FormControl>
192-
<Input {...field} />
193-
</FormControl>
194-
<FormMessage />
195-
</FormItem>
196-
)}
197-
/> */}
198-
199184
<FormField
200185
control={form.control}
201186
name="metadata.seo.keywords"
@@ -247,32 +232,17 @@ const ArticleEditorDrawer: React.FC<Props> = ({ article, open, onClose }) => {
247232
</FormItem>
248233
)}
249234
/>
250-
{/*
251-
<FormField
252-
control={form.control}
253-
name="metadata.seo.keywords"
254-
render={({ field }) => (
255-
<FormItem>
256-
<FormLabel>{_t("SEO Keywords")}</FormLabel>
257-
<FormDescription className="text-xs">
258-
Put some relevent keywords for better search engine
259-
visibility
260-
</FormDescription>
261-
<FormControl>
262-
<InputTags
263-
value={[]}
264-
onChange={(e) => {
265-
console.log(e);
266-
}}
267-
/>
268-
</FormControl>
269-
<FormMessage />
270-
</FormItem>
271-
)}
272-
/> */}
273235
</div>
274236

275-
<Button type="submit">{_t("Save")}</Button>
237+
<Button
238+
type="submit"
239+
disabled={updateMyArticleMutation.isPending}
240+
>
241+
{updateMyArticleMutation.isPending && (
242+
<Loader className="mr-2 h-4 w-4 animate-spin" />
243+
)}
244+
{_t("Save")}
245+
</Button>
276246
</form>
277247
</Form>
278248
</div>

0 commit comments

Comments
 (0)