-
Couldn't load subscription status.
- Fork 78
Comment publish preview flow #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,49 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| export default Ember.Component.extend({ | ||
| classNames: ['comment-item'] | ||
| classNames: ['comment-item'], | ||
| classNameBindings: ['isEditing:editing'], | ||
|
|
||
| session: Ember.inject.service(), | ||
|
|
||
| currentUserId: Ember.computed.alias('session.session.authenticated.user_id'), | ||
| commentAuthorId: Ember.computed.alias('comment.user.id'), | ||
| currentUserIsCommentAuthor: Ember.computed('currentUserId', 'commentAuthorId', function() { | ||
| let userId = parseInt(this.get('currentUserId'), 10); | ||
| let authorId = parseInt(this.get('commentAuthorId'), 10); | ||
| return userId === authorId; | ||
| }), | ||
|
|
||
| canEdit: Ember.computed.and('session.isAuthenticated', 'currentUserIsCommentAuthor'), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Common to keep the aliases all together near the top after static attributes, then computed properties, then methods, then actions. Keeps the files clean and clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm having trouble seeing how you want this reordered. Can you order it in something like:
so I can understand better? |
||
|
|
||
| didInitAttrs() { | ||
| this.set('isEditing', false); | ||
| return this._super(...arguments); | ||
| }, | ||
|
|
||
| actions: { | ||
| edit() { | ||
| this.set('isEditing', true); | ||
| }, | ||
|
|
||
| cancel() { | ||
| this.set('isEditing', false); | ||
| }, | ||
|
|
||
| save() { | ||
| let component = this; | ||
| let comment = this.get('comment'); | ||
| comment.set('preview', false); | ||
| comment.save().then(() => { | ||
| component.set('isEditing', false); | ||
| }); | ||
| }, | ||
|
|
||
| generatePreview(markdown) { | ||
| let comment = this.get('comment'); | ||
| comment.set('markdownPreview', markdown); | ||
| comment.set('preview', true); | ||
| comment.save(); | ||
| } | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| export default Ember.Component.extend({ | ||
| classNames: ['editor-with-preview'], | ||
| classNameBindings: ['mode'], | ||
|
|
||
| mode: null, | ||
|
|
||
| editing: Ember.computed.equal('mode', 'editing'), | ||
| previewing: Ember.computed.equal('mode', 'previewing'), | ||
|
|
||
| didInitAttrs() { | ||
| this._super(...arguments); | ||
| this.mode = 'editing'; | ||
| }, | ||
|
|
||
| actions: { | ||
| preview() { | ||
| this.set('mode', 'previewing'); | ||
| this.set('preview', 'Loading preview...'); | ||
| let content = this.get('input'); | ||
| this.sendAction('generatePreview', content); | ||
| }, | ||
|
|
||
| edit() { | ||
| this.set('mode', 'editing'); | ||
| } | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,49 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| export default Ember.Component.extend({ | ||
| classNames: ['post-details'] | ||
| session: Ember.inject.service(), | ||
|
|
||
| classNames: ['post-details'], | ||
| classNameBindings: ['post.postType'], | ||
|
|
||
| didInitAttrs() { | ||
| this.set('isEditingBody', false); | ||
| this.set('isEditingTitle', false); | ||
| return this._super(...arguments); | ||
| }, | ||
|
|
||
| actions: { | ||
| editPostBody() { | ||
| this.set('isEditingBody', true); | ||
| }, | ||
|
|
||
| cancelEditingPostBody() { | ||
| this.set('isEditingBody', false); | ||
| }, | ||
|
|
||
| generatePreview(markdown) { | ||
| let post = this.get('post'); | ||
| post.set('markdownPreview', markdown); | ||
| post.set('preview', true); | ||
| post.save(); | ||
| }, | ||
|
|
||
| savePostBody() { | ||
| let component = this; | ||
| let post = this.get('post'); | ||
| post.set('preview', false); | ||
| post.save().then(() => { | ||
| component.set('isEditingBody', false); | ||
| }); | ||
| }, | ||
|
|
||
| savePostTitle(title) { | ||
| let component = this; | ||
| let post = this.get('post'); | ||
| post.set('title', title); | ||
| post.save().then(() => { | ||
| component.set('isEditingTitle', false); | ||
| }); | ||
| } | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| export default Ember.Component.extend({ | ||
| session: Ember.inject.service(), | ||
|
|
||
| classNames: ['post-title'], | ||
| classNameBindings: ['isEditing:editing'], | ||
|
|
||
| didInitAttrs() { | ||
| this.setProperties({ | ||
| isEditing: false, | ||
| }); | ||
| }, | ||
|
|
||
| actions: { | ||
| edit() { | ||
| this.set('newTitle', this.get('title')); | ||
| this.set('isEditing', true); | ||
| }, | ||
|
|
||
| save() { | ||
| let newTitle = this.get('newTitle'); | ||
| this.sendAction('saveTitle', newTitle); | ||
| this.set('isEditing', false); | ||
| }, | ||
|
|
||
| cancel() { | ||
| this.set('isEditing', false); | ||
| } | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import DS from 'ember-data'; | ||
|
|
||
| export default DS.Model.extend({ | ||
| model: DS.belongsTo('model', { polymorphic: true }), | ||
| model: DS.belongsTo('model', { async: true, polymorphic: true }), | ||
| modelType: DS.attr('string'), | ||
| slug: DS.attr('string'), | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import ApplicationSerializer from './application'; | ||
|
|
||
| export default ApplicationSerializer.extend({ | ||
| _attributeIsPreviewOnly(attribute) { | ||
| return ['preview', 'markdownPreview'].indexOf(attribute.name) > -1; | ||
| }, | ||
|
|
||
| serializeAttribute: function(snapshot, json, key, attribute) { | ||
| // for creating records, just regularly serialize the payload | ||
| if (snapshot.record.get('isNew')) { | ||
| if (snapshot.attr('preview')) { | ||
| if (this._attributeIsPreviewOnly(attribute)) { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else { | ||
| // for updating existing records, we have 2 cases | ||
| // we're editing or requesting a preview of the post body. In that | ||
| // case, we only need to push markdownPreview and the preview flag itself | ||
|
|
||
| if (this._attributeIsPreviewOnly(attribute)) { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import ApplicationSerializer from './application'; | ||
|
|
||
| export default ApplicationSerializer.extend({ | ||
| _attributeIsPreviewOnly(attribute) { | ||
| return ['preview', 'markdownPreview'].indexOf(attribute.name) > -1; | ||
| }, | ||
|
|
||
| serializeAttribute: function(snapshot, json, key, attribute) { | ||
| // for creating records, just regularly serialize the payload | ||
| if (snapshot.record.get('isNew')) { | ||
| if (snapshot.attr('preview')) { | ||
| if (this._attributeIsPreviewOnly(attribute)) { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else { | ||
| // for updating existing records, we have 3 cases | ||
| // 1. we're editing or requesting a preview of the post body. In that | ||
| // case, we only need to push markdownPreview and the preview flag itself | ||
| // 2. we're editing the title. In that case, we only push the title | ||
| // 3. We're outright editing the post body - we only send markdownPreview | ||
| if (snapshot.attr('preview') === true) { | ||
| if (this._attributeIsPreviewOnly(attribute)) { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else if (snapshot.changedAttributes().title) { | ||
| if (attribute.name === 'title') { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } else { | ||
| if (attribute.name === 'markdownPreview') { | ||
| this._super(snapshot, json, key, attribute); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| .editor-with-preview { | ||
| margin: 10px; | ||
|
|
||
| ul { | ||
| @include clearfix; | ||
| margin: 0 0 10px 0; | ||
| padding: 0; | ||
| list-style-type: none; | ||
| width: 100%; | ||
| border-bottom: 1px solid $border-default; | ||
|
|
||
| li { | ||
| float: left; | ||
| } | ||
|
|
||
| a { | ||
| display: block; | ||
| padding: 10px 14px; | ||
| text-decoration: none; | ||
| color: $light-text; | ||
| font-weight: 700; | ||
| border-bottom: 5px solid transparent; | ||
|
|
||
| &.active { | ||
| color: $link-color; | ||
| border-bottom-color: $dark-blue; | ||
| } | ||
|
|
||
| &:hover { | ||
| color: $link-color; | ||
| border-bottom-color: $dark-blue; | ||
| transition: border-bottom-color ease 0.3s; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| textarea { | ||
| width: 100%; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to refactor this later with the
currentUserobject I'm introducing in #76.