refactor(admin-web): drop recent-articles fallback from templates records
Remove the recentArticlesQuery fallback path so the templates record table renders straight from the article list query, simplifying polling, pagination and loading state. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import type {
|
||||
ArticleListItem,
|
||||
ArticleListParams,
|
||||
KolWorkspaceCard,
|
||||
RecentArticle,
|
||||
TemplateListItem,
|
||||
} from '@geo/shared-types'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
@@ -94,17 +93,6 @@ const kolCardsQuery = useQuery({
|
||||
queryFn: () => workspaceApi.kolCards(),
|
||||
})
|
||||
|
||||
const recentArticlesQuery = useQuery({
|
||||
queryKey: computed(() => [
|
||||
'workspace',
|
||||
'recent-articles',
|
||||
'templates',
|
||||
companyStore.currentBrandId,
|
||||
]),
|
||||
enabled: computed(() => Boolean(companyStore.currentBrandId)),
|
||||
queryFn: () => workspaceApi.recentArticles(),
|
||||
})
|
||||
|
||||
const articleParams = computed<ArticleListParams>(() => {
|
||||
const params: ArticleListParams = {
|
||||
page: page.value,
|
||||
@@ -147,65 +135,11 @@ const articleListQuery = useQuery({
|
||||
queryFn: () => articlesApi.list(articleParams.value),
|
||||
})
|
||||
|
||||
const hasActiveRecordFilters = computed(() =>
|
||||
Boolean(
|
||||
appliedFilters.template_filter ||
|
||||
appliedFilters.publish_status ||
|
||||
appliedFilters.generate_status ||
|
||||
appliedFilters.keyword?.trim() ||
|
||||
appliedFilters.created_from ||
|
||||
appliedFilters.created_to,
|
||||
),
|
||||
)
|
||||
|
||||
const recentTemplateArticles = computed<ArticleListItem[]>(() =>
|
||||
(recentArticlesQuery.data.value || [])
|
||||
.filter(
|
||||
(article: RecentArticle) =>
|
||||
article.source_type === 'template' || article.source_type === 'kol',
|
||||
)
|
||||
.map((article: RecentArticle) => ({
|
||||
id: article.id,
|
||||
source_type: article.source_type,
|
||||
template_id: null,
|
||||
kol_prompt_id: null,
|
||||
template_name:
|
||||
article.template_name ||
|
||||
(article.source_type === 'kol'
|
||||
? t('templates.sections.refinedTemplates')
|
||||
: t('templates.sections.generalTemplates')),
|
||||
prompt_rule_id: null,
|
||||
prompt_rule_name: null,
|
||||
generation_mode: article.generation_mode,
|
||||
auto_publish_platforms: [],
|
||||
generate_status: article.generate_status,
|
||||
publish_status: article.publish_status,
|
||||
title: article.title,
|
||||
generation_error_message: null,
|
||||
word_count: article.word_count,
|
||||
source_label: article.source_label,
|
||||
created_at: article.created_at,
|
||||
})),
|
||||
)
|
||||
|
||||
const shouldUseRecentFallback = computed(
|
||||
() =>
|
||||
!hasActiveRecordFilters.value &&
|
||||
(articleListQuery.data.value?.total ?? 0) === 0 &&
|
||||
recentTemplateArticles.value.length > 0,
|
||||
)
|
||||
|
||||
const displayedArticles = computed<ArticleListItem[]>(() =>
|
||||
shouldUseRecentFallback.value
|
||||
? recentTemplateArticles.value
|
||||
: articleListQuery.data.value?.items || [],
|
||||
articleListQuery.data.value?.items || [],
|
||||
)
|
||||
|
||||
const displayedArticleTotal = computed(() =>
|
||||
shouldUseRecentFallback.value
|
||||
? recentTemplateArticles.value.length
|
||||
: articleListQuery.data.value?.total || 0,
|
||||
)
|
||||
const displayedArticleTotal = computed(() => articleListQuery.data.value?.total || 0)
|
||||
|
||||
let articlePollingTimer: number | null = null
|
||||
const ARTICLE_LIST_POLL_INTERVAL_MS = 5000
|
||||
@@ -287,18 +221,14 @@ const articleColumns = computed<TableColumnsType<ArticleListItem>>(() => [
|
||||
},
|
||||
])
|
||||
|
||||
const articlePagination = computed(() =>
|
||||
shouldUseRecentFallback.value
|
||||
? false
|
||||
: {
|
||||
current: page.value,
|
||||
pageSize: pageSize.value,
|
||||
total: displayedArticleTotal.value,
|
||||
showSizeChanger: true,
|
||||
onChange: handleTableChange,
|
||||
onShowSizeChange: handleTableChange,
|
||||
},
|
||||
)
|
||||
const articlePagination = computed(() => ({
|
||||
current: page.value,
|
||||
pageSize: pageSize.value,
|
||||
total: displayedArticleTotal.value,
|
||||
showSizeChanger: true,
|
||||
onChange: handleTableChange,
|
||||
onShowSizeChange: handleTableChange,
|
||||
}))
|
||||
|
||||
// removed wizard watch effect
|
||||
|
||||
@@ -449,13 +379,6 @@ function startArticlePolling(): void {
|
||||
}
|
||||
|
||||
articlePollingTimer = window.setInterval(() => {
|
||||
if (shouldUseRecentFallback.value) {
|
||||
if (!recentArticlesQuery.isFetching.value) {
|
||||
void recentArticlesQuery.refetch()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (!articleListQuery.isFetching.value) {
|
||||
void articleListQuery.refetch()
|
||||
}
|
||||
@@ -493,7 +416,7 @@ async function copyArticle(articleId: number): Promise<void> {
|
||||
}
|
||||
|
||||
function refreshRecords(): void {
|
||||
void Promise.all([articleListQuery.refetch(), recentArticlesQuery.refetch()])
|
||||
void articleListQuery.refetch()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -602,7 +525,7 @@ function refreshRecords(): void {
|
||||
class="templates-view__desktop-table"
|
||||
:columns="articleColumns"
|
||||
:data-source="displayedArticles"
|
||||
:loading="articleListQuery.isPending.value || recentArticlesQuery.isPending.value"
|
||||
:loading="articleListQuery.isPending.value"
|
||||
row-key="id"
|
||||
:pagination="articlePagination"
|
||||
:scroll="{ x: 1068 }"
|
||||
@@ -657,7 +580,7 @@ function refreshRecords(): void {
|
||||
|
||||
<div class="templates-view__mobile-records">
|
||||
<a-skeleton
|
||||
v-if="articleListQuery.isPending.value || recentArticlesQuery.isPending.value"
|
||||
v-if="articleListQuery.isPending.value"
|
||||
active
|
||||
:paragraph="{ rows: 6 }"
|
||||
/>
|
||||
@@ -720,7 +643,6 @@ function refreshRecords(): void {
|
||||
</article>
|
||||
|
||||
<a-pagination
|
||||
v-if="!shouldUseRecentFallback"
|
||||
class="templates-view__mobile-pagination"
|
||||
:current="page"
|
||||
:page-size="pageSize"
|
||||
|
||||
Reference in New Issue
Block a user