mirror of https://github.com/langgenius/dify.git
improve: better popup blocker detection and type safety
- Add immediate popup blocker detection with user-friendly error message - Improve type safety by removing any types - Simplify logic flow in useAsyncWindowOpen hook Addresses code review suggestions
This commit is contained in:
parent
e95b7b57c9
commit
bac0513b8b
|
|
@ -223,8 +223,8 @@ const AppPublisher = ({
|
|||
|
||||
openAsync(
|
||||
async () => {
|
||||
const { installed_apps }: any = await fetchInstalledAppList(appDetail.id) || {}
|
||||
if (installed_apps?.length > 0)
|
||||
const { installed_apps }: { installed_apps?: { id: string }[] } = await fetchInstalledAppList(appDetail.id) || {}
|
||||
if (installed_apps && installed_apps.length > 0)
|
||||
return `${basePath}/explore/installed/${installed_apps[0].id}`
|
||||
throw new Error('No app found in Explore')
|
||||
},
|
||||
|
|
|
|||
|
|
@ -252,8 +252,8 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => {
|
|||
|
||||
openAsync(
|
||||
async () => {
|
||||
const { installed_apps }: any = await fetchInstalledAppList(app.id) || {}
|
||||
if (installed_apps?.length > 0)
|
||||
const { installed_apps }: { installed_apps?: { id: string }[] } = await fetchInstalledAppList(app.id) || {}
|
||||
if (installed_apps && installed_apps.length > 0)
|
||||
return `${basePath}/explore/installed/${installed_apps[0].id}`
|
||||
throw new Error('No app found in Explore')
|
||||
},
|
||||
|
|
|
|||
|
|
@ -24,10 +24,20 @@ export const useAsyncWindowOpen = () => {
|
|||
|
||||
const newWindow = window.open('', '_blank', windowFeatures)
|
||||
|
||||
if (!newWindow) {
|
||||
const error = new Error('Popup blocked by browser')
|
||||
onError?.(error)
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: 'Popup blocked. Please allow popups for this site.',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const url = await fetchUrl()
|
||||
|
||||
if (url && newWindow) {
|
||||
if (url) {
|
||||
newWindow.location.href = url
|
||||
onSuccess?.(url)
|
||||
|
||||
|
|
@ -39,8 +49,8 @@ export const useAsyncWindowOpen = () => {
|
|||
}
|
||||
}
|
||||
else {
|
||||
newWindow?.close()
|
||||
const error = new Error('Invalid URL or window was closed')
|
||||
newWindow.close()
|
||||
const error = new Error('Invalid URL received')
|
||||
onError?.(error)
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
|
|
@ -49,7 +59,7 @@ export const useAsyncWindowOpen = () => {
|
|||
}
|
||||
}
|
||||
catch (error) {
|
||||
newWindow?.close()
|
||||
newWindow.close()
|
||||
onError?.(error)
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
|
|
|
|||
Loading…
Reference in New Issue