-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
461 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,7 @@ stats.json | |
size-plugin.json | ||
# VSCode | ||
.vscode | ||
#Webstorm | ||
.idea/ | ||
.tmp | ||
.DS_Store | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
front/src/routes/scene/duplicate-scene/DuplicateScenePage.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Text, Localizer } from 'preact-i18n'; | ||
import { RequestStatus } from '../../../utils/consts'; | ||
import cx from 'classnames'; | ||
import get from 'get-value'; | ||
import style from './style.css'; | ||
import iconList from '../../../../../server/config/icons.json'; | ||
|
||
const DuplicateScenePage = ({ children, ...props }) => ( | ||
<div class={cx('container', style.containerWithMargin)}> | ||
<button onClick={props.goBack} className="btn btn-secondary btn-sm"> | ||
<Text id="global.backButton" /> | ||
</button> | ||
|
||
<div class="row"> | ||
<div class="col col-login mx-auto"> | ||
<form onSubmit={props.duplicateScene} class="card"> | ||
<div class="card-body p-6"> | ||
<div class="card-title"> | ||
<Text id="duplicateScene.cardTitle" fields={{ name: props.sourceScene.name }} /> | ||
</div> | ||
{props.duplicateSceneStatus === RequestStatus.ConflictError && ( | ||
<div class="alert alert-danger"> | ||
<Text id="duplicateScene.sceneAlreadyExist" /> | ||
</div> | ||
)} | ||
<div class="form-group"> | ||
<label class="form-label"> | ||
<Text id="duplicateScene.nameLabel" /> | ||
</label> | ||
<Localizer> | ||
<input | ||
type="text" | ||
class={cx('form-control', { | ||
'is-invalid': get(props, 'duplicateSceneErrors.name') | ||
})} | ||
placeholder={<Text id="duplicateScene.namePlaceholder" />} | ||
value={get(props, 'scene.name')} | ||
onInput={props.updateDuplicateSceneName} | ||
/> | ||
</Localizer> | ||
<div class="invalid-feedback"> | ||
<Text id="duplicateScene.invalidName" /> | ||
</div> | ||
</div> | ||
|
||
<div className="form-group"> | ||
<label className="form-label"> | ||
<Text id="duplicateScene.iconLabel" /> | ||
</label> | ||
{get(props, 'duplicateSceneErrors.icon') && ( | ||
<div className="alert alert-danger"> | ||
<Text id="duplicateScene.invalidIcon" /> | ||
</div> | ||
)} | ||
<div className={cx('row', style.iconContainer)}> | ||
{iconList.map(icon => ( | ||
<div className="col-2"> | ||
<div | ||
className={cx('text-center', style.iconDiv, { | ||
[style.iconDivChecked]: get(props, 'scene.icon') === icon | ||
})} | ||
> | ||
<label className={style.iconLabel}> | ||
<input | ||
name="icon" | ||
type="radio" | ||
onChange={props.updateDuplicateSceneIcon} | ||
checked={get(props, 'scene.icon') === icon} | ||
value={icon} | ||
className={style.iconInput} | ||
/> | ||
<i className={`fe fe-${icon}`} /> | ||
</label> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
<div class="form-footer"> | ||
<button | ||
onClick={props.duplicateScene} | ||
class="btn btn-primary btn-block" | ||
disabled={props.duplicateSceneStatus === RequestStatus.Getting} | ||
> | ||
<Text id="duplicateScene.duplicateSceneButton" /> | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default DuplicateScenePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { Component } from 'preact'; | ||
import { connect } from 'unistore/preact'; | ||
import DuplicateScenePage from './DuplicateScenePage'; | ||
import { route } from 'preact-router'; | ||
import { RequestStatus } from '../../../utils/consts'; | ||
import get from 'get-value'; | ||
|
||
@connect('httpClient', {}) | ||
class DuplicateScene extends Component { | ||
goBack = async () => { | ||
route(`/dashboard/scene/${this.props.scene_selector}`); | ||
}; | ||
|
||
getSourceScene = async () => { | ||
const scene = await this.props.httpClient.get(`/api/v1/scene/${this.props.scene_selector}`); | ||
this.setState({ | ||
sourceScene: scene, | ||
scene: { | ||
name: '', | ||
icon: scene.icon | ||
} | ||
}); | ||
}; | ||
|
||
duplicateScene = async e => { | ||
e.preventDefault(); | ||
// if errored, we don't continue | ||
if (this.checkErrors()) { | ||
return; | ||
} | ||
this.setState({ | ||
duplicateSceneStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
const duplicatedScene = await this.props.httpClient.post( | ||
`/api/v1/scene/${this.props.scene_selector}/duplicate`, | ||
this.state.scene | ||
); | ||
this.setState({ | ||
duplicateSceneStatus: RequestStatus.Success | ||
}); | ||
route(`/dashboard/scene/${duplicatedScene.selector}`); | ||
} catch (e) { | ||
const status = get(e, 'response.status'); | ||
if (status === 409) { | ||
this.setState({ | ||
duplicateSceneStatus: RequestStatus.ConflictError | ||
}); | ||
} else { | ||
this.setState({ | ||
duplicateSceneStatus: RequestStatus.Error | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
checkErrors = () => { | ||
let duplicateSceneErrors = {}; | ||
if (!this.state.scene.name) { | ||
duplicateSceneErrors.name = true; | ||
} | ||
if (!this.state.scene.icon) { | ||
duplicateSceneErrors.icon = true; | ||
} | ||
this.setState({ | ||
duplicateSceneErrors | ||
}); | ||
return Object.keys(duplicateSceneErrors).length > 0; | ||
}; | ||
|
||
updateDuplicateSceneName = e => { | ||
this.setState({ | ||
scene: { | ||
name: e.target.value, | ||
icon: this.state.scene.icon | ||
} | ||
}); | ||
if (this.state.duplicateSceneErrors) { | ||
this.checkErrors(); | ||
} | ||
}; | ||
|
||
updateDuplicateSceneIcon = e => { | ||
this.setState({ | ||
scene: { | ||
name: this.state.scene.name, | ||
icon: e.target.value | ||
} | ||
}); | ||
if (this.state.duplicateSceneErrors) { | ||
this.checkErrors(); | ||
} | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.getSourceScene(); | ||
this.state = { | ||
scene: { | ||
name: '', | ||
icon: '' | ||
}, | ||
sourceScene: { | ||
name: '', | ||
icon: '' | ||
}, | ||
duplicateSceneErrors: null, | ||
duplicateSceneStatus: null | ||
}; | ||
} | ||
|
||
render(props, { duplicateSceneErrors, scene, duplicateSceneStatus, sourceScene }) { | ||
return ( | ||
<DuplicateScenePage | ||
{...props} | ||
goBack={this.goBack} | ||
scene={scene} | ||
sourceScene={sourceScene} | ||
updateDuplicateSceneName={this.updateDuplicateSceneName} | ||
updateDuplicateSceneIcon={this.updateDuplicateSceneIcon} | ||
duplicateScene={this.duplicateScene} | ||
duplicateSceneErrors={duplicateSceneErrors} | ||
duplicateSceneStatus={duplicateSceneStatus} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default DuplicateScene; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.containerWithMargin { | ||
margin-top: 3rem; | ||
} | ||
|
||
|
||
.iconContainer { | ||
margin-top: 1rem; | ||
height: 10rem; | ||
overflow: scroll; | ||
} | ||
|
||
.iconDiv { | ||
padding: 5px; | ||
width: 35px; | ||
margin-bottom: 8px; | ||
} | ||
|
||
.iconDivChecked { | ||
background-color: #f5f7fb; | ||
border-radius: 4px; | ||
} | ||
|
||
.iconLabel { | ||
cursor: pointer; | ||
margin-bottom: 0; | ||
} | ||
|
||
.iconInput { | ||
position: absolute; | ||
z-index: -1; | ||
opacity: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.