-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(loading): merge github fetch with the loading bar (#6630)
This PR adds the loading stages to the loading bar screen and progress bar. Stages for GH import: 1. Loading Editor... 2. Fetching <repo name> 3. Parsing files 4. Fetching dependencies Stages for project load (we reverse the order in our project load): 1. Fetching dependencies 2. Parsing files If everything is validated correctly - it just shows the editor with the project ready to be worked on. If not - it shows an error modal (its UI was slightly changed in #6677 to better reflect errors). It also adds support for Dark mode. **Note:** - The new logic is almost entirely in [editor/src/components/editor/loading-screen.tsx](https://github.com/concrete-utopia/utopia/pull/6630/files#diff-5aa4d7e811e0bfb07a60910e517fe3a01cd270c9b4fd05132e513d939d69f769) - There is a jump in the progress bar since these are actually two DOM elements, one that is rendered before the React is loaded and a React component that replaces it after the React code is loaded. This jump will be fixed in a subsequent PR. - Currently the progress bar is "static" (advances by time and not stages). This will be changed in (the same) subsequent PR. <video src="https://github.com/user-attachments/assets/a6d52f3d-b27b-4110-be1e-a7f213f563ab"></video> **Manual Tests:** I hereby swear that: - [X] I opened a hydrogen project and it loaded - [X] I could navigate to various routes in Play mode
- Loading branch information
Showing
13 changed files
with
333 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
import React from 'react' | ||
import { Substores, useEditorState } from './store/store-hook' | ||
import { getImportOperationTextAsJsx } from './import-wizard/import-wizard-helpers' | ||
import { getTotalImportStatusAndResult } from '../../core/shared/import/import-operation-service' | ||
import type { TotalImportResult } from '../../core/shared/import/import-operation-types' | ||
import type { Theme } from '../../uuiui' | ||
import { useColorTheme } from '../../uuiui' | ||
import { getCurrentTheme } from './store/editor-state' | ||
import ReactDOM from 'react-dom' | ||
|
||
export function LoadingEditorComponent() { | ||
const colorTheme = useColorTheme() | ||
|
||
const currentTheme: Theme = useEditorState( | ||
Substores.theme, | ||
(store) => getCurrentTheme(store.userState), | ||
'currentTheme', | ||
) | ||
|
||
const importState = useEditorState( | ||
Substores.restOfEditor, | ||
(store) => store.editor.importState, | ||
'LoadingEditorComponent importState', | ||
) | ||
|
||
const githubRepo = useEditorState( | ||
Substores.userState, | ||
(store) => store.userState.githubState.gitRepoToLoad, | ||
'LoadingEditorComponent githubRepoToLoad', | ||
) | ||
|
||
const totalImportResult: TotalImportResult = React.useMemo( | ||
() => getTotalImportStatusAndResult(importState), | ||
[importState], | ||
) | ||
|
||
const projectId = useEditorState( | ||
Substores.restOfEditor, | ||
(store) => store.editor.id, | ||
'LoadingEditorComponent projectId', | ||
) | ||
|
||
const cleared = React.useRef(false) | ||
|
||
const currentOperationToShow: { | ||
text: React.ReactNode | ||
id: string | ||
timeDone: number | null | undefined | ||
timeStarted: number | null | undefined | ||
} | null = React.useMemo(() => { | ||
if (totalImportResult.importStatus.status == 'not-started') { | ||
if (projectId == null) { | ||
return { | ||
text: 'Loading Editor...', | ||
id: 'loading-editor', | ||
timeDone: null, | ||
timeStarted: null, | ||
} | ||
} else { | ||
return { | ||
text: `Parsing files`, | ||
id: 'parseFiles', | ||
timeDone: null, | ||
timeStarted: null, | ||
} | ||
} | ||
} | ||
for (const op of importState.importOperations) { | ||
if (op?.children?.length == 0 || op.type == 'refreshDependencies') { | ||
if (op.timeStarted != null && op.timeDone == null) { | ||
return { | ||
text: getImportOperationTextAsJsx(op), | ||
id: op.id ?? op.type, | ||
timeDone: op.timeDone, | ||
timeStarted: op.timeStarted, | ||
} | ||
} | ||
} | ||
if (op.type !== 'refreshDependencies') { | ||
for (const child of op.children ?? []) { | ||
if (child.timeStarted != null && child.timeDone == null) { | ||
return { | ||
text: getImportOperationTextAsJsx(child), | ||
id: child.id ?? child.type, | ||
timeDone: child.timeDone, | ||
timeStarted: child.timeStarted, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
text: 'Loading Editor...', | ||
id: 'loading-editor', | ||
timeDone: null, | ||
timeStarted: null, | ||
} | ||
}, [totalImportResult, importState.importOperations, projectId]) | ||
|
||
const shouldBeCleared = React.useMemo(() => { | ||
return ( | ||
cleared.current || | ||
(totalImportResult.importStatus.status == 'done' && | ||
(githubRepo == null || totalImportResult.result == 'criticalError')) || | ||
totalImportResult.importStatus.status == 'paused' | ||
) | ||
}, [totalImportResult, githubRepo]) | ||
|
||
React.useEffect(() => { | ||
if (shouldBeCleared) { | ||
const loadingScreenWrapper = document.getElementById('loading-screen-wrapper') | ||
if (loadingScreenWrapper != null) { | ||
loadingScreenWrapper.remove() | ||
} | ||
} | ||
}, [shouldBeCleared]) | ||
|
||
const portal = React.useRef(document.getElementById('loading-screen-progress-bar-portal')).current | ||
const hasMounted = React.useRef(false) | ||
if (portal == null) { | ||
return null | ||
} | ||
|
||
if (shouldBeCleared) { | ||
cleared.current = true | ||
return null | ||
} | ||
|
||
if (!hasMounted.current) { | ||
portal.innerHTML = '' | ||
hasMounted.current = true | ||
} | ||
|
||
const themeStyle = | ||
currentTheme === 'dark' | ||
? ` | ||
.editor-loading-screen { background-color: ${colorTheme.bg6.value} } | ||
.utopia-logo-pyramid.light { display: none; } | ||
.utopia-logo-pyramid.dark { display: block; } | ||
` | ||
: '' | ||
|
||
return ReactDOM.createPortal( | ||
<React.Fragment> | ||
<style>{themeStyle}</style> | ||
<div className='progress-bar-shell' style={{ borderColor: colorTheme.fg0.value }}> | ||
<div | ||
className='progress-bar-progress animation-progress' | ||
style={{ | ||
transform: 'translateX(-180px)', | ||
animationName: 'animation-keyframes-2', | ||
backgroundColor: colorTheme.fg0.value, | ||
}} | ||
></div> | ||
</div> | ||
<div> | ||
<ul className='loading-screen-import-operations'> | ||
{currentOperationToShow != null ? ( | ||
<li | ||
style={{ | ||
listStyle: 'none', | ||
color: colorTheme.fg0.value, | ||
}} | ||
key={currentOperationToShow.id} | ||
> | ||
{currentOperationToShow.text} | ||
</li> | ||
) : null} | ||
</ul> | ||
</div> | ||
</React.Fragment>, | ||
portal, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.