1- import React , { useRef , useState } from 'react' ;
1+ import React from 'react' ;
22import classNames from 'classnames' ;
33import PropTypes from 'prop-types' ;
44import { useTranslation } from 'react-i18next' ;
55import { useDispatch , useSelector } from 'react-redux' ;
66import { Link } from 'react-router-dom' ;
7- import {
8- hideEditProjectName ,
9- showEditProjectName
10- } from '../../actions/project' ;
117import {
128 openPreferences ,
139 startAccessibleSketch ,
@@ -19,12 +15,11 @@ import {
1915 setGridOutput ,
2016 setTextOutput
2117} from '../../actions/preferences' ;
22- import { useSketchActions } from '../../hooks' ;
2318
2419import PlayIcon from '../../../../images/play.svg' ;
2520import StopIcon from '../../../../images/stop.svg' ;
2621import PreferencesIcon from '../../../../images/preferences.svg' ;
27- import EditProjectNameIcon from '../../../../images/pencil.svg ' ;
22+ import ProjectName from './ProjectName ' ;
2823
2924const Toolbar = ( props ) => {
3025 const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector (
@@ -35,34 +30,6 @@ const Toolbar = (props) => {
3530 const dispatch = useDispatch ( ) ;
3631
3732 const { t } = useTranslation ( ) ;
38- const { changeSketchName, canEditProjectName } = useSketchActions ( ) ;
39-
40- const projectNameInputRef = useRef ( ) ;
41- const [ nameInputValue , setNameInputValue ] = useState ( project . name ) ;
42-
43- function handleKeyPress ( event ) {
44- if ( event . key === 'Enter' ) {
45- dispatch ( hideEditProjectName ( ) ) ;
46- projectNameInputRef . current ?. blur ( ) ;
47- }
48- }
49-
50- function handleProjectNameClick ( ) {
51- if ( canEditProjectName ) {
52- dispatch ( showEditProjectName ( ) ) ;
53- setTimeout ( ( ) => {
54- projectNameInputRef . current ?. focus ( ) ;
55- } , 140 ) ;
56- }
57- }
58-
59- function handleProjectNameSave ( ) {
60- const newName = nameInputValue ;
61- if ( newName . length > 0 ) {
62- dispatch ( hideEditProjectName ( ) ) ;
63- changeSketchName ( newName ) ;
64- }
65- }
6633
6734 const playButtonClass = classNames ( {
6835 'toolbar__play-button' : true ,
@@ -76,10 +43,6 @@ const Toolbar = (props) => {
7643 'toolbar__preferences-button' : true ,
7744 'toolbar__preferences-button--selected' : preferencesIsVisible
7845 } ) ;
79- const nameContainerClass = classNames ( {
80- 'toolbar__project-name-container' : true ,
81- 'toolbar__project-name-container--editing' : project . isEditingName
82- } ) ;
8346
8447 return (
8548 < div className = "toolbar" >
@@ -130,34 +93,8 @@ const Toolbar = (props) => {
13093 { t ( 'Toolbar.Auto-refresh' ) }
13194 </ label >
13295 </ div >
133- < div className = { nameContainerClass } >
134- < button
135- className = "toolbar__project-name"
136- onClick = { handleProjectNameClick }
137- disabled = { ! canEditProjectName }
138- aria-label = { t ( 'Toolbar.EditSketchARIA' ) }
139- >
140- < span > { project . name } </ span >
141- { canEditProjectName && (
142- < EditProjectNameIcon
143- className = "toolbar__edit-name-button"
144- focusable = "false"
145- aria-hidden = "true"
146- />
147- ) }
148- </ button >
149- < input
150- type = "text"
151- maxLength = "128"
152- className = "toolbar__project-name-input"
153- aria-label = { t ( 'Toolbar.NewSketchNameARIA' ) }
154- disabled = { ! canEditProjectName }
155- ref = { projectNameInputRef }
156- value = { nameInputValue }
157- onChange = { ( e ) => setNameInputValue ( e . target . value ) }
158- onBlur = { handleProjectNameSave }
159- onKeyPress = { handleKeyPress }
160- />
96+ < div className = "toolbar__project-name-container" >
97+ < ProjectName />
16198 { ( ( ) => {
16299 if ( project . owner ) {
163100 return (
0 commit comments