Skip to content

Commit

Permalink
move ProjectName to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
lindapaiste committed Aug 13, 2023
1 parent aa3b454 commit a49f834
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
28 changes: 28 additions & 0 deletions client/modules/IDE/components/Header/ProjectName.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { useSketchActions } from '../../hooks';
import { selectProjectName } from '../../selectors/project';
import EditableInput from '../EditableInput';

export default function ProjectName() {
const { t } = useTranslation();

const { changeSketchName, canEditProjectName } = useSketchActions();

const projectName = useSelector(selectProjectName);

return (
<EditableInput
value={projectName}
disabled={!canEditProjectName}
aria-label={t('Toolbar.EditSketchARIA')}
inputProps={{
maxLength: 128,
'aria-label': t('Toolbar.NewSketchNameARIA')
}}
validate={(text) => text.trim().length > 0}
onChange={changeSketchName}
/>
);
}
16 changes: 2 additions & 14 deletions client/modules/IDE/components/Header/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import {
setGridOutput,
setTextOutput
} from '../../actions/preferences';
import { useSketchActions } from '../../hooks';

import PlayIcon from '../../../../images/play.svg';
import StopIcon from '../../../../images/stop.svg';
import PreferencesIcon from '../../../../images/preferences.svg';
import EditableInput from '../EditableInput';
import ProjectName from './ProjectName';

const Toolbar = (props) => {
const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector(
Expand All @@ -31,7 +30,6 @@ const Toolbar = (props) => {
const dispatch = useDispatch();

const { t } = useTranslation();
const { changeSketchName, canEditProjectName } = useSketchActions();

const playButtonClass = classNames({
'toolbar__play-button': true,
Expand Down Expand Up @@ -96,17 +94,7 @@ const Toolbar = (props) => {
</label>
</div>
<div className="toolbar__project-name-container">
<EditableInput
value={project.name}
disabled={!canEditProjectName}
aria-label={t('Toolbar.EditSketchARIA')}
inputProps={{
maxLength: 128,
'aria-label': t('Toolbar.NewSketchNameARIA')
}}
validate={(text) => text.trim().length > 0}
onChange={changeSketchName}
/>
<ProjectName />
{(() => {
if (project.owner) {
return (
Expand Down

0 comments on commit a49f834

Please sign in to comment.