Skip to content

Commit 335b442

Browse files
committed
feat: improve welcome screen ux
1 parent bf44cf5 commit 335b442

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

src/editor/Welcome.tsx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2022-2023 The Pybricks Authors
2+
// Copyright (c) 2022-2024 The Pybricks Authors
33

44
// welcome screen that is shown when no editor is open.
55

6-
import { Colors } from '@blueprintjs/core';
7-
import React, { useEffect, useRef } from 'react';
6+
import { Button, Colors } from '@blueprintjs/core';
7+
import { Document, Plus } from '@blueprintjs/icons';
8+
import React, { useCallback, useEffect, useRef } from 'react';
9+
import { useDispatch } from 'react-redux';
810
import Two from 'two.js';
911
import { useTernaryDarkMode } from 'usehooks-ts';
12+
import { Activity, useActivitiesSelectedActivity } from '../activities/hooks';
13+
import { explorerCreateNewFile } from '../explorer/actions';
1014
import logoSvg from './logo.svg';
1115

1216
const defaultRotation = -Math.PI / 9; // radians
@@ -61,6 +65,7 @@ type WelcomeProps = {
6165
};
6266

6367
const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
68+
const dispatch = useDispatch();
6469
const stateRef = useRef<State>({
6570
rotation: defaultRotation,
6671
rotationSpeed: 0,
@@ -104,7 +109,7 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
104109
});
105110

106111
logo.fill = fillColorRef.current;
107-
logo.scale = Math.min(two.width, two.height) / 80;
112+
logo.scale = Math.min(two.width, two.height) / 90;
108113
logo.rotation = stateRef.current.rotation;
109114

110115
two.scene.position.x = two.width / 2;
@@ -156,15 +161,40 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
156161
};
157162
}, [isVisible]);
158163

164+
const [, setSelectedActivity] = useActivitiesSelectedActivity();
165+
const handleOpenNewProject = useCallback(() => {
166+
setSelectedActivity(Activity.Explorer);
167+
dispatch(explorerCreateNewFile());
168+
}, [dispatch, setSelectedActivity]);
169+
170+
const handleOpenExplorer = useCallback(() => {
171+
setSelectedActivity(Activity.Explorer);
172+
}, [setSelectedActivity]);
173+
159174
return (
160175
<div
161176
className="pb-editor-welcome"
162-
ref={elementRef}
163177
onContextMenuCapture={(e) => {
164178
e.stopPropagation();
165179
e.preventDefault();
166180
}}
167-
/>
181+
>
182+
<div className="logo" ref={elementRef}></div>
183+
<div className="shortcuts">
184+
<dl>
185+
<dt>Open existing project</dt>
186+
<dd>
187+
<Button icon={<Document />} onClick={handleOpenExplorer} />
188+
</dd>
189+
</dl>
190+
<dl>
191+
<dt>Open a new project</dt>
192+
<dd>
193+
<Button icon={<Plus />} onClick={handleOpenNewProject} />
194+
</dd>
195+
</dl>
196+
</div>
197+
</div>
168198
);
169199
};
170200

src/editor/editor.scss

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,56 @@
6363
flex: 1 1 auto;
6464
}
6565

66+
.pb-editor-tabpanel.pb-empty {
67+
display: flex;
68+
justify-content: space-around;
69+
}
70+
6671
&-welcome {
6772
display: none;
68-
6973
.pb-editor-tabpanel.pb-empty > & {
70-
display: block;
74+
display: flex;
75+
flex-direction: column;
76+
justify-content: center;
77+
align-items: center;
78+
79+
// display: block;
7180
width: 100%;
7281
height: 100%;
82+
// max-width: 290px;
83+
84+
.logo {
85+
width: 100%;
86+
height: 100%;
87+
position: absolute;
88+
top: -2%;
89+
90+
svg {
91+
overflow: visible !important;
92+
}
93+
}
94+
.shortcuts {
95+
position: relative;
96+
top: +6%;
97+
98+
border-collapse: separate;
99+
border-spacing: 11px 17px;
100+
dl {
101+
display: table-row;
102+
opacity: 0.8;
103+
}
104+
dt,
105+
dd {
106+
display: table-cell;
107+
vertical-align: middle;
108+
}
109+
dd {
110+
text-align: left;
111+
}
112+
dt {
113+
text-align: right;
114+
}
115+
}
73116
}
74117
}
75118

0 commit comments

Comments
 (0)