2023-09-01 03:02:12 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import type { ListedPost, Post } from "@halo-dev/api-client";
|
2024-06-26 10:42:50 +00:00
|
|
|
import { coreApiClient } from "@halo-dev/api-client";
|
2023-09-01 03:02:12 +00:00
|
|
|
import { IconEye, IconEyeOff, Toast, VEntityField } from "@halo-dev/components";
|
|
|
|
import { useMutation, useQueryClient } from "@tanstack/vue-query";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
|
|
|
withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
post: ListedPost;
|
|
|
|
}>(),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
const { mutate: changeVisibleMutation } = useMutation({
|
|
|
|
mutationFn: async (post: Post) => {
|
2024-08-14 06:59:57 +00:00
|
|
|
return await coreApiClient.content.post.patchPost({
|
2024-06-25 04:31:44 +00:00
|
|
|
name: post.metadata.name,
|
2024-08-14 06:59:57 +00:00
|
|
|
jsonPatchInner: [
|
|
|
|
{
|
|
|
|
op: "add",
|
|
|
|
path: "/spec/visible",
|
|
|
|
value: post.spec.visible === "PRIVATE" ? "PUBLIC" : "PRIVATE",
|
|
|
|
},
|
|
|
|
],
|
2024-06-25 04:31:44 +00:00
|
|
|
});
|
2023-09-01 03:02:12 +00:00
|
|
|
},
|
|
|
|
retry: 3,
|
|
|
|
onSuccess: () => {
|
|
|
|
Toast.success(t("core.common.toast.operation_success"));
|
2024-08-14 06:59:57 +00:00
|
|
|
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
2023-09-01 03:02:12 +00:00
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
Toast.error(t("core.common.toast.operation_failed"));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VEntityField>
|
|
|
|
<template #description>
|
|
|
|
<IconEye
|
|
|
|
v-if="post.post.spec.visible === 'PUBLIC'"
|
|
|
|
v-tooltip="$t('core.post.filters.visible.items.public')"
|
|
|
|
class="cursor-pointer text-sm transition-all hover:text-blue-600"
|
|
|
|
@click="changeVisibleMutation(post.post)"
|
|
|
|
/>
|
|
|
|
<IconEyeOff
|
|
|
|
v-if="post.post.spec.visible === 'PRIVATE'"
|
|
|
|
v-tooltip="$t('core.post.filters.visible.items.private')"
|
|
|
|
class="cursor-pointer text-sm transition-all hover:text-blue-600"
|
|
|
|
@click="changeVisibleMutation(post.post)"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</VEntityField>
|
|
|
|
</template>
|