From f52aa068c656e7988cff7a71b7ddff2d5b981aac Mon Sep 17 00:00:00 2001 From: Dblue <89646192+trungdong11@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:57:29 +0700 Subject: [PATCH] [QUIZ-144][QUIZ-165] feat: post feature in group (#93) * [QUIZ-144][QUIZ-165] feat: post feature in group * [QUIZ-144][QUIZ-165] feat: post feature in group --- src/components/group/Activity.vue | 182 +++++++++++--- src/components/group/comment/FormSend.vue | 34 +++ src/components/group/modal/MCreatePost.vue | 246 +++++++++++++------ src/components/group/modal/MListQuizzfly.vue | 29 +-- src/services/group.ts | 13 + src/services/user.ts | 6 +- src/types/group.ts | 31 ++- 7 files changed, 399 insertions(+), 142 deletions(-) create mode 100644 src/components/group/comment/FormSend.vue diff --git a/src/components/group/Activity.vue b/src/components/group/Activity.vue index eb1ea4b..c8e28a9 100644 --- a/src/components/group/Activity.vue +++ b/src/components/group/Activity.vue @@ -8,10 +8,13 @@ import { useAuthStore } from '@/stores/auth' import { usePostStore } from '@/stores/group/post' import { formatDateTime } from '@/utils/time' import { useConfirmDialog } from '@/stores/modal' +import FormSend from './comment/FormSend.vue' const confirmDialog = useConfirmDialog() const authStore = useAuthStore() const postStore = usePostStore() +const router = useRouter() +const route = useRoute() const getUser = computed(() => { return authStore.getUser @@ -21,6 +24,8 @@ const listPosts = computed(() => { return postStore.getPosts }) +const groupId = route.params.groupId as string + const isShowModal = ref(false) const isShowQuizzlfyModal = ref(false) @@ -52,6 +57,10 @@ const handleDeletePost = async (id: string) => { postStore.handleDeleteGroup(id) } } + +const handPosted = () => { + postStore.fetchPosts(1, groupId) +} - + diff --git a/src/components/group/comment/FormSend.vue b/src/components/group/comment/FormSend.vue new file mode 100644 index 0000000..1d6bd34 --- /dev/null +++ b/src/components/group/comment/FormSend.vue @@ -0,0 +1,34 @@ + + + + diff --git a/src/components/group/modal/MCreatePost.vue b/src/components/group/modal/MCreatePost.vue index fab41df..fe493d9 100644 --- a/src/components/group/modal/MCreatePost.vue +++ b/src/components/group/modal/MCreatePost.vue @@ -9,8 +9,9 @@ import sanitizeHtml from 'sanitize-html' import { type ICreatePost } from '@/types/group' import { useQuizzflyStore } from '@/stores/quizzfly/quizzfly' import { usePostStore } from '@/stores/group/post' -import ImagePicker from '@/components/base/ImagePicker.vue' import ScrollArea from '@/components/ui/scroll-area/ScrollArea.vue' +import { uploadMultiFileApi } from '@/services/file' +import { showToast } from '@/utils/toast' const quizzflyStore = useQuizzflyStore() const postStore = usePostStore() @@ -38,9 +39,58 @@ const closeModal = () => { const content = ref('') const type = ref<'SHARE' | 'POST'>('POST') -const files = ref([]) +const refImage = ref(null) +const listImage = ref([]) +const ImageUpload = ref([]) + +const onChangeBg = (e: Event) => { + const target = e.target as HTMLInputElement + const files = target?.files + + if (files && files.length > 0) { + for (let i = 0; i < files.length; i++) { + const file = files[i] + ImageUpload.value.push(file) + listImage.value.push(URL.createObjectURL(file)) + } + } +} + +const showChooseImage = () => { + refImage.value?.click() +} + +const removeBg = (data: string) => { + const index = listImage.value.indexOf(data) + if (index > -1) { + ImageUpload.value.splice(index, 1) + listImage.value.splice(index, 1) + } +} + const onSubmit = async () => { isLoading.value = true + const listImageUpload = [] as any + + if (ImageUpload.value.length > 0) { + const formData = new FormData() + + for (let i = 0; i < ImageUpload.value.length; i++) { + formData.append('files', ImageUpload.value[i]) + } + + try { + await uploadMultiFileApi(formData).then((res) => { + listImageUpload.push(...res.data) + }) + } catch (error) { + showToast({ + description: 'Upload files failed', + variant: 'destructive', + }) + } + } + if (quizzflyShared.value.id) { type.value = 'SHARE' idQuizzfly.value = quizzflyShared.value.id @@ -48,15 +98,17 @@ const onSubmit = async () => { type.value = 'POST' idQuizzfly.value = '' } + const data: ICreatePost = { type: type.value, content: sanitizeHtml(content.value), quizzfly_id: quizzflyShared.value?.id, - files: files.value, + files: listImageUpload, } - postStore.createPost(idGroup, data) - isLoading.value = false + + await postStore.createPost(idGroup, data) emits('created') + isLoading.value = false closeModal() } @@ -69,11 +121,11 @@ const handleRemoveQuizzfly = () => {