Skip to content
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

feat: add retry mechanism for publishing posts on the UC end #7171

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Toast, VButton, VModal, VSpace } from "@halo-dev/components";
import { useMutation } from "@tanstack/vue-query";
import { ref } from "vue";
import { useI18n } from "vue-i18n";
import { usePostPublishMutate } from "../composables/use-post-publish-mutate";
import type { PostFormState } from "../types";
import PostSettingForm from "./PostSettingForm.vue";

Expand All @@ -31,6 +32,8 @@ const emit = defineEmits<{

const modal = ref<InstanceType<typeof VModal> | null>(null);

const { mutateAsync: postPublishMutate } = usePostPublishMutate();

const { mutate, isLoading } = useMutation({
mutationKey: ["uc:create-post"],
mutationFn: async ({ data }: { data: PostFormState }) => {
Expand All @@ -55,7 +58,7 @@ const { mutate, isLoading } = useMutation({
htmlMetas: [],
pinned: data.pinned,
priority: 0,
publish: false,
publish: props.publish,
publishTime: data.publishTime,
slug: data.slug,
tags: data.tags,
Expand All @@ -69,9 +72,7 @@ const { mutate, isLoading } = useMutation({
});

if (props.publish) {
await ucApiClient.content.post.publishMyPost({
name: post.metadata.name,
});
await postPublishMutate({ name: post.metadata.name });
}

return createdPost;
Expand Down
15 changes: 10 additions & 5 deletions ui/uc-src/modules/contents/posts/components/PostListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { useQueryClient } from "@tanstack/vue-query";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { usePostPublishMutate } from "../composables/use-post-publish-mutate";

const { t } = useI18n();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -67,13 +68,17 @@ const isPublishing = computed(() => {
);
});

const { mutateAsync: postPublishMutate } = usePostPublishMutate();

async function handlePublish() {
await ucApiClient.content.post.publishMyPost({
name: props.post.post.metadata.name,
});
try {
await postPublishMutate({ name: props.post.post.metadata.name });

Toast.success(t("core.common.toast.publish_success"));
queryClient.invalidateQueries({ queryKey: ["my-posts"] });
Toast.success(t("core.common.toast.publish_success"));
queryClient.invalidateQueries({ queryKey: ["my-posts"] });
} catch (_) {
Toast.error(t("core.common.toast.publish_failed_and_retry"));
}
}

function handleUnpublish() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ucApiClient } from "@halo-dev/api-client";
import { useMutation } from "@tanstack/vue-query";

export function usePostPublishMutate() {
return useMutation({
mutationKey: ["uc:publish-post"],
mutationFn: async ({ name }: { name: string }) => {
return await ucApiClient.content.post.publishMyPost(
{
name: name,
},
{
mute: true,
}
);
},
retry: 3,
});
}
Loading