mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
fix app list cache
This commit is contained in:
parent
ccb67bffc4
commit
88ef220d4d
@ -46,6 +46,7 @@ const Apps = () => {
|
|||||||
const { isCurrentWorkspaceManager } = useAppContext()
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const [activeTab, setActiveTab] = useTabSearchParams({
|
const [activeTab, setActiveTab] = useTabSearchParams({
|
||||||
defaultTab: 'all',
|
defaultTab: 'all',
|
||||||
|
disableSearchParams: true, // use search params will distroy app list mutation
|
||||||
})
|
})
|
||||||
const [keywords, setKeywords] = useState('')
|
const [keywords, setKeywords] = useState('')
|
||||||
const [searchKeywords, setSearchKeywords] = useState('')
|
const [searchKeywords, setSearchKeywords] = useState('')
|
||||||
|
|||||||
@ -10,7 +10,7 @@ type CreateAppDialogProps = {
|
|||||||
onClose: () => void
|
onClose: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateAppTemplateDialog = ({ show, onClose }: CreateAppDialogProps) => {
|
const CreateAppTemplateDialog = ({ show, onSuccess, onClose }: CreateAppDialogProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -22,7 +22,10 @@ const CreateAppTemplateDialog = ({ show, onClose }: CreateAppDialogProps) => {
|
|||||||
{/* template list */}
|
{/* template list */}
|
||||||
<div className='grow flex flex-col h-full bg-gray-100'>
|
<div className='grow flex flex-col h-full bg-gray-100'>
|
||||||
<div className='shrink-0 pl-8 pr-6 pt-6 pb-3 bg-gray-100 rounded-se-xl text-xl leading-[30px] font-semibold text-gray-900 z-10'>{t('app.newApp.startFromTemplate')}</div>
|
<div className='shrink-0 pl-8 pr-6 pt-6 pb-3 bg-gray-100 rounded-se-xl text-xl leading-[30px] font-semibold text-gray-900 z-10'>{t('app.newApp.startFromTemplate')}</div>
|
||||||
<AppList pageType={PageType.CREATE} />
|
<AppList onSuccess={() => {
|
||||||
|
onSuccess()
|
||||||
|
onClose()
|
||||||
|
}} pageType={PageType.CREATE} />
|
||||||
</div>
|
</div>
|
||||||
<div className='absolute right-6 top-6 p-2 cursor-pointer z-20' onClick={onClose}>
|
<div className='absolute right-6 top-6 p-2 cursor-pointer z-20' onClick={onClose}>
|
||||||
<XClose className='w-4 h-4 text-gray-500' />
|
<XClose className='w-4 h-4 text-gray-500' />
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import { AiText, ChatBot, CuteRobote } from '@/app/components/base/icons/src/ven
|
|||||||
import { HelpCircle, XClose } from '@/app/components/base/icons/src/vender/line/general'
|
import { HelpCircle, XClose } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
import { Route } from '@/app/components/base/icons/src/vender/solid/mapsAndTravel'
|
import { Route } from '@/app/components/base/icons/src/vender/solid/mapsAndTravel'
|
||||||
import TooltipPlus from '@/app/components/base/tooltip-plus'
|
import TooltipPlus from '@/app/components/base/tooltip-plus'
|
||||||
|
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||||
import { getRedirection } from '@/utils/app-redirection'
|
import { getRedirection } from '@/utils/app-redirection'
|
||||||
|
|
||||||
type CreateAppDialogProps = {
|
type CreateAppDialogProps = {
|
||||||
@ -70,6 +71,7 @@ const CreateAppModal = ({ show, onSuccess, onClose }: CreateAppDialogProps) => {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
onClose()
|
onClose()
|
||||||
mutateApps()
|
mutateApps()
|
||||||
|
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
|
||||||
getRedirection(isCurrentWorkspaceManager, app, push)
|
getRedirection(isCurrentWorkspaceManager, app, push)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import { getRedirection } from '@/utils/app-redirection'
|
|||||||
|
|
||||||
type AppsProps = {
|
type AppsProps = {
|
||||||
pageType?: PageType
|
pageType?: PageType
|
||||||
|
onSuccess?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PageType {
|
export enum PageType {
|
||||||
@ -34,6 +35,7 @@ export enum PageType {
|
|||||||
|
|
||||||
const Apps = ({
|
const Apps = ({
|
||||||
pageType = PageType.EXPLORE,
|
pageType = PageType.EXPLORE,
|
||||||
|
onSuccess,
|
||||||
}: AppsProps) => {
|
}: AppsProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { isCurrentWorkspaceManager } = useAppContext()
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
@ -111,6 +113,8 @@ const Apps = ({
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('app.newApp.appCreated'),
|
message: t('app.newApp.appCreated'),
|
||||||
})
|
})
|
||||||
|
if (onSuccess)
|
||||||
|
onSuccess()
|
||||||
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
|
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
|
||||||
getRedirection(isCurrentWorkspaceManager, app, push)
|
getRedirection(isCurrentWorkspaceManager, app, push)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,22 @@ import type { AppListResponse } from '@/models/app'
|
|||||||
import { useAppContext } from '@/context/app-context'
|
import { useAppContext } from '@/context/app-context'
|
||||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||||
|
|
||||||
const getKey = (pageIndex: number, previousPageData: AppListResponse) => {
|
const getKey = (
|
||||||
if (!pageIndex || previousPageData.has_more)
|
pageIndex: number,
|
||||||
return { url: 'apps', params: { page: pageIndex + 1, limit: 30 } }
|
previousPageData: AppListResponse,
|
||||||
|
activeTab: string,
|
||||||
|
keywords: string,
|
||||||
|
) => {
|
||||||
|
if (!pageIndex || previousPageData.has_more) {
|
||||||
|
const params: any = { url: 'apps', params: { page: pageIndex + 1, limit: 30, name: keywords } }
|
||||||
|
|
||||||
|
if (activeTab !== 'all')
|
||||||
|
params.params.mode = activeTab
|
||||||
|
else
|
||||||
|
delete params.params.mode
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +46,13 @@ const AppNav = () => {
|
|||||||
const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(false)
|
const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(false)
|
||||||
const [navItems, setNavItems] = useState<NavItem[]>([])
|
const [navItems, setNavItems] = useState<NavItem[]>([])
|
||||||
|
|
||||||
const { data: appsData, setSize } = useSWRInfinite(appId ? getKey : () => null, fetchAppList, { revalidateFirstPage: false })
|
const { data: appsData, setSize, mutate } = useSWRInfinite(
|
||||||
|
appId
|
||||||
|
? (pageIndex: number, previousPageData: AppListResponse) => getKey(pageIndex, previousPageData, 'all', '')
|
||||||
|
: () => null,
|
||||||
|
fetchAppList,
|
||||||
|
{ revalidateFirstPage: false },
|
||||||
|
)
|
||||||
|
|
||||||
const handleLoadmore = useCallback(() => {
|
const handleLoadmore = useCallback(() => {
|
||||||
setSize(size => size + 1)
|
setSize(size => size + 1)
|
||||||
@ -105,17 +124,17 @@ const AppNav = () => {
|
|||||||
<CreateAppModal
|
<CreateAppModal
|
||||||
show={showNewAppDialog}
|
show={showNewAppDialog}
|
||||||
onClose={() => setShowNewAppDialog(false)}
|
onClose={() => setShowNewAppDialog(false)}
|
||||||
onSuccess={() => {}}
|
onSuccess={() => mutate()}
|
||||||
/>
|
/>
|
||||||
<CreateAppTemplateDialog
|
<CreateAppTemplateDialog
|
||||||
show={showNewAppTemplateDialog}
|
show={showNewAppTemplateDialog}
|
||||||
onClose={() => setShowNewAppTemplateDialog(false)}
|
onClose={() => setShowNewAppTemplateDialog(false)}
|
||||||
onSuccess={() => {}}
|
onSuccess={() => mutate()}
|
||||||
/>
|
/>
|
||||||
<CreateFromDSLModal
|
<CreateFromDSLModal
|
||||||
show={showCreateFromDSLModal}
|
show={showCreateFromDSLModal}
|
||||||
onClose={() => setShowCreateFromDSLModal(false)}
|
onClose={() => setShowCreateFromDSLModal(false)}
|
||||||
onSuccess={() => {}}
|
onSuccess={() => mutate()}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user