From bcd997231a54a808de9220e984f5468fa88f9ceb Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sat, 10 Sep 2022 00:32:46 +0800 Subject: [PATCH] feat: refine post filtering --- src/modules/contents/posts/PostList.vue | 145 +++++++++++++++++- .../posts/components/PostSettingModal.vue | 16 +- 2 files changed, 150 insertions(+), 11 deletions(-) diff --git a/src/modules/contents/posts/PostList.vue b/src/modules/contents/posts/PostList.vue index 08dfb0721..d0906b41f 100644 --- a/src/modules/contents/posts/PostList.vue +++ b/src/modules/contents/posts/PostList.vue @@ -9,6 +9,7 @@ import { IconEyeOff, IconSettings, IconTeam, + IconCloseCircle, useDialog, VButton, VCard, @@ -21,7 +22,14 @@ import UserDropdownSelector from "@/components/dropdown-selector/UserDropdownSel import PostSettingModal from "./components/PostSettingModal.vue"; import PostTag from "../posts/tags/components/PostTag.vue"; import { onMounted, ref, watch, watchEffect } from "vue"; -import type { ListedPostList, Post, PostRequest } from "@halo-dev/api-client"; +import type { + User, + Category, + ListedPostList, + Post, + PostRequest, + Tag, +} from "@halo-dev/api-client"; import { apiClient } from "@halo-dev/admin-shared"; import { formatDatetime } from "@/utils/date"; import { usePostCategory } from "@/modules/contents/posts/categories/composables/use-post-category"; @@ -74,10 +82,29 @@ const handleFetchPosts = async () => { ); } + let categories: string[] | undefined; + let tags: string[] | undefined; + let contributors: string[] | undefined; + + if (selectedCategoryFilterItem.value) { + categories = [selectedCategoryFilterItem.value.metadata.name]; + } + + if (selectedTagFilterItem.value) { + tags = [selectedTagFilterItem.value.metadata.name]; + } + + if (selectedContributorItem.value) { + contributors = [selectedContributorItem.value.metadata.name]; + } + const { data } = await apiClient.post.listPosts({ page: posts.value.page, size: posts.value.size, labelSelector, + categories, + tags, + contributors, }); posts.value = data; } catch (e) { @@ -266,6 +293,9 @@ const PhaseFilterItems: FilterItem[] = [ const selectedVisibleFilterItem = ref(VisibleFilterItems[0]); const selectedPhaseFilterItem = ref(PhaseFilterItems[0]); +const selectedCategoryFilterItem = ref(); +const selectedTagFilterItem = ref(); +const selectedContributorItem = ref(); function handleVisibleFilterItemChange(filterItem: FilterItem) { selectedVisibleFilterItem.value = filterItem; @@ -276,6 +306,21 @@ function handlePhaseFilterItemChange(filterItem: FilterItem) { selectedPhaseFilterItem.value = filterItem; handleFetchPosts(); } + +function handleCategoryFilterItemChange(category?: Category) { + selectedCategoryFilterItem.value = category; + handleFetchPosts(); +} + +function handleTagFilterItemChange(tag?: Tag) { + selectedTagFilterItem.value = tag; + handleFetchPosts(); +} + +function handleContributorFilterItemChange(user?: User) { + selectedContributorItem.value = user; + handleFetchPosts(); +} - +
diff --git a/src/modules/contents/posts/components/PostSettingModal.vue b/src/modules/contents/posts/components/PostSettingModal.vue index 57810a51a..09e6645b1 100644 --- a/src/modules/contents/posts/components/PostSettingModal.vue +++ b/src/modules/contents/posts/components/PostSettingModal.vue @@ -1,6 +1,6 @@