|
1 | 1 | // SPDX-License-Identifier: MIT |
2 | | -// Copyright (c) 2022-2023 The Pybricks Authors |
| 2 | +// Copyright (c) 2022-2024 The Pybricks Authors |
3 | 3 |
|
4 | 4 | // welcome screen that is shown when no editor is open. |
5 | 5 |
|
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'; |
8 | 10 | import Two from 'two.js'; |
9 | 11 | import { useTernaryDarkMode } from 'usehooks-ts'; |
| 12 | +import { Activity, useActivitiesSelectedActivity } from '../activities/hooks'; |
| 13 | +import { explorerCreateNewFile } from '../explorer/actions'; |
10 | 14 | import logoSvg from './logo.svg'; |
11 | 15 |
|
12 | 16 | const defaultRotation = -Math.PI / 9; // radians |
@@ -61,6 +65,7 @@ type WelcomeProps = { |
61 | 65 | }; |
62 | 66 |
|
63 | 67 | const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => { |
| 68 | + const dispatch = useDispatch(); |
64 | 69 | const stateRef = useRef<State>({ |
65 | 70 | rotation: defaultRotation, |
66 | 71 | rotationSpeed: 0, |
@@ -104,7 +109,7 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => { |
104 | 109 | }); |
105 | 110 |
|
106 | 111 | logo.fill = fillColorRef.current; |
107 | | - logo.scale = Math.min(two.width, two.height) / 80; |
| 112 | + logo.scale = Math.min(two.width, two.height) / 90; |
108 | 113 | logo.rotation = stateRef.current.rotation; |
109 | 114 |
|
110 | 115 | two.scene.position.x = two.width / 2; |
@@ -156,15 +161,40 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => { |
156 | 161 | }; |
157 | 162 | }, [isVisible]); |
158 | 163 |
|
| 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 | + |
159 | 174 | return ( |
160 | 175 | <div |
161 | 176 | className="pb-editor-welcome" |
162 | | - ref={elementRef} |
163 | 177 | onContextMenuCapture={(e) => { |
164 | 178 | e.stopPropagation(); |
165 | 179 | e.preventDefault(); |
166 | 180 | }} |
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> |
168 | 198 | ); |
169 | 199 | }; |
170 | 200 |
|
|
0 commit comments