perf: use component to handle webapp info fetch, authorization
parent
e4b6c33bdd
commit
513af98729
@ -1,16 +1,18 @@
|
|||||||
import type { FC } from 'react'
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Main from '@/app/components/explore/installed-app'
|
import Main from '@/app/components/explore/installed-app'
|
||||||
|
|
||||||
export type IInstalledAppProps = {
|
export type IInstalledAppProps = {
|
||||||
params: Promise<{
|
params: {
|
||||||
appId: string
|
appId: string
|
||||||
}>
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const InstalledApp: FC<IInstalledAppProps> = async ({ params }) => {
|
// Using Next.js page convention for async server components
|
||||||
|
async function InstalledApp({ params }: IInstalledAppProps) {
|
||||||
|
const appId = (await params).appId
|
||||||
return (
|
return (
|
||||||
<Main id={(await params).appId} />
|
<Main id={appId} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default React.memo(InstalledApp)
|
|
||||||
|
export default InstalledApp
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||||
|
import { AccessMode } from '@/models/access-control'
|
||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { getAppAccessModeByAppId } from './explore'
|
||||||
|
import { fetchAppMeta, fetchAppParams } from './share'
|
||||||
|
|
||||||
|
const NAME_SPACE = 'explore'
|
||||||
|
|
||||||
|
export const useGetInstalledAppAccessModeByAppId = (appId: string | null) => {
|
||||||
|
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [NAME_SPACE, 'appAccessMode', appId],
|
||||||
|
queryFn: () => {
|
||||||
|
if (systemFeatures.webapp_auth.enabled === false) {
|
||||||
|
return {
|
||||||
|
accessMode: AccessMode.PUBLIC,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!appId || appId.length === 0)
|
||||||
|
return Promise.reject(new Error('App code is required to get access mode'))
|
||||||
|
|
||||||
|
return getAppAccessModeByAppId(appId)
|
||||||
|
},
|
||||||
|
enabled: !!appId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useGetInstalledAppParams = (appId: string | null) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [NAME_SPACE, 'appParams', appId],
|
||||||
|
queryFn: () => {
|
||||||
|
if (!appId || appId.length === 0)
|
||||||
|
return Promise.reject(new Error('App ID is required to get app params'))
|
||||||
|
return fetchAppParams(true, appId)
|
||||||
|
},
|
||||||
|
enabled: !!appId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useGetInstalledAppMeta = (appId: string | null) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [NAME_SPACE, 'appMeta', appId],
|
||||||
|
queryFn: () => {
|
||||||
|
if (!appId || appId.length === 0)
|
||||||
|
return Promise.reject(new Error('App ID is required to get app meta'))
|
||||||
|
return fetchAppMeta(true, appId)
|
||||||
|
},
|
||||||
|
enabled: !!appId,
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue