Skip to content

Commit a6f9d06

Browse files
committed
refactor: update ArticleList component to use async function and improve article deletion handling
1 parent a6dcfbd commit a6f9d06

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/app/dashboard/_components/ArticleList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { Article } from "@/backend/models/domain-models";
34
import * as articleActions from "@/backend/services/article.actions";
45
import { useAppConfirm } from "@/components/app-confirm";
56
import { Button } from "@/components/ui/button";
@@ -30,7 +31,7 @@ import { addDays, differenceInHours } from "date-fns";
3031
import { TrashIcon } from "lucide-react";
3132
import Link from "next/link";
3233

33-
const ArticleList = () => {
34+
const ArticleList = async () => {
3435
const { _t } = useTranslation();
3536
const queryClient = useQueryClient();
3637
const appConfirm = useAppConfirm();
@@ -74,6 +75,9 @@ const ArticleList = () => {
7475

7576
return { previousData };
7677
},
78+
onSuccess(data, variables, context) {
79+
// data
80+
},
7781
onError: (err, variables, context) => {
7882
if (context?.previousData) {
7983
queryClient.setQueryData(["dashboard-articles"], context.previousData);

src/backend/models/action-contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type ActionResponse<T = any> =
1+
export type ActionResponse<T> =
22
| {
33
success: true | boolean;
44
data: T;

src/backend/services/article.actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export async function updateMyArticle(
185185
}
186186
}
187187

188-
export const scheduleArticleDelete = async (article_id: string) => {
188+
export async function scheduleArticleDelete(article_id: string) {
189189
try {
190190
const session_userID = await authID();
191191
if (!session_userID) {
@@ -206,14 +206,15 @@ export const scheduleArticleDelete = async (article_id: string) => {
206206
delete_scheduled_at: addDays(new Date(), 7),
207207
},
208208
});
209+
209210
return {
210211
success: true as const,
211212
data: updated.rows[0],
212-
};
213+
} satisfies ActionResponse<unknown>;
213214
} catch (error) {
214215
return handleActionException(error);
215216
}
216-
};
217+
}
217218

218219
export const restoreShceduleDeletedArticle = async (
219220
article_id: string

0 commit comments

Comments
 (0)