2
0
mirror of https://github.com/lowdefy/lowdefy.git synced 2025-03-19 15:01:06 +08:00

fix: Replace progressBarDispatcher with process object.

This commit is contained in:
Gervwyk 2022-04-08 09:34:03 +02:00
parent 62265b593d
commit 9aff083310
4 changed files with 54 additions and 62 deletions
packages/server/lib/components

@ -19,7 +19,7 @@ import getContext from '@lowdefy/engine';
import MountEvents from './MountEvents.js';
const Context = ({ children, config, lowdefy, progressBarDispatcher }) => {
const Context = ({ children, config, lowdefy, progress }) => {
const context = getContext({ config, lowdefy });
return (
<MountEvents
@ -30,7 +30,7 @@ const Context = ({ children, config, lowdefy, progressBarDispatcher }) => {
await context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
name: 'onInit',
progress: () => {
progressBarDispatcher({
progress.dispatch({
type: 'increment',
});
},
@ -44,7 +44,7 @@ const Context = ({ children, config, lowdefy, progressBarDispatcher }) => {
context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
name: 'onInitAsync',
progress: () => {
progressBarDispatcher({
progress.dispatch({
type: 'increment',
});
},
@ -61,7 +61,7 @@ const Context = ({ children, config, lowdefy, progressBarDispatcher }) => {
await context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
name: 'onEnter',
progress: () => {
progressBarDispatcher({
progress.dispatch({
type: 'increment',
});
},
@ -72,12 +72,12 @@ const Context = ({ children, config, lowdefy, progressBarDispatcher }) => {
await context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
name: 'onEnterAsync', // TODO: Do we want this to happen in the background, as in not effecting progress bar?
progress: () => {
progressBarDispatcher({
progress.dispatch({
type: 'increment',
});
},
});
progressBarDispatcher({
progress.dispatch({
type: 'done',
});
};

@ -45,32 +45,30 @@ const Page = ({ lowdefy, pageConfig, rootConfig }) => {
id="page-loader"
ProgressBar={lowdefy._internal.blockComponents.ProgressBar}
lowdefy={lowdefy}
>
{(progressBarDispatcher) => (
<Context
config={pageConfig}
lowdefy={lowdefy}
progressBarDispatcher={progressBarDispatcher}
>
{(context, loading) => {
return (
<>
<Head
properties={context._internal.RootBlocks.map[pageConfig.id].eval.properties}
/>
<Block
block={context._internal.RootBlocks.map[pageConfig.id]}
Blocks={context._internal.RootBlocks}
context={context}
parentLoading={loading}
lowdefy={lowdefy}
/>
</>
);
}}
</Context>
)}
</ProgressBarController>
content={{
content: (progress) => (
<Context config={pageConfig} lowdefy={lowdefy} progress={progress}>
{(context, loading) => {
return (
<>
<Head
properties={context._internal.RootBlocks.map[pageConfig.id].eval.properties}
/>
<Block
block={context._internal.RootBlocks.map[pageConfig.id]}
Blocks={context._internal.RootBlocks}
context={context}
lowdefy={lowdefy}
parentLoading={loading}
progress={progress}
/>
</>
);
}}
</Context>
),
}}
/>
);
};

@ -46,7 +46,7 @@ const ProgressBarController = ({ id, ProgressBar, children, lowdefy }) => {
properties={{ ...state }}
user={lowdefy.user}
content={{
content: () => children(dispatch),
content: () => children({ state, dispatch }),
}}
/>
);

@ -14,12 +14,11 @@
limitations under the License.
*/
import React, { Suspense, useState } from 'react';
import React, { useState } from 'react';
import { ErrorBoundary } from '@lowdefy/block-utils';
import CategorySwitch from './CategorySwitch.js';
import LoadingBlock from './LoadingBlock.js';
import MountEvents from '../MountEvents.js';
const Block = ({ block, Blocks, context, isRoot, lowdefy, parentLoading }) => {
@ -27,33 +26,28 @@ const Block = ({ block, Blocks, context, isRoot, lowdefy, parentLoading }) => {
lowdefy._internal.updaters[block.id] = () => setUpdate(updates + 1);
return (
<ErrorBoundary>
<Suspense fallback={<LoadingBlock block={block} lowdefy={lowdefy} />}>
<MountEvents
context={context}
parentLoading={parentLoading}
triggerEvent={async () => {
await block.triggerEvent({ name: 'onMount' });
}}
triggerEventAsync={() => {
block.triggerEvent({ name: 'onMount' });
}}
>
{(loading) =>
loading ? (
<LoadingBlock block={block} lowdefy={lowdefy} />
) : (
<CategorySwitch
block={block}
Blocks={Blocks}
context={context}
isRoot={isRoot}
lowdefy={lowdefy}
updates={updates}
/>
)
}
</MountEvents>
</Suspense>
<MountEvents
context={context}
parentLoading={parentLoading}
triggerEvent={async () => {
await block.triggerEvent({ name: 'onMount' });
}}
triggerEventAsync={() => {
block.triggerEvent({ name: 'onMount' });
}}
>
{(loading) => (
<CategorySwitch
block={block}
Blocks={Blocks}
context={context}
isRoot={isRoot}
loading={loading}
lowdefy={lowdefy}
updates={updates}
/>
)}
</MountEvents>
</ErrorBoundary>
);
};