Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit fbb417a

Browse files
committed
Release.
1 parent 422ffea commit fbb417a

8 files changed

Lines changed: 71 additions & 26 deletions

File tree

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
# Drupal Block React
2-
Combining goodies of Drupal 8, Blocks and React.
3-
This one should be really minimal.
1+
# Drupal Block Reactive (codename Hipster)
2+
3+
[Drupal 8](https://www.drupal.org/8) module creates a block with recent comments. Displayed dynamically using [React.js](https://facebook.github.io/react/).
4+
5+
[ES2015 (ES6)](https://babeljs.io/docs/learn-es2015/) is used via Babel and npm scripts.
6+
7+
The goal is to be as simple as possible: minimum dependencies, tools and steps to actually write ES6 code that works. This way, the code can be easily modified and played with for other purposes without too much hassle.
8+
9+
## Requirements
10+
- [node.js](https://nodejs.org/en/download/) for using npm, not for API
11+
- npm for package management)
12+
- working [Drupal 8](https://www.drupal.org/project/drupal) project
13+
- command line obviously
14+
15+
## Installation
16+
1. Go to the /modules folder in your Drupal 8 project (normally /modules from project root)
17+
2. Clone this repository
18+
3. Go to /js folder inside the cloned folder
19+
4. Run `npm install` to download dependencies
20+
5. Enable the Drupal module by `drush pm-enable drupal_block_reactive` or [via the UI](https://www.drupal.org/documentation/install/modules-themes/modules-8)
21+
6. Import example Views export configuration from the module. (/config/install, will be automatic later)
22+
7. Go to the block management page '/admin/structure/block' and find/place the custom module 'Recent comments (reactive)'
23+
8. Go to the page where you placed the block and you should see 'No comments.' message in a block.
24+
25+
Now, play with the reactivity by splitting the window into 2 and posting a comment from one to the other. The expected modern behavior :)
26+
27+
## Demo
28+
29+
![ScreenShot](https://raw.github.com/kalinchernev/drupal_block_reactive/master/screenshot.gif)
30+
31+
## Credits
32+
Inspirations from places:
33+
34+
- [Drupal React Block](https://github.com/blackwood/drupal-react_blocks) (same idea for Drupal 7)
35+
- [React.js tutorial](https://facebook.github.io/react/docs/tutorial.html)
36+
- [Powering Up With React](https://www.codeschool.com/courses/powering-up-with-react)

drupal_block_reactive.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Recent comments (React)
22
type: module
3-
description: 'Showing latest comments in a reactive way.'
3+
description: 'Latest comments block with React.js'
44
package: Development
55
version: '8.x-1.x-dev'
66
core: '8.x'

drupal_block_reactive.libraries.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
recent-comments-reactive.reactjs:
1+
reactjs:
22
remote: https://github.com/facebook/react
33
version: 15.1.0
44
license:
@@ -10,7 +10,7 @@ recent-comments-reactive.reactjs:
1010
//cdn.jsdelivr.net/react/15.1.0/react.js: { type: external, minified: false }
1111
//cdn.jsdelivr.net/react/15.1.0/react-dom.js: { type: external, minified: false }
1212

13-
recent-comments-reactive.component:
13+
component:
1414
version: VERSION
1515
js:
1616
js/dist/index.js: {}

js/dist/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
1515

1616
Drupal.behaviors.drupal_block_reactive = {
1717
attach: function attach(context) {
18-
// CommentBox component definition.
18+
// CommentBox component.
1919

2020
var CommentBox = function (_React$Component) {
2121
_inherits(CommentBox, _React$Component);
2222

2323
function CommentBox() {
2424
_classCallCheck(this, CommentBox);
2525

26+
// Setting initial state.
27+
2628
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(CommentBox).call(this));
2729

2830
_this.state = {
@@ -49,7 +51,6 @@ Drupal.behaviors.drupal_block_reactive = {
4951
}
5052
});
5153
}
52-
5354
// Gets data from state, returns a list components.
5455

5556
}, {
@@ -85,16 +86,15 @@ Drupal.behaviors.drupal_block_reactive = {
8586
var commentsNodes = this._getComments();
8687
return React.createElement(
8788
'div',
88-
{ className: 'comments' },
89+
{ className: 'CommentBox' },
8990
commentsNodes
9091
);
9192
}
9293
}]);
9394

9495
return CommentBox;
9596
}(React.Component);
96-
97-
// Comment component definition.
97+
// Comment component.
9898

9999

100100
var Comment = function (_React$Component2) {
@@ -111,7 +111,7 @@ Drupal.behaviors.drupal_block_reactive = {
111111
value: function render() {
112112
return React.createElement(
113113
'div',
114-
{ className: 'comment' },
114+
{ className: 'Comment' },
115115
React.createElement(
116116
'span',
117117
null,

js/package.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
{
22
"name": "drupal-block-reactive",
33
"version": "1.0.0",
4-
"description": "JS things in Drupal things",
4+
"description": "A drop of reactivity in Drupal 8",
55
"main": "index.js",
6+
"private": true,
67
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"dev": "./node_modules/babel-cli/bin/babel.js --presets es2015,react --watch src/ --out-dir dist"
8+
"clean": "rm -rf dist",
9+
"build": "npm run clean && npm run transpile",
10+
"dev": "./node_modules/babel-cli/bin/babel.js --presets es2015,react --watch src/ --out-dir dist",
11+
"lint": "eslint src",
12+
"transpile": "./node_modules/babel-cli/bin/babel.js --presets es2015,react src/ --out-dir dist"
13+
},
14+
"author": "Kalin Chernev",
15+
"url": "https://github.com/kalinchernev",
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/kalinchernev/drupal_block_reactive.git"
919
},
10-
"author": "",
11-
"license": "ISC",
1220
"devDependencies": {
1321
"babel-cli": "^6.10.1",
1422
"babel-preset-es2015": "^6.9.0",
15-
"babel-preset-react": "^6.5.0"
23+
"babel-preset-react": "^6.5.0",
24+
"eslint": "^2.12.0",
25+
"eslint-config-airbnb": "^9.0.1",
26+
"eslint-plugin-import": "^1.8.1",
27+
"eslint-plugin-jsx-a11y": "^1.4.2",
28+
"eslint-plugin-react": "^5.1.1"
1629
}
1730
}

js/src/index.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
Drupal.behaviors.drupal_block_reactive = {
77
attach: (context) => {
8-
// CommentBox component definition.
8+
// CommentBox component.
99
class CommentBox extends React.Component {
1010
constructor() {
1111
super();
12+
// Setting initial state.
1213
this.state = {
1314
comments: []
1415
}
@@ -24,7 +25,6 @@ Drupal.behaviors.drupal_block_reactive = {
2425
}
2526
});
2627
}
27-
2828
// Gets data from state, returns a list components.
2929
_getComments() {
3030
// Get the list of comments from the state.
@@ -52,18 +52,17 @@ Drupal.behaviors.drupal_block_reactive = {
5252
render() {
5353
const commentsNodes = this._getComments();
5454
return (
55-
<div className="comments">
55+
<div className="CommentBox">
5656
{commentsNodes}
5757
</div>
5858
);
5959
}
6060
}
61-
62-
// Comment component definition.
61+
// Comment component.
6362
class Comment extends React.Component {
6463
render() {
6564
return (
66-
<div className="comment">
65+
<div className="Comment">
6766
<span>{this.props.subject}</span> | <span>{this.props.changed}</span>
6867
</div>
6968
);

screenshot.gif

1.8 MB
Loading

src/Plugin/Block/RecentCommentsBlock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function build() {
2323
'#markup' => '<div id="recent-comments-react"></div>',
2424
'#attached' => [
2525
'library' => [
26-
'drupal_block_reactive/recent-comments-reactive.reactjs',
27-
'drupal_block_reactive/recent-comments-reactive.component',
26+
'drupal_block_reactive/reactjs',
27+
'drupal_block_reactive/component',
2828
],
2929
],
3030
];

0 commit comments

Comments
 (0)