Skip to content

Commit

Permalink
on save, flash "saved" message #124
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielflorit committed Dec 7, 2014
1 parent 3a691a7 commit ccca2bd
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
19 changes: 19 additions & 0 deletions src/css/_animations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%flash {
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
-webkit-animation-name: flash;
}

@-webkit-keyframes flash {
from {
opacity: 0;
}

50% {
opacity: 1;
}

to {
opacity: 0;
}
}
14 changes: 13 additions & 1 deletion src/css/_menubar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,21 @@
.saved {
float: left;

a {
a, .success {
@include adjust-font-size-to($s3);
@include adjust-leading-to(1);
}

.success {
opacity: 0;
margin-left: $horizontal-space;
color: $solarized_base3;
}

.success-enter {
@extend %flash;
}
.success-enter-active {
}
}
}
1 change: 1 addition & 0 deletions src/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@import "colors";
@import "typography";
@import "button";
@import "animations";

// components
@import "livecoding";
Expand Down
23 changes: 17 additions & 6 deletions src/js/components/Livecoding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ var Livecoding = React.createClass({
// Specify what mode we're currently editing.
mode: 'html',
user: this.getUser(),
userAvatarUrl: this.getUserAvatarUrl()
userAvatarUrl: this.getUserAvatarUrl(),
gist: null
};
},

Expand Down Expand Up @@ -78,8 +79,10 @@ var Livecoding = React.createClass({
<MenuBar
mode={mode}
gistUrl={this.state.gist ? this.state.gist.html_url : null}
gistVersion={this.state.gist ? this.state.gist.history[0].version : null}
user={this.state.user}
userAvatarUrl={this.state.userAvatarUrl}
savedMessage={this.flashSaved.pop()}
/>
<div className='content'>
<Output
Expand Down Expand Up @@ -259,17 +262,16 @@ var Livecoding = React.createClass({

var self = this;

// If we're not the gist owner, fork, and save.
// If we're the gist owner, update.
// If there is no gist, create.

// If there is no gist,
if (!this.state.gist) {

// create a new gist,
GitHub.createGist(this.getToken(), data)
.then(function(gist) {

// set flash message,
self.flashSaved.push('saved');

// and update state.
self.setState({gist: gist});
history.pushState(gist.id, '', '#' + gist.id);
Expand All @@ -287,6 +289,9 @@ var Livecoding = React.createClass({
GitHub.updateGist(this.getToken(), data, this.state.gist.id)
.then(function(gist) {

// set flash message,
self.flashSaved.push('saved');

// and update state.
self.setState({gist: gist});

Expand All @@ -305,6 +310,9 @@ var Livecoding = React.createClass({
})
.then(function(gist) {

// set flash message,
self.flashSaved.push('saved');

// and update state.
self.setState({gist: gist});
history.pushState(gist.id, '', '#' + gist.id);
Expand All @@ -328,7 +336,10 @@ var Livecoding = React.createClass({

// Decide whether to render update Editor contents.
_defaultUpdateEditorContent: true,
updateEditorContent: [this._defaultUpdateEditorContent]
updateEditorContent: [this._defaultUpdateEditorContent],

// Flash saved message.
flashSaved: []

});

Expand Down
20 changes: 15 additions & 5 deletions src/js/components/MenuBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ var MenuBar = React.createClass({
</li>;
});

var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;

var gistUrl = this.props.gistUrl;

var saved = gistUrl ?
<div className='saved'>
<a href={gistUrl}>{gistUrl}</a>
</div> : null;
var saved = gistUrl ? <a href={gistUrl}>{gistUrl}</a> : null;

var success = null;
var savedMessage = this.props.savedMessage;
if (savedMessage) {
success = <span className='success' key={this.props.gistVersion}>saved</span>;
}

return (
<div className='menubar'>
Expand All @@ -81,7 +86,12 @@ var MenuBar = React.createClass({
</ul>
</li>
</ul>
{saved}
<div className='saved'>
{saved}
<ReactCSSTransitionGroup transitionName='success' transitionLeave={false}>
{success}
</ReactCSSTransitionGroup>
</div>
<ul className='menugroup mode'>
<li>
<ul className='menu'>
Expand Down

0 comments on commit ccca2bd

Please sign in to comment.