mirror of https://github.com/halo-dev/halo
Refactor comment data update using the patch api (#6112)
#### What type of PR is this? /area ui /kind improvement /milestone 2.17.x #### What this PR does / why we need it: 使用新的 patch 接口重构评论相关的逻辑。 #### Special notes for your reviewer: 需要测试: 1. 审核评论和回复功能。 2. 批量审核评论和回复功能。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/6086/head^2
parent
ae7dcbb317
commit
f45ffdeca1
|
@ -200,18 +200,22 @@ const handleApproveInBatch = async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const promises = commentsToUpdate?.map((comment) => {
|
const promises = commentsToUpdate?.map((comment) => {
|
||||||
return apiClient.extension.comment.updateContentHaloRunV1alpha1Comment(
|
return apiClient.extension.comment.patchContentHaloRunV1alpha1Comment(
|
||||||
{
|
{
|
||||||
name: comment.comment.metadata.name,
|
name: comment.comment.metadata.name,
|
||||||
comment: {
|
jsonPatchInner: [
|
||||||
...comment.comment,
|
{
|
||||||
spec: {
|
op: "add",
|
||||||
...comment.comment.spec,
|
path: "/spec/approved",
|
||||||
approved: true,
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approvedTime",
|
||||||
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
||||||
approvedTime: new Date().toISOString(),
|
value: new Date().toISOString(),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,7 +31,6 @@ import type {
|
||||||
CommentSubjectRefResult,
|
CommentSubjectRefResult,
|
||||||
} from "@halo-dev/console-shared";
|
} from "@halo-dev/console-shared";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import { computed, onMounted, provide, ref, type Ref } from "vue";
|
import { computed, onMounted, provide, ref, type Ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import ReplyCreationModal from "./ReplyCreationModal.vue";
|
import ReplyCreationModal from "./ReplyCreationModal.vue";
|
||||||
|
@ -91,17 +90,21 @@ const handleApproveReplyInBatch = async () => {
|
||||||
return !reply.reply.spec.approved;
|
return !reply.reply.spec.approved;
|
||||||
});
|
});
|
||||||
const promises = repliesToUpdate?.map((reply) => {
|
const promises = repliesToUpdate?.map((reply) => {
|
||||||
return apiClient.extension.reply.updateContentHaloRunV1alpha1Reply({
|
return apiClient.extension.reply.patchContentHaloRunV1alpha1Reply({
|
||||||
name: reply.reply.metadata.name,
|
name: reply.reply.metadata.name,
|
||||||
reply: {
|
jsonPatchInner: [
|
||||||
...reply.reply,
|
{
|
||||||
spec: {
|
op: "add",
|
||||||
...reply.reply.spec,
|
path: "/spec/approved",
|
||||||
approved: true,
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approvedTime",
|
||||||
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
||||||
approvedTime: new Date().toISOString(),
|
value: new Date().toISOString(),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await Promise.all(promises || []);
|
await Promise.all(promises || []);
|
||||||
|
@ -118,13 +121,21 @@ const handleApproveReplyInBatch = async () => {
|
||||||
|
|
||||||
const handleApprove = async () => {
|
const handleApprove = async () => {
|
||||||
try {
|
try {
|
||||||
const commentToUpdate = cloneDeep(props.comment.comment);
|
await apiClient.extension.comment.patchContentHaloRunV1alpha1Comment({
|
||||||
commentToUpdate.spec.approved = true;
|
name: props.comment.comment.metadata.name,
|
||||||
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approved",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approvedTime",
|
||||||
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
||||||
commentToUpdate.spec.approvedTime = new Date().toISOString();
|
value: new Date().toISOString(),
|
||||||
await apiClient.extension.comment.updateContentHaloRunV1alpha1Comment({
|
},
|
||||||
name: commentToUpdate.metadata.name,
|
],
|
||||||
comment: commentToUpdate,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Toast.success(t("core.common.toast.operation_success"));
|
Toast.success(t("core.common.toast.operation_success"));
|
||||||
|
@ -165,21 +176,16 @@ const {
|
||||||
const { mutateAsync: updateCommentLastReadTimeMutate } = useMutation({
|
const { mutateAsync: updateCommentLastReadTimeMutate } = useMutation({
|
||||||
mutationKey: ["update-comment-last-read-time"],
|
mutationKey: ["update-comment-last-read-time"],
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const { data: latestComment } =
|
return apiClient.extension.comment.patchContentHaloRunV1alpha1Comment(
|
||||||
await apiClient.extension.comment.getContentHaloRunV1alpha1Comment({
|
|
||||||
name: props.comment.comment.metadata.name,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!latestComment.status?.unreadReplyCount) {
|
|
||||||
return latestComment;
|
|
||||||
}
|
|
||||||
|
|
||||||
latestComment.spec.lastReadTime = new Date().toISOString();
|
|
||||||
|
|
||||||
return apiClient.extension.comment.updateContentHaloRunV1alpha1Comment(
|
|
||||||
{
|
{
|
||||||
name: latestComment.metadata.name,
|
name: props.comment.comment.metadata.name,
|
||||||
comment: latestComment,
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/lastReadTime",
|
||||||
|
value: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mute: true,
|
mute: true,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import type { ListedComment, ListedReply } from "@halo-dev/api-client";
|
||||||
import { formatDatetime } from "@/utils/date";
|
import { formatDatetime } from "@/utils/date";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { computed, inject, ref, type Ref } from "vue";
|
import { computed, inject, ref, type Ref } from "vue";
|
||||||
import { cloneDeep } from "lodash-es";
|
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useQueryClient } from "@tanstack/vue-query";
|
import { useQueryClient } from "@tanstack/vue-query";
|
||||||
import ReplyCreationModal from "./ReplyCreationModal.vue";
|
import ReplyCreationModal from "./ReplyCreationModal.vue";
|
||||||
|
@ -71,13 +70,21 @@ const handleDelete = async () => {
|
||||||
|
|
||||||
const handleApprove = async () => {
|
const handleApprove = async () => {
|
||||||
try {
|
try {
|
||||||
const replyToUpdate = cloneDeep(props.reply.reply);
|
await apiClient.extension.reply.patchContentHaloRunV1alpha1Reply({
|
||||||
replyToUpdate.spec.approved = true;
|
name: props.reply.reply.metadata.name,
|
||||||
|
jsonPatchInner: [
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approved",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "add",
|
||||||
|
path: "/spec/approvedTime",
|
||||||
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
// TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746
|
||||||
replyToUpdate.spec.approvedTime = new Date().toISOString();
|
value: new Date().toISOString(),
|
||||||
await apiClient.extension.reply.updateContentHaloRunV1alpha1Reply({
|
},
|
||||||
name: replyToUpdate.metadata.name,
|
],
|
||||||
reply: replyToUpdate,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Toast.success(t("core.common.toast.operation_success"));
|
Toast.success(t("core.common.toast.operation_success"));
|
||||||
|
|
Loading…
Reference in New Issue