no invalidateAppDetail

This commit is contained in:
Stephen Zhou 2026-01-19 18:10:05 +08:00
parent 6e08e7ff95
commit 740245b982
No known key found for this signature in database
2 changed files with 49 additions and 8 deletions

View File

@ -18,15 +18,15 @@ import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useContext } from 'use-context-selector'
import CardView from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/card-view'
import { appStoreSelectors, useAppStore } from '@/app/components/app/store'
import { appStoreActions, appStoreSelectors, useAppStore } from '@/app/components/app/store'
import Button from '@/app/components/base/button'
import ContentDialog from '@/app/components/base/content-dialog'
import { ToastContext } from '@/app/components/base/toast'
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
import { useAppContext } from '@/context/app-context'
import { useProviderContext } from '@/context/provider-context'
import { copyApp, deleteApp, exportAppConfig, updateAppInfo } from '@/service/apps'
import { useInvalidateAppDetail, useInvalidateAppList } from '@/service/use-apps'
import { copyApp, deleteApp, exportAppConfig } from '@/service/apps'
import { useInvalidateAppList } from '@/service/use-apps'
import { fetchWorkflowDraft } from '@/service/workflow'
import { AppModeEnum } from '@/types/app'
import { getRedirection } from '@/utils/app-redirection'
@ -67,7 +67,6 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
const { appId } = useParams()
const { onPlanInfoChanged } = useProviderContext()
const appDetail = useAppStore(appStoreSelectors.appDetails(appId as string))
const invalidateAppDetail = useInvalidateAppDetail()
const invalidateAppList = useInvalidateAppList()
const [open, setOpen] = useState(openState)
const [showEditModal, setShowEditModal] = useState(false)
@ -90,7 +89,7 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
if (!appDetail)
return
try {
await updateAppInfo({
await appStoreActions.updateAppDetail({
appID: appDetail.id,
name,
icon_type,
@ -105,12 +104,12 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
type: 'success',
message: t('editDone', { ns: 'app' }),
})
invalidateAppDetail(appId as string)
// invalidateAppDetail(appId as string)
}
catch {
notify({ type: 'error', message: t('editFailed', { ns: 'app' }) })
}
}, [appDetail, notify, invalidateAppDetail, appId, t])
}, [appDetail, notify, appId, t])
const onCopy: DuplicateAppModalProps['onConfirm'] = async ({ name, icon_type, icon, icon_background }) => {
if (!appDetail)

View File

@ -1,7 +1,9 @@
import type { IChatItem } from '@/app/components/base/chat/chat/type'
import type { App, AppSSO } from '@/types/app'
import type { App, AppIconType, AppSSO } from '@/types/app'
import { cloneDeep } from 'es-toolkit/compat'
import { shallow } from 'zustand/shallow'
import { createWithEqualityFn } from 'zustand/traditional'
import { updateAppInfo } from '@/service/apps'
import { get as serviceGet } from '@/service/base'
type AppDetail = App & Partial<AppSSO>
@ -81,6 +83,46 @@ async function fetchAppDetail(appID: string | undefined) {
return appDetail
}
async function updateAppDetail(updatedDetail: {
appID: string
name: string
icon_type: AppIconType
icon: string
icon_background?: string
description: string
use_icon_as_answer_icon?: boolean
max_active_requests?: number | null
}) {
const appID = updatedDetail.appID
const currentDetails = useAppStore.getState().appDetails || {}
const currentDetail = cloneDeep(currentDetails[appID])
if (!currentDetail)
return
set(state => ({
appDetails: {
...state.appDetails,
[appID]: {
...currentDetail,
...updatedDetail,
},
},
}))
return updateAppInfo({
...updatedDetail,
appID,
}).catch(() => {
set(state => ({
appDetails: {
...state.appDetails,
[appID]: currentDetail,
},
}))
})
}
export const appStoreActions = {
fetchAppDetail,
updateAppDetail,
}