|
386 | 386 | >{{ $t("common.report") }}</span
|
387 | 387 | >
|
388 | 388 | </button>
|
| 389 | + <button |
| 390 | + v-if=" |
| 391 | + authStore.authenticated && |
| 392 | + profileId == authStore.user.id |
| 393 | + " |
| 394 | + class="flex w-full items-center justify-start gap-2 py-3 px-4 hover:bg-gray-100 text-red-500 dark:hover:bg-slate-800 cursor-pointer" |
| 395 | + @click="handleVideoDelete" |
| 396 | + > |
| 397 | + <i class="bx bx-trash text-[20px]"></i> |
| 398 | + <span |
| 399 | + class="pl-2 font-semibold text-sm" |
| 400 | + >{{ $t("common.delete") }}</span |
| 401 | + > |
| 402 | + </button> |
389 | 403 | </div>
|
390 | 404 | </div>
|
391 | 405 | </div>
|
@@ -544,6 +558,8 @@ import "video.js/dist/video-js.css";
|
544 | 558 | import LoopLink from "../LoopLink.vue";
|
545 | 559 | import { useReportModal } from "@/composables/useReportModal";
|
546 | 560 | import { useQueryClient } from "@tanstack/vue-query";
|
| 561 | +import { useAlertModal } from "@/composables/useAlertModal.js"; |
| 562 | +import { useI18n } from "vue-i18n"; |
547 | 563 |
|
548 | 564 | const props = defineProps({
|
549 | 565 | videoId: { type: String, required: true },
|
@@ -588,6 +604,8 @@ const isSensitiveRevealed = ref(false);
|
588 | 604 | const pendingPlay = ref(false);
|
589 | 605 | const { openReportModal } = useReportModal();
|
590 | 606 | const queryClient = useQueryClient();
|
| 607 | +const { alertModal, confirmModal } = useAlertModal(); |
| 608 | +const { t } = useI18n(); |
591 | 609 |
|
592 | 610 | const {
|
593 | 611 | hasInteracted: hasGlobalInteraction,
|
@@ -732,17 +750,19 @@ const submitComment = async () => {
|
732 | 750 |
|
733 | 751 | const toggleLike = async () => {
|
734 | 752 | const state = videoLiked.value;
|
735 |
| - queryClient.invalidateQueries({ queryKey: ["feed"] }); |
736 |
| - queryClient.invalidateQueries({ queryKey: ["following-feed"] }); |
737 |
| - await videoStore.likeVideo().then((res) => { |
738 |
| - videoStore.setVideo(res.data); |
739 |
| - }); |
| 753 | +
|
740 | 754 | if (state) {
|
741 |
| - videoLiked.value = false; |
742 |
| - likeCount.value = Math.max((likeCount.value ?? 0) - 1, 0); |
| 755 | + await videoStore.unlikeVideo(props.videoId).then((res) => { |
| 756 | + videoStore.setVideo(res.data); |
| 757 | + videoLiked.value = false; |
| 758 | + likeCount.value = res.data.likes; |
| 759 | + }); |
743 | 760 | } else {
|
744 |
| - videoLiked.value = true; |
745 |
| - likeCount.value = likeCount.value + 1; |
| 761 | + await videoStore.likeVideo(props.videoId).then((res) => { |
| 762 | + videoStore.setVideo(res.data); |
| 763 | + videoLiked.value = true; |
| 764 | + likeCount.value = res.data.likes; |
| 765 | + }); |
746 | 766 | }
|
747 | 767 | };
|
748 | 768 |
|
@@ -951,6 +971,28 @@ const formatCount = (count) => {
|
951 | 971 | return count.toString();
|
952 | 972 | };
|
953 | 973 |
|
| 974 | +const handleVideoDelete = async () => { |
| 975 | + showMenu.value = false; |
| 976 | +
|
| 977 | + const result = await confirmModal( |
| 978 | + t("post.deleteVideo"), |
| 979 | + t("post.deleteVideoConfirmMessage"), |
| 980 | + t("common.delete"), |
| 981 | + t("common.cancel"), |
| 982 | + ); |
| 983 | + if (result) { |
| 984 | + try { |
| 985 | + await videoStore.deleteVideoById(props.videoId); |
| 986 | + await nextTick(); |
| 987 | + queryClient.invalidateQueries({ queryKey: ["feed"] }); |
| 988 | + queryClient.invalidateQueries({ queryKey: ["following-feed"] }); |
| 989 | + window.location.reload(); |
| 990 | + } catch (error) { |
| 991 | + console.log(error); |
| 992 | + } |
| 993 | + } |
| 994 | +}; |
| 995 | +
|
954 | 996 | defineExpose({
|
955 | 997 | play,
|
956 | 998 | pause,
|
|
0 commit comments