2022-09-19 09:26:50 +00:00
|
|
|
<script lang="ts" setup>
|
2022-12-20 11:04:29 +00:00
|
|
|
import {
|
|
|
|
IconMotionLine,
|
|
|
|
Toast,
|
2024-05-23 02:56:50 +00:00
|
|
|
VButton,
|
2023-03-27 08:06:13 +00:00
|
|
|
VDropdown,
|
2024-05-23 02:56:50 +00:00
|
|
|
VModal,
|
|
|
|
VSpace,
|
2022-12-20 11:04:29 +00:00
|
|
|
} from "@halo-dev/components";
|
2022-09-26 07:48:55 +00:00
|
|
|
import SubmitButton from "@/components/button/SubmitButton.vue";
|
2022-09-19 09:26:50 +00:00
|
|
|
import type {
|
|
|
|
ListedComment,
|
|
|
|
ListedReply,
|
|
|
|
ReplyRequest,
|
|
|
|
} from "@halo-dev/api-client";
|
|
|
|
// @ts-ignore
|
|
|
|
import { Picker } from "emoji-mart";
|
|
|
|
import i18n from "@emoji-mart/data/i18n/zh.json";
|
2024-05-23 02:56:50 +00:00
|
|
|
import { onMounted, ref } from "vue";
|
2022-09-19 09:26:50 +00:00
|
|
|
import { setFocus } from "@/formkit/utils/focus";
|
2022-09-22 08:46:32 +00:00
|
|
|
import { apiClient } from "@/utils/api-client";
|
2023-03-23 08:54:33 +00:00
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
2022-09-19 09:26:50 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
comment?: ListedComment;
|
|
|
|
reply?: ListedReply;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
visible: false,
|
|
|
|
comment: undefined,
|
|
|
|
reply: undefined,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: "close"): void;
|
|
|
|
}>();
|
|
|
|
|
2024-05-27 08:56:57 +00:00
|
|
|
const modal = ref<InstanceType<typeof VModal> | null>(null);
|
2024-05-23 02:56:50 +00:00
|
|
|
const formState = ref<ReplyRequest>({
|
2022-09-19 09:26:50 +00:00
|
|
|
raw: "",
|
|
|
|
content: "",
|
|
|
|
allowNotification: true,
|
|
|
|
quoteReply: undefined,
|
|
|
|
});
|
2024-05-23 02:56:50 +00:00
|
|
|
const saving = ref(false);
|
2022-09-19 09:26:50 +00:00
|
|
|
|
2024-05-23 02:56:50 +00:00
|
|
|
onMounted(() => {
|
|
|
|
setFocus("content-input");
|
2022-09-19 09:26:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const handleCreateReply = async () => {
|
|
|
|
try {
|
|
|
|
saving.value = true;
|
2024-05-23 02:56:50 +00:00
|
|
|
|
2022-09-19 09:26:50 +00:00
|
|
|
if (props.reply) {
|
|
|
|
formState.value.quoteReply = props.reply.reply.metadata.name;
|
|
|
|
}
|
2024-05-23 02:56:50 +00:00
|
|
|
|
|
|
|
formState.value.content = formState.value.raw;
|
|
|
|
|
2022-09-19 09:26:50 +00:00
|
|
|
await apiClient.comment.createReply({
|
2022-11-17 02:38:22 +00:00
|
|
|
name: props.comment?.comment.metadata.name as string,
|
2022-09-19 09:26:50 +00:00
|
|
|
replyRequest: formState.value,
|
|
|
|
});
|
2024-05-23 02:56:50 +00:00
|
|
|
|
2024-05-27 08:56:57 +00:00
|
|
|
modal.value?.close();
|
2022-12-20 11:04:29 +00:00
|
|
|
|
2023-03-23 08:54:33 +00:00
|
|
|
Toast.success(
|
|
|
|
t("core.comment.reply_modal.operations.submit.toast_success")
|
|
|
|
);
|
2022-09-19 09:26:50 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to create comment reply", error);
|
|
|
|
} finally {
|
|
|
|
saving.value = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Emoji picker
|
|
|
|
const emojiPickerRef = ref<HTMLElement | null>(null);
|
|
|
|
|
2024-05-23 02:56:50 +00:00
|
|
|
const handleCreateEmojiPicker = async () => {
|
|
|
|
if (emojiPickerRef.value?.childElementCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await import("@emoji-mart/data");
|
|
|
|
|
2022-09-19 09:26:50 +00:00
|
|
|
const emojiPicker = new Picker({
|
2024-05-23 02:56:50 +00:00
|
|
|
data: Object.assign({}, data),
|
2022-09-19 09:26:50 +00:00
|
|
|
theme: "light",
|
|
|
|
autoFocus: true,
|
|
|
|
i18n: i18n,
|
|
|
|
onEmojiSelect: onEmojiSelect,
|
|
|
|
});
|
2024-05-23 02:56:50 +00:00
|
|
|
|
2022-11-17 02:38:22 +00:00
|
|
|
emojiPickerRef.value?.appendChild(emojiPicker as unknown as Node);
|
2022-09-19 09:26:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onEmojiSelect = (emoji: { native: string }) => {
|
|
|
|
formState.value.raw += emoji.native;
|
2024-05-23 02:56:50 +00:00
|
|
|
setFocus("content-input");
|
2022-09-19 09:26:50 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VModal
|
2024-05-23 02:56:50 +00:00
|
|
|
ref="modal"
|
2023-03-23 08:54:33 +00:00
|
|
|
:title="$t('core.comment.reply_modal.title')"
|
2022-10-31 08:01:28 +00:00
|
|
|
:width="500"
|
2024-05-23 02:56:50 +00:00
|
|
|
@close="emit('close')"
|
2022-09-19 09:26:50 +00:00
|
|
|
>
|
|
|
|
<FormKit
|
2024-05-23 02:56:50 +00:00
|
|
|
id="create-reply-form"
|
|
|
|
name="create-reply-form"
|
2022-09-19 09:26:50 +00:00
|
|
|
type="form"
|
|
|
|
:config="{ validationVisibility: 'submit' }"
|
|
|
|
@submit="handleCreateReply"
|
|
|
|
>
|
|
|
|
<FormKit
|
2024-05-23 02:56:50 +00:00
|
|
|
id="content-input"
|
2022-09-19 09:26:50 +00:00
|
|
|
v-model="formState.raw"
|
|
|
|
type="textarea"
|
2023-03-23 08:54:33 +00:00
|
|
|
:validation-label="$t('core.comment.reply_modal.fields.content.label')"
|
2022-10-31 08:01:28 +00:00
|
|
|
:rows="6"
|
2024-05-23 02:56:50 +00:00
|
|
|
value=""
|
2022-11-23 03:00:19 +00:00
|
|
|
validation="required|length:0,1024"
|
2022-09-19 09:26:50 +00:00
|
|
|
></FormKit>
|
|
|
|
</FormKit>
|
|
|
|
<div class="mt-2 flex justify-end">
|
2024-05-23 02:56:50 +00:00
|
|
|
<VDropdown :classes="['!p-0']" @show="handleCreateEmojiPicker">
|
2022-09-19 09:26:50 +00:00
|
|
|
<IconMotionLine
|
|
|
|
class="h-5 w-5 cursor-pointer text-gray-500 transition-all hover:text-gray-900"
|
|
|
|
/>
|
|
|
|
<template #popper>
|
|
|
|
<div ref="emojiPickerRef"></div>
|
|
|
|
</template>
|
2023-03-27 08:06:13 +00:00
|
|
|
</VDropdown>
|
2022-09-19 09:26:50 +00:00
|
|
|
</div>
|
|
|
|
<template #footer>
|
|
|
|
<VSpace>
|
2022-09-26 07:48:55 +00:00
|
|
|
<SubmitButton
|
|
|
|
:loading="saving"
|
|
|
|
type="secondary"
|
2023-03-23 08:54:33 +00:00
|
|
|
:text="$t('core.common.buttons.submit')"
|
2024-05-23 02:56:50 +00:00
|
|
|
@submit="$formkit.submit('create-reply-form')"
|
2022-09-26 07:48:55 +00:00
|
|
|
>
|
|
|
|
</SubmitButton>
|
2024-05-27 08:56:57 +00:00
|
|
|
<VButton @click="modal?.close()">
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.common.buttons.cancel_and_shortcut") }}
|
|
|
|
</VButton>
|
2022-09-19 09:26:50 +00:00
|
|
|
</VSpace>
|
|
|
|
</template>
|
|
|
|
</VModal>
|
|
|
|
</template>
|