Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions common.blocks/comments/comments.bemtree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
block('comments').content()(function() {
return this.data.comments.map(function(comment) {
return {
block: 'comment',
comment: comment
};
});
var comments = this.data.comments;

return [
comments.map(function(comment) {
return {
block: 'comment',
comment: comment
};
}),
{
elem: 'add-form',
content: {
block: 'forum-form'
}
}
]
});
5 changes: 5 additions & 0 deletions common.blocks/comments/comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@

background-color: #e1e1e1;
}

.comments__add-form {
padding: 30px 0;
background-color: #fff;
}
2 changes: 1 addition & 1 deletion common.blocks/comments/comments.deps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
({
shouldDeps: 'comment'
shouldDeps: ['comment', 'forum-form']
})
4 changes: 4 additions & 0 deletions common.blocks/forum-form/forum-form.bemhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
block('forum-form')(
tag()('form'),
js()(true)
);
61 changes: 61 additions & 0 deletions common.blocks/forum-form/forum-form.bemtree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
block('forum-form').content()(function() {
var i18n = this.require('i18n');

return [
{
elem: 'forum-create',
content: [
{
elem: 'header',
content: {
block: 'radio-group',
mods: { theme: 'islands', size: 'm', type: 'button' },
name: 'radio-button',
val: 1,
options: [
{
val: 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why such strange values? use markdown and preview. so it'll be much easier to get the value on change event instead of modifier usage.

icon: {
block: 'icon',
mods: { view: 'markdown', size: '24' }
}
},
{
val: 2,
disabled: true,
icon: {
block: 'icon',
mods: { view: 'preview', size: '24' }
}
}
]
}
},
{
elem: 'body',
content: [
{
block: 'textarea',
name: 'body',
mods: { theme: 'islands', size: 'l', width: 'available' },
mix: [{ block: 'forum-form', elem: 'view' }, { block: 'forum-form', elem: 'view_visible' }],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element name can't contain underscores as they separate names from modifiers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can I mix a block with element which has modifier(so, I wont to have like this: forum-form__view_visible)? I could not find this decision :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mix: { block: 'b1', elem: 'e1', elemMods: { m1: 'v1' } }

placeholder: i18n(this.block, 'leaveMessage')
},
{
elem: 'preview',
mix: { block: 'forum-form', elem: 'view' }
}
]
}
]
},
{
elem: 'submit',
content: {
block: 'button',
mods: { theme: 'islands', size: 'm', view: 'action' },
text: i18n(this.block, 'comment')
}
}
]
});
31 changes: 31 additions & 0 deletions common.blocks/forum-form/forum-form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.forum-form__forum-create {
margin-left: 120px;
}

.forum-form .forum-form__view {
display: none;
width: 100%;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min-height: 150px;
margin-top: 10px;
resize: vertical;
}

.forum-form .forum-form__view_visible {
display: inline-block;
}

.forum-form__preview {
box-sizing: border-box;
border: 1px solid #e5e5e5;
background-color: #f5f5f5;
padding: 5px 20px;
}

.forum-form__body {
margin-top: 10px;
}

.forum-form__submit {
margin-left: 120px;
padding-top: 20px;
}
28 changes: 28 additions & 0 deletions common.blocks/forum-form/forum-form.deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
({
shouldDeps: [
{
block: 'icon',
mods: { view: ['markdown', 'preview'], size: '24' }
},
{
block: 'radio-group',
mods: {
theme: 'islands',
size: 'm',
type: 'button'
}
},
{
block: 'textarea',
mods: {
theme: 'islands',
size: 'm',
width: 'available'
}
},
{
block: 'button',
mods: { theme: 'islands', size: 'm', view: 'action' }
}
]
})
6 changes: 6 additions & 0 deletions common.blocks/forum-form/forum-form.i18n/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'forum-form': {
leaveMessage: 'Leave a comment',
comment: 'Comment'
}
};
6 changes: 6 additions & 0 deletions common.blocks/forum-form/forum-form.i18n/ru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'forum-form': {
leaveMessage: 'Ответить',
comment: 'Написать'
}
};
35 changes: 35 additions & 0 deletions common.blocks/forum-form/forum-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
modules.define('forum-form', ['i-bem__dom', 'jquery'],
function(provide, BEMDOM, $) {

provide(BEMDOM.decl(this.name, {
onSetMod: {
js: {
inited: function() {
var textarea = this.findBlockInside('textarea'),
plainTextButton = this.findBlocksInside('button')[0],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not reliable way to find needed blocks. it'd be much better to mix elements of forum-form and find blocks like this:

plainTextButton = this.findBlockInside('plain', 'button'),
previewButton = this.findBlockInside('preview', 'button');

which means «find button on my own element plain» (or preview element).

previewButton = this.findBlocksInside('button')[1];

textarea.bindTo('keyup', function() {
$('.textarea').val() ? previewButton.delMod('disabled') : previewButton.setMod('disabled');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to use API of textarea block and use the fact that setting a modifier to false is the same as deleating it:

previewButton.setMod('disabled', !!textarea.getVal());

});

previewButton.bindTo('click', function(){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use BEM events: previewButton.on('click', function() { /* ... */ })

if( $('.textarea').val() ){
$.post('/comment-preview', { data : $('.textarea').val() })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AJAX error should be handled as well (e.g. no internet connection, etc)

.then(function(data) {
$('.textarea').removeClass('forum-form__view_visible');

@tadatuta tadatuta Aug 8, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEM API should be used: findBlockOn() and setMod() / delMod() helpers.

Almost no direct jQuery selectors are allowed in i-bem code.

$('.forum-form__preview').addClass('forum-form__view_visible').html(data);
});
}
});

plainTextButton.bindTo('click', function(){
$('.textarea').addClass('forum-form__view_visible');
$('.forum-form__preview').removeClass('forum-form__view_visible');
});
}
}
}
}));

});
4 changes: 4 additions & 0 deletions common.blocks/icon/_size/icon_size_24.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.icon_size_24 {
background-size: 24px;
margin: 0 10px;
}
3 changes: 3 additions & 0 deletions common.blocks/icon/_view/icon_view_markdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.icon_view_markdown {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="208" height="128" viewBox="0 0 208 128"><rect width="198" height="118" x="5" y="5" ry="10" stroke="#000" stroke-width="10" fill="none"/><path d="M30 98V30h20l20 25 20-25h20v68H90V59L70 84 50 59v39zm125 0l-30-33h20V30h20v35h20z"/></svg>');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to keep icons as separate files. build system will inline them automatically

}
3 changes: 3 additions & 0 deletions common.blocks/icon/_view/icon_view_preview.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions server/controllers/gh.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function getComments(req, res) {
});
}

function getCommentPreview(req, res) {
var comment = req.body.data;

res.send(marked(comment));
}

function get404 (req, res) {
makeIssueRequest(issuesRequestUrl).then(function(issues) {
var latestIssues = issues.slice(0, 10);
Expand Down Expand Up @@ -109,5 +115,6 @@ module.exports = {
getIssues,
getIssue,
getComments,
getCommentPreview,
get404
};
1 change: 1 addition & 0 deletions server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ router
.get('/:id(\\d+)', keepRetpath, controllers.gh.getIssue)

.get('/api/:id(\\d+)/comments', controllers.gh.getComments)
.post('/comment-preview', controllers.gh.getCommentPreview)

// Auth routes
.get('/auth/github', passportGitHub.authenticate('github', { scope: ['user:email'] }))
Expand Down