Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 20 additions & 106 deletions moon/apps/web/components/ClView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { atomWithWebStorage } from '@/utils/atomWithWebStorage'
import { IndexPageContainer, IndexPageContent } from '../IndexPages/components'
import { Pagination } from '../Issues/Pagenation'
import { clIdAtom } from '../Issues/utils/store'
import { useDraftClList } from './hook/useDraftClList'

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement for useDraftClList has been removed, but the hook file itself (moon/apps/web/components/ClView/hook/useDraftClList.ts) likely still exists in the codebase. Since this hook is no longer used anywhere (verified via search), the file should be deleted to avoid confusion and maintain a clean codebase.

Copilot uses AI. Check for mistakes.
type ItemsType = NonNullable<PostApiClListData['data']>['items']

Expand All @@ -66,7 +65,6 @@ export default function CLView() {
const [_clid, setClid] = useAtom(clIdAtom)

const { mutate: fetchClList } = usePostClList()
const { mutate: fetchDraftClList } = useDraftClList()
const { members } = useSyncedMembers()

const filterState = useFilterState({ scope: scope as string, type: 'cl' })
Expand Down Expand Up @@ -104,121 +102,37 @@ export default function CLView() {

const params = filterStateRef.current.toApiParams()
const currentOrder = orderRef.current
const baseAdditional: any = {
const additional: any = {
sort_by: handleSort(currentOrder.sort),
asc: currentOrder.time === 'Oldest',
status: status, // 始终传递 status,open 时后端会返回 open + draft
...params
}

if (status === 'draft') {
fetchDraftClList(
{
data: {
pagination: { page, per_page: pageSize },
additional: baseAdditional
}
},
{
onSuccess: (response) => {
const data = response.data

setClList((data?.items ?? []) as ItemsType)
setNumTotal(data?.total ?? 0)
},
onError: apiErrorToast,
onSettled: () => setIsLoading(false)
fetchClList(
{
data: {
pagination: { page, per_page: pageSize },
additional
}
)
} else if (status === 'open') {
const additional: any = {
...baseAdditional,
status: 'open',
asc: currentOrder.time === 'Oldest'
}

let openData: PostApiClListData['data'] | undefined
let draftData: PostApiClListData['data'] | undefined
let openFinished = false
let draftFinished = false

const finalize = () => {
if (!openFinished || !draftFinished) return
},
{
onSuccess: (response) => {
const data = response.data

const openItems = (openData?.items ?? []) as ItemsType
const draftItems = (draftData?.items ?? []) as ItemsType

setClList([...openItems, ...draftItems])
setNumTotal((openData?.total ?? 0) + (draftData?.total ?? 0))
setIsLoading(false)
}

fetchClList(
{
data: {
pagination: { page, per_page: pageSize },
additional
}
setClList((data?.items ?? []) as ItemsType)
setNumTotal(data?.total ?? 0)
},
{
onSuccess: (response) => {
openData = response.data
},
onError: apiErrorToast,
onSettled: () => {
openFinished = true
finalize()
}
}
)

fetchDraftClList(
{
data: {
pagination: { page, per_page: pageSize },
additional: baseAdditional
}
},
{
onSuccess: (response) => {
draftData = response.data
},
onError: apiErrorToast,
onSettled: () => {
draftFinished = true
finalize()
}
}
)
} else {
const additional: any = {
...baseAdditional,
status,
asc: currentOrder.time === 'Oldest'
onError: apiErrorToast,
onSettled: () => setIsLoading(false)
}

fetchClList(
{
data: {
pagination: { page, per_page: pageSize },
additional
}
},
{
onSuccess: (response) => {
const data = response.data

setClList((data?.items ?? []) as ItemsType)
setNumTotal(data?.total ?? 0)
},
onError: apiErrorToast,
onSettled: () => setIsLoading(false)
}
)
}
}, [page, pageSize, status, fetchClList, fetchDraftClList])
)
}, [page, pageSize, status, fetchClList])

useEffect(() => {
fetchClListData()
}, [page, pageSize, status, fetchClListData])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page, pageSize, status])
Comment on lines +134 to +135

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect dependency array is missing fetchClListData which is used inside the effect. While you've disabled the exhaustive-deps lint rule, this creates a potential issue: if fetchClList changes (which is included in fetchClListData's dependencies), the effect won't re-run but fetchClListData will capture a stale closure of fetchClList.

Either:

  1. Add fetchClListData to the dependency array (recommended), or
  2. If you intentionally want to avoid re-running when fetchClList changes, document why with a comment explaining the reasoning
Suggested change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page, pageSize, status])
}, [fetchClListData])

Copilot uses AI. Check for mistakes.

const handleSort = (str: string): string => {
switch (str) {
Expand Down
44 changes: 41 additions & 3 deletions moon/packages/types/generated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading