Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
276d3d10
Unverified
Commit
276d3d10
authored
Aug 24, 2023
by
Matri
Committed by
GitHub
Aug 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: apps loading issue (#994)
parent
f1362318
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
29 deletions
+22
-29
Apps.tsx
web/app/(commonLayout)/apps/Apps.tsx
+22
-29
No files found.
web/app/(commonLayout)/apps/Apps.tsx
View file @
276d3d10
'use client'
'use client'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
use
Callback
,
use
Effect
,
useRef
,
useState
}
from
'react'
import
{
useRouter
,
useSearchParams
}
from
'next/navigation'
import
{
useRouter
,
useSearchParams
}
from
'next/navigation'
import
useSWRInfinite
from
'swr/infinite'
import
useSWRInfinite
from
'swr/infinite'
import
{
debounce
}
from
'lodash-es'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
AppCard
from
'./AppCard'
import
AppCard
from
'./AppCard'
import
NewAppCard
from
'./NewAppCard'
import
NewAppCard
from
'./NewAppCard'
import
type
{
AppListResponse
}
from
'@/models/app'
import
type
{
AppListResponse
}
from
'@/models/app'
import
{
fetchAppList
}
from
'@/service/apps'
import
{
fetchAppList
}
from
'@/service/apps'
import
{
useAppContext
,
useSelector
}
from
'@/context/app-context'
import
{
useAppContext
}
from
'@/context/app-context'
import
{
NEED_REFRESH_APP_LIST_KEY
}
from
'@/config'
import
{
NEED_REFRESH_APP_LIST_KEY
}
from
'@/config'
import
{
ProviderEnum
}
from
'@/app/components/header/account-setting/model-page/declarations'
import
{
ProviderEnum
}
from
'@/app/components/header/account-setting/model-page/declarations'
import
Confirm
from
'@/app/components/base/confirm/common'
import
Confirm
from
'@/app/components/base/confirm/common'
...
@@ -24,15 +23,18 @@ const Apps = () => {
...
@@ -24,15 +23,18 @@ const Apps = () => {
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
isCurrentWorkspaceManager
}
=
useAppContext
()
const
{
isCurrentWorkspaceManager
}
=
useAppContext
()
const
{
data
,
isLoading
,
setSize
,
mutate
}
=
useSWRInfinite
(
getKey
,
fetchAppList
,
{
revalidateFirstPage
:
false
})
const
{
data
,
isLoading
,
setSize
,
mutate
}
=
useSWRInfinite
(
getKey
,
fetchAppList
,
{
revalidateFirstPage
:
false
})
const
loadingStateRef
=
useRef
(
false
)
const
anchorRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
pageContainerRef
=
useSelector
(
state
=>
state
.
pageContainerRef
)
const
anchorRef
=
useRef
<
HTMLAnchorElement
>
(
null
)
const
searchParams
=
useSearchParams
()
const
searchParams
=
useSearchParams
()
const
router
=
useRouter
()
const
router
=
useRouter
()
const
payProviderName
=
searchParams
.
get
(
'provider_name'
)
const
payProviderName
=
searchParams
.
get
(
'provider_name'
)
const
payStatus
=
searchParams
.
get
(
'payment_result'
)
const
payStatus
=
searchParams
.
get
(
'payment_result'
)
const
[
showPayStatusModal
,
setShowPayStatusModal
]
=
useState
(
false
)
const
[
showPayStatusModal
,
setShowPayStatusModal
]
=
useState
(
false
)
const
handleCancelShowPayStatusModal
=
useCallback
(()
=>
{
setShowPayStatusModal
(
false
)
router
.
replace
(
'/'
,
{
forceOptimisticNavigation
:
false
})
},
[
router
])
useEffect
(()
=>
{
useEffect
(()
=>
{
document
.
title
=
`
${
t
(
'app.title'
)}
- Dify`
document
.
title
=
`
${
t
(
'app.title'
)}
- Dify`
if
(
localStorage
.
getItem
(
NEED_REFRESH_APP_LIST_KEY
)
===
'1'
)
{
if
(
localStorage
.
getItem
(
NEED_REFRESH_APP_LIST_KEY
)
===
'1'
)
{
...
@@ -41,35 +43,24 @@ const Apps = () => {
...
@@ -41,35 +43,24 @@ const Apps = () => {
}
}
if
(
payProviderName
===
ProviderEnum
.
anthropic
&&
(
payStatus
===
'succeeded'
||
payStatus
===
'cancelled'
))
if
(
payProviderName
===
ProviderEnum
.
anthropic
&&
(
payStatus
===
'succeeded'
||
payStatus
===
'cancelled'
))
setShowPayStatusModal
(
true
)
setShowPayStatusModal
(
true
)
},
[])
},
[
mutate
,
payProviderName
,
payStatus
,
t
])
useEffect
(()
=>
{
useEffect
(()
=>
{
loadingStateRef
.
current
=
isLoading
let
observer
:
IntersectionObserver
|
undefined
},
[
isLoading
])
if
(
anchorRef
.
current
)
{
observer
=
new
IntersectionObserver
((
entries
)
=>
{
useEffect
(()
=>
{
if
(
entries
[
0
].
isIntersecting
)
const
onScroll
=
debounce
(()
=>
{
if
(
!
loadingStateRef
.
current
)
{
const
{
scrollTop
,
clientHeight
}
=
pageContainerRef
.
current
!
const
anchorOffset
=
anchorRef
.
current
!
.
offsetTop
if
(
anchorOffset
-
scrollTop
-
clientHeight
<
100
)
setSize
(
size
=>
size
+
1
)
setSize
(
size
=>
size
+
1
)
}
},
{
rootMargin
:
'100px'
})
},
50
)
observer
.
observe
(
anchorRef
.
current
)
}
pageContainerRef
.
current
?.
addEventListener
(
'scroll'
,
onScroll
)
return
()
=>
observer
?.
disconnect
()
return
()
=>
pageContainerRef
.
current
?.
removeEventListener
(
'scroll'
,
onScroll
)
},
[
isLoading
,
setSize
,
anchorRef
,
mutate
])
},
[])
const
handleCancelShowPayStatusModal
=
()
=>
{
setShowPayStatusModal
(
false
)
router
.
replace
(
'/'
,
{
forceOptimisticNavigation
:
false
})
}
return
(
return
(
<
nav
className=
'grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 grow shrink-0'
>
<
><
nav
className=
'grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 grow shrink-0'
>
{
isCurrentWorkspaceManager
{
isCurrentWorkspaceManager
&&
<
NewAppCard
ref=
{
anchorRef
}
onSuccess=
{
mutate
}
/>
}
&&
<
NewAppCard
onSuccess=
{
mutate
}
/>
}
{
data
?.
map
(({
data
:
apps
})
=>
apps
.
map
(
app
=>
(
{
data
?.
map
(({
data
:
apps
})
=>
apps
.
map
(
app
=>
(
<
AppCard
key=
{
app
.
id
}
app=
{
app
}
onRefresh=
{
mutate
}
/>
<
AppCard
key=
{
app
.
id
}
app=
{
app
}
onRefresh=
{
mutate
}
/>
)))
}
)))
}
...
@@ -95,6 +86,8 @@ const Apps = () => {
...
@@ -95,6 +86,8 @@ const Apps = () => {
)
)
}
}
</
nav
>
</
nav
>
<
div
ref=
{
anchorRef
}
className=
'h-0'
>
</
div
>
</>
)
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment