@@ -8,11 +8,15 @@ import { Document, Plus } from '@blueprintjs/icons';
88import React , { useCallback , useEffect , useRef } from 'react' ;
99import { useDispatch } from 'react-redux' ;
1010import Two from 'two.js' ;
11- import { useTernaryDarkMode } from 'usehooks-ts' ;
11+ import { useLocalStorage , useTernaryDarkMode } from 'usehooks-ts' ;
1212import { Activity , useActivitiesSelectedActivity } from '../activities/hooks' ;
13+ import { recentFileCount } from '../app/constants' ;
1314import { explorerCreateNewFile } from '../explorer/actions' ;
15+ import { UUID } from '../fileStorage' ;
16+ import { editorActivateFile } from './actions' ;
1417import { useI18n } from './i18n' ;
1518import logoSvg from './logo.svg' ;
19+ import { RecentFileMetadata } from '.' ;
1620
1721const defaultRotation = - Math . PI / 9 ; // radians
1822const rotationSpeedIncrement = 0.1 ; // radians per second
@@ -100,6 +104,7 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
100104
101105 const logo = two . load ( logoSvg , ( g ) => {
102106 g . center ( ) ;
107+
103108 two . add ( logo ) ;
104109 two . play ( ) ;
105110 } ) ;
@@ -111,7 +116,7 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
111116 } ) ;
112117
113118 logo . fill = fillColorRef . current ;
114- logo . scale = Math . min ( two . width , two . height ) / 90 ;
119+ logo . scale = Math . min ( two . width , two . height ) / 80 ;
115120 logo . rotation = stateRef . current . rotation ;
116121
117122 two . scene . position . x = two . width / 2 ;
@@ -169,9 +174,34 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
169174 dispatch ( explorerCreateNewFile ( ) ) ;
170175 } , [ dispatch , setSelectedActivity ] ) ;
171176
172- const handleOpenExplorer = useCallback ( ( ) => {
177+ //useCallback
178+ const handleOpenExplorer = ( uuid : UUID ) => {
173179 setSelectedActivity ( Activity . Explorer ) ;
174- } , [ setSelectedActivity ] ) ;
180+ dispatch ( editorActivateFile ( uuid ) ) ;
181+ } ;
182+
183+ const [ editorRecentFiles ] = useLocalStorage ( 'editor.recentFiles' , [ ] ) ;
184+ const getRecentFileShortCuts = ( ) => (
185+ < >
186+ { editorRecentFiles
187+ . slice ( 0 , recentFileCount )
188+ . map ( ( fitem : RecentFileMetadata ) => (
189+ < dl key = { fitem . uuid } >
190+ < dt >
191+ { i18n . translate ( 'welcome.openProject' , {
192+ fileName : fitem . path ,
193+ } ) }
194+ </ dt >
195+ < dd >
196+ < Button
197+ icon = { < Document /> }
198+ onClick = { ( ) => handleOpenExplorer ( fitem . uuid ) }
199+ />
200+ </ dd >
201+ </ dl >
202+ ) ) }
203+ </ >
204+ ) ;
175205
176206 return (
177207 < div
@@ -183,12 +213,7 @@ const Welcome: React.FunctionComponent<WelcomeProps> = ({ isVisible }) => {
183213 >
184214 < div className = "logo" ref = { elementRef } > </ div >
185215 < div className = "shortcuts" >
186- < dl >
187- < dt > { i18n . translate ( 'welcome.openProject' ) } </ dt >
188- < dd >
189- < Button icon = { < Document /> } onClick = { handleOpenExplorer } />
190- </ dd >
191- </ dl >
216+ { getRecentFileShortCuts ( ) }
192217 < dl >
193218 < dt > { i18n . translate ( 'welcome.newProject' ) } </ dt >
194219 < dd >
0 commit comments