mirror of
https://github.com/ragestudio/comty.git
synced 2025-07-08 08:44:15 +00:00
Refactor app page to use component refs and metadata state
This commit is contained in:
parent
df88d69c3a
commit
e3d8d25391
@ -15,10 +15,9 @@ const AppPage = (props) => {
|
|||||||
useTotalWindowHeight(true)
|
useTotalWindowHeight(true)
|
||||||
|
|
||||||
const [loading, setLoading] = React.useState(true)
|
const [loading, setLoading] = React.useState(true)
|
||||||
|
const [appMetadata, setAppMetadata] = React.useState({})
|
||||||
const [customApp, setCustomApp] = React.useState({})
|
const [ctx, setCtx] = React.useState({})
|
||||||
const [extensionRef, setExtensionRef] = React.useState({})
|
const extensionRef = React.useRef(null)
|
||||||
const [Render, setRender] = React.useState(() => () => null)
|
|
||||||
|
|
||||||
async function loadApp() {
|
async function loadApp() {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@ -29,13 +28,30 @@ const AppPage = (props) => {
|
|||||||
throw new Error(`Extension with id ${id} not found`)
|
throw new Error(`Extension with id ${id} not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!extension.main.app.component) {
|
||||||
|
throw new Error(`Missing component for extension with id [${id}]`)
|
||||||
|
}
|
||||||
|
|
||||||
|
setAppMetadata({
|
||||||
|
title: extension.main.app.title,
|
||||||
|
description: extension.main.app.description,
|
||||||
|
icon: extension.main.app.icon,
|
||||||
|
})
|
||||||
|
|
||||||
if (typeof extension.main.app.onLoad === "function") {
|
if (typeof extension.main.app.onLoad === "function") {
|
||||||
await extension.main.app.onLoad()
|
await extension.main.app.onLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
setExtensionRef(extension)
|
if (typeof extension.main.app.component.onMount === "function") {
|
||||||
setCustomApp(extension.main.app)
|
await extension.main.app.component.onMount({
|
||||||
setRender(extension.main.app.renderComponent)
|
extension,
|
||||||
|
ctx,
|
||||||
|
setCtx,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// set to ref
|
||||||
|
extensionRef.current = extension
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@ -48,8 +64,8 @@ const AppPage = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div className="custom-app-page-loading">
|
<div className="custom-app-page-loading">
|
||||||
<div className="custom-app-page-loading-icon">
|
<div className="custom-app-page-loading-icon">
|
||||||
{customApp.icon && (
|
{appMetadata.icon && (
|
||||||
<Image src={customApp.icon} alt={customApp.name} />
|
<Image src={appMetadata.icon} alt={appMetadata.title} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -64,7 +80,11 @@ const AppPage = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div className="custom-app-page-render">
|
<div className="custom-app-page-render">
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<Render />
|
{React.createElement(extensionRef.current.main.app.component, {
|
||||||
|
extension: extensionRef.current,
|
||||||
|
ctx,
|
||||||
|
setCtx,
|
||||||
|
})}
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
border-radius: 24px;
|
// border-radius: 24px;
|
||||||
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user