Skip to content

Commit c53d685

Browse files
authored
feat(onboarding-ui): create LaunchingWorkspace page (#666)
* feat(onboarding-ui): create LaunchingWorkspace page * feat(onboarding-ui): refactor to single responsibility LoaderPage * feat(onboarding-ui): remove unused property
1 parent e746cfb commit c53d685

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ReactDOM from 'react-dom';
2+
3+
import LoaderPage from './LoaderPage';
4+
5+
const subtitles = [
6+
'Bringing rocket to launch position',
7+
'Loading rocket propellant',
8+
'Performing final go/no go poll with flight crew',
9+
'All systems nominal, switching to internal computer',
10+
'Beginning countdown, 5...4...3...2...1',
11+
'Transitioning to liftoff',
12+
];
13+
14+
it('renders without crashing', () => {
15+
const div = document.createElement('div');
16+
ReactDOM.render(
17+
<LoaderPage title='Kapai' subtitles={subtitles} isReady={false} />,
18+
div
19+
);
20+
ReactDOM.unmountComponentAtNode(div);
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Story, Meta } from '@storybook/react';
2+
import type { ComponentProps } from 'react';
3+
4+
import LoaderPage from './LoaderPage';
5+
6+
const subtitles = [
7+
'Bringing rocket to launch position1 🚀',
8+
'Loading rocket propellant 🚀',
9+
'Performing final go/no go poll with flight crew 🚀',
10+
'All systems nominal, switching to internal computer 🚀',
11+
'Beginning countdown, 5...4...3...2...1 🚀',
12+
'Transitioning to liftoff 🚀',
13+
];
14+
15+
type Args = ComponentProps<typeof LoaderPage>;
16+
17+
export default {
18+
title: 'pages/LoaderPage',
19+
component: LoaderPage,
20+
parameters: {
21+
actions: { argTypesRegex: '^on.*' },
22+
layout: 'fullscreen',
23+
},
24+
args: {
25+
title: 'Launching Kapai...',
26+
subtitles,
27+
isReady: false,
28+
loadingSeconds: 15,
29+
},
30+
} as Meta<Args>;
31+
32+
export const _LoaderPage: Story<Args> = (args) => <LoaderPage {...args} />;
33+
_LoaderPage.storyName = 'LoaderPage';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Box, Margins, ProgressBar } from '@rocket.chat/fuselage';
2+
import type { ReactElement } from 'react';
3+
import { useEffect, useState } from 'react';
4+
5+
import BackgroundLayer from '../../common/BackgroundLayer';
6+
import { OnboardingLogo } from '../../common/OnboardingLogo';
7+
8+
type LoaderPageProps = {
9+
title: string;
10+
subtitles: string[];
11+
isReady: boolean;
12+
loadingSeconds?: number;
13+
};
14+
15+
const LoaderPage = ({
16+
title,
17+
subtitles,
18+
isReady = false,
19+
loadingSeconds = 90,
20+
}: LoaderPageProps): ReactElement => {
21+
const timeFraction = 100 / subtitles.length;
22+
23+
const [percentage, setPercentage] = useState(0);
24+
const [subtitleIndex, setSubtitleIndex] = useState(0);
25+
26+
const progressHandler = () => {
27+
const interval = (loadingSeconds * 1000) / 100;
28+
setInterval(() => {
29+
setPercentage((prev) => (prev === 99 ? 99 : prev + 1));
30+
}, interval);
31+
};
32+
33+
useEffect(() => {
34+
if (isReady) setPercentage(100);
35+
else progressHandler();
36+
}, [isReady]);
37+
38+
useEffect(() => {
39+
// Change subtitle according to percentage
40+
const index = Math.floor(percentage / timeFraction);
41+
if (index !== subtitleIndex) setSubtitleIndex(index);
42+
}, [percentage]);
43+
44+
return (
45+
<BackgroundLayer>
46+
<Box
47+
display='flex'
48+
flexDirection='column'
49+
alignItems='center'
50+
textAlign='center'
51+
width='100%'
52+
maxWidth={768}
53+
paddingBlock={32}
54+
paddingInline={16}
55+
>
56+
<Margins blockEnd={32}>
57+
<OnboardingLogo />
58+
59+
<Box fontScale='hero'>{title}</Box>
60+
61+
<Box fontScale='p1b'>{subtitles[subtitleIndex]}</Box>
62+
63+
<ProgressBar barColor='#1D74F5' percentage={percentage} />
64+
</Margins>
65+
</Box>
66+
</BackgroundLayer>
67+
);
68+
};
69+
70+
export default LoaderPage;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './LoaderPage';

0 commit comments

Comments
 (0)