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,
|
ArticleListItem,
|
||||||
ArticleListParams,
|
ArticleListParams,
|
||||||
KolWorkspaceCard,
|
KolWorkspaceCard,
|
||||||
RecentArticle,
|
|
||||||
TemplateListItem,
|
TemplateListItem,
|
||||||
} from '@geo/shared-types'
|
} from '@geo/shared-types'
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
@@ -94,17 +93,6 @@ const kolCardsQuery = useQuery({
|
|||||||
queryFn: () => workspaceApi.kolCards(),
|
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 articleParams = computed<ArticleListParams>(() => {
|
||||||
const params: ArticleListParams = {
|
const params: ArticleListParams = {
|
||||||
page: page.value,
|
page: page.value,
|
||||||
@@ -147,65 +135,11 @@ const articleListQuery = useQuery({
|
|||||||
queryFn: () => articlesApi.list(articleParams.value),
|
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[]>(() =>
|
const displayedArticles = computed<ArticleListItem[]>(() =>
|
||||||
shouldUseRecentFallback.value
|
articleListQuery.data.value?.items || [],
|
||||||
? recentTemplateArticles.value
|
|
||||||
: articleListQuery.data.value?.items || [],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const displayedArticleTotal = computed(() =>
|
const displayedArticleTotal = computed(() => articleListQuery.data.value?.total || 0)
|
||||||
shouldUseRecentFallback.value
|
|
||||||
? recentTemplateArticles.value.length
|
|
||||||
: articleListQuery.data.value?.total || 0,
|
|
||||||
)
|
|
||||||
|
|
||||||
let articlePollingTimer: number | null = null
|
let articlePollingTimer: number | null = null
|
||||||
const ARTICLE_LIST_POLL_INTERVAL_MS = 5000
|
const ARTICLE_LIST_POLL_INTERVAL_MS = 5000
|
||||||
@@ -287,18 +221,14 @@ const articleColumns = computed<TableColumnsType<ArticleListItem>>(() => [
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const articlePagination = computed(() =>
|
const articlePagination = computed(() => ({
|
||||||
shouldUseRecentFallback.value
|
current: page.value,
|
||||||
? false
|
pageSize: pageSize.value,
|
||||||
: {
|
total: displayedArticleTotal.value,
|
||||||
current: page.value,
|
showSizeChanger: true,
|
||||||
pageSize: pageSize.value,
|
onChange: handleTableChange,
|
||||||
total: displayedArticleTotal.value,
|
onShowSizeChange: handleTableChange,
|
||||||
showSizeChanger: true,
|
}))
|
||||||
onChange: handleTableChange,
|
|
||||||
onShowSizeChange: handleTableChange,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// removed wizard watch effect
|
// removed wizard watch effect
|
||||||
|
|
||||||
@@ -449,13 +379,6 @@ function startArticlePolling(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
articlePollingTimer = window.setInterval(() => {
|
articlePollingTimer = window.setInterval(() => {
|
||||||
if (shouldUseRecentFallback.value) {
|
|
||||||
if (!recentArticlesQuery.isFetching.value) {
|
|
||||||
void recentArticlesQuery.refetch()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!articleListQuery.isFetching.value) {
|
if (!articleListQuery.isFetching.value) {
|
||||||
void articleListQuery.refetch()
|
void articleListQuery.refetch()
|
||||||
}
|
}
|
||||||
@@ -493,7 +416,7 @@ async function copyArticle(articleId: number): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshRecords(): void {
|
function refreshRecords(): void {
|
||||||
void Promise.all([articleListQuery.refetch(), recentArticlesQuery.refetch()])
|
void articleListQuery.refetch()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -602,7 +525,7 @@ function refreshRecords(): void {
|
|||||||
class="templates-view__desktop-table"
|
class="templates-view__desktop-table"
|
||||||
:columns="articleColumns"
|
:columns="articleColumns"
|
||||||
:data-source="displayedArticles"
|
:data-source="displayedArticles"
|
||||||
:loading="articleListQuery.isPending.value || recentArticlesQuery.isPending.value"
|
:loading="articleListQuery.isPending.value"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
:pagination="articlePagination"
|
:pagination="articlePagination"
|
||||||
:scroll="{ x: 1068 }"
|
:scroll="{ x: 1068 }"
|
||||||
@@ -657,7 +580,7 @@ function refreshRecords(): void {
|
|||||||
|
|
||||||
<div class="templates-view__mobile-records">
|
<div class="templates-view__mobile-records">
|
||||||
<a-skeleton
|
<a-skeleton
|
||||||
v-if="articleListQuery.isPending.value || recentArticlesQuery.isPending.value"
|
v-if="articleListQuery.isPending.value"
|
||||||
active
|
active
|
||||||
:paragraph="{ rows: 6 }"
|
:paragraph="{ rows: 6 }"
|
||||||
/>
|
/>
|
||||||
@@ -720,7 +643,6 @@ function refreshRecords(): void {
|
|||||||
</article>
|
</article>
|
||||||
|
|
||||||
<a-pagination
|
<a-pagination
|
||||||
v-if="!shouldUseRecentFallback"
|
|
||||||
class="templates-view__mobile-pagination"
|
class="templates-view__mobile-pagination"
|
||||||
:current="page"
|
:current="page"
|
||||||
:page-size="pageSize"
|
:page-size="pageSize"
|
||||||
|
|||||||
Reference in New Issue
Block a user