Better async loading behavior

This commit is contained in:
Nick Gerleman
2023-10-19 22:36:48 -07:00
parent b4960085c6
commit 1acbd2e85a
3 changed files with 82 additions and 61 deletions

View File

@@ -5,19 +5,14 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
.PlaygroundContainer { .PlaygroundContainer {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-grow: 1; flex-grow: 1;
width: 100%; width: 100%;
} }
.Playground { .playground-background {
display: flex;
flex-grow: 1;
position: relative;
width: 100%;
overflow: hidden;
background: linear-gradient(-90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px), background: linear-gradient(-90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px),
linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px), linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
linear-gradient(-90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px), linear-gradient(-90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
@@ -41,6 +36,15 @@
100px 100px, 100px 100px, 100px 100px; 100px 100px, 100px 100px, 100px 100px;
} }
.Playground {
display: flex;
flex-grow: 1;
position: relative;
width: 100%;
overflow: hidden;
animation: playground-content-fade-in-frames 50ms ease-in;
}
.Playground > .YogaNode { .Playground > .YogaNode {
margin: auto; margin: auto;
position: static; position: static;
@@ -72,3 +76,12 @@
.ant-modal-content { .ant-modal-content {
overflow: hidden; overflow: hidden;
} }
@keyframes playground-content-fade-in-frames {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

View File

@@ -235,52 +235,58 @@ export default class Playground extends Component<Props, State> {
: null; : null;
const playground = ( const playground = (
<div <div className="playground-background">
className={`Playground ${this.props.renderSidebar ? '' : 'standalone'}`} <div
onMouseDown={this.onMouseDown} className={`Playground ${
style={{height, maxHeight: height}} this.props.renderSidebar ? '' : 'standalone'
ref={ref => { }`}
this._containerRef = ref; onMouseDown={this.onMouseDown}
}}> style={{height, maxHeight: height}}
<YogaNode ref={ref => {
layoutDefinition={layoutDefinition} this._containerRef = ref;
selectedNodePath={selectedNodePath} }}>
onClick={selectedNodePath => this.setState({selectedNodePath})} <YogaNode
onDoubleClick={this.onAdd} layoutDefinition={layoutDefinition}
direction={direction} selectedNodePath={selectedNodePath}
showGuides={this.props.showGuides} onClick={selectedNodePath => this.setState({selectedNodePath})}
/> onDoubleClick={this.onAdd}
{!this.props.renderSidebar && ( direction={direction}
<Sidebar> showGuides={this.props.showGuides}
{this.state.selectedNodePath ? ( />
<Editor {!this.props.renderSidebar && (
node={selectedNode} <Sidebar>
selectedNodeIsRoot={ {this.state.selectedNodePath ? (
selectedNodePath ? selectedNodePath.length === 0 : false <Editor
} node={selectedNode}
onChangeLayout={this.onChangeLayout} selectedNodeIsRoot={
// @ts-ignore selectedNodePath ? selectedNodePath.length === 0 : false
onChangeSetting={(key, value) => this.setState({[key]: value})} }
direction={direction} onChangeLayout={this.onChangeLayout}
onRemove={ // @ts-ignore
selectedNodePath && selectedNodePath.length > 0 onChangeSetting={(key, value) =>
? this.onRemove this.setState({[key]: value})
: undefined }
} direction={direction}
onAdd={ onRemove={
selectedNodePath && selectedNodePath && selectedNodePath.length > 0
selectedNodePath.length < this.props.maxDepth ? this.onRemove
? this.onAdd : undefined
: undefined }
} onAdd={
/> selectedNodePath &&
) : ( selectedNodePath.length < this.props.maxDepth
<div className="NoContent"> ? this.onAdd
Select a node to edit its properties : undefined
</div> }
)} />
</Sidebar> ) : (
)} <div className="NoContent">
Select a node to edit its properties
</div>
)}
</Sidebar>
)}
</div>
</div> </div>
); );

View File

@@ -38,15 +38,17 @@ const LazyPlayground = React.lazy(() => import('../components/Playground'));
function ClientPlayground() { function ClientPlayground() {
const fallback = <div className={styles.playgroundFallback} />; const fallback = <div className={styles.playgroundFallback} />;
return <BrowserOnly fallback={fallback}>
{() => (
<Suspense fallback={fallback}>
<LazyPlayground />
</Suspense>
)}
</BrowserOnly>;
}
return (
<BrowserOnly fallback={fallback}>
{() => (
<Suspense fallback={fallback}>
<LazyPlayground />
</Suspense>
)}
</BrowserOnly>
);
}
export default function Home(): JSX.Element { export default function Home(): JSX.Element {
const {siteConfig} = useDocusaurusContext(); const {siteConfig} = useDocusaurusContext();