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

fix: unable to manually fill in the publish time #5472

Merged
merged 1 commit into from Mar 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,7 +6,7 @@ import {
VModal,
VSpace,
} from "@halo-dev/components";
import { computed, nextTick, ref, watchEffect } from "vue";
import { computed, nextTick, ref, toRaw, watch } from "vue";
import type { SinglePage } from "@halo-dev/api-client";
import { cloneDeep } from "lodash-es";
import { apiClient } from "@/utils/api-client";
Expand Down Expand Up @@ -76,6 +76,7 @@ const saving = ref(false);
const publishing = ref(false);
const publishCanceling = ref(false);
const submitType = ref<"publish" | "save">();
const publishTime = ref<string | undefined>(undefined);

const isUpdateMode = computed(() => {
return !!formState.value.metadata.creationTimestamp;
Expand Down Expand Up @@ -247,26 +248,26 @@ const handleUnpublish = async () => {
}
};

watchEffect(() => {
if (props.singlePage) {
formState.value = cloneDeep(props.singlePage);
watch(
() => props.singlePage,
(value) => {
if (value) {
formState.value = toRaw(value);
publishTime.value = toDatetimeLocal(formState.value.spec.publishTime);
}
}
});
);

watch(
() => publishTime.value,
(value) => {
formState.value.spec.publishTime = value ? toISOString(value) : undefined;
}
);

// custom templates
const { templates } = useThemeCustomTemplates("page");

// publishTime
const publishTime = computed({
get() {
const { publishTime } = formState.value.spec;
return publishTime ? toDatetimeLocal(publishTime) : undefined;
},
set(value) {
formState.value.spec.publishTime = value ? toISOString(value) : undefined;
},
});

// slug
const { handleGenerateSlug } = useSlugify(
computed(() => formState.value.spec.title),
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
VModal,
VSpace,
} from "@halo-dev/components";
import { computed, nextTick, ref, watchEffect } from "vue";
import { computed, nextTick, ref, toRaw, watch } from "vue";
import type { Post } from "@halo-dev/api-client";
import { cloneDeep } from "lodash-es";
import { apiClient } from "@/utils/api-client";
Expand Down Expand Up @@ -78,6 +78,7 @@ const saving = ref(false);
const publishing = ref(false);
const publishCanceling = ref(false);
const submitType = ref<"publish" | "save">();
const publishTime = ref<string | undefined>(undefined);

const isUpdateMode = computed(() => {
return !!formState.value.metadata.creationTimestamp;
Expand Down Expand Up @@ -208,26 +209,26 @@ const handleUnpublish = async () => {
}
};

watchEffect(() => {
if (props.post) {
formState.value = cloneDeep(props.post);
watch(
() => props.post,
(value) => {
if (value) {
formState.value = toRaw(value);
publishTime.value = toDatetimeLocal(formState.value.spec.publishTime);
}
}
});
);

watch(
() => publishTime.value,
(value) => {
formState.value.spec.publishTime = value ? toISOString(value) : undefined;
}
);

// custom templates
const { templates } = useThemeCustomTemplates("post");

// publishTime convert
const publishTime = computed({
get() {
const { publishTime } = formState.value.spec;
return publishTime ? toDatetimeLocal(publishTime) : undefined;
},
set(value) {
formState.value.spec.publishTime = value ? toISOString(value) : undefined;
},
});

const annotationsFormRef = ref<InstanceType<typeof AnnotationsForm>>();

// slug
Expand Down