Skip to content

Commit d86eabd

Browse files
authored
Merge pull request #47 from jazzsequence/feature/1.3.0-gutenblocks
Feature/1.3.0 gutenblocks
2 parents 1c87283 + 5ca1e30 commit d86eabd

22 files changed

+726
-56
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "@wordpress/default" ]
3+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ bower_components
2828
.bower-registry
2929
.bower-tmp
3030

31+
### Don't version control lock files
32+
*.lock
33+
package-lock.json
34+
35+
### Don't version control the yeoman generator file.
36+
.yo-rc.json
3137

3238
### Node ###
3339
# Logs

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ You can checkout a live [demo](https://jazzsequence.com/games/) of the plugin (w
3939

4040
## Changelog ##
4141

42+
### 1.3.0 ###
43+
* Added first Gutenberg block! Now you can add your games list in Gutenberg rather than using a shortcode. More Gutenberg blocks to come.
44+
4245
### 1.2.0 ###
4346
* Added integration with Board Game Geek API. Games can now be added by searching BGG for matching titles and information imported and automatically added to new games.
4447
* Fixed an issue where games with an indeterminate max number of players was displaying a 0 value (e.g. `2 - 0 players`) and combined that with games with an unrealistically large number of players (e.g. `2 - 99 players`) to display `{{min_players}}+ players` e.g. `2+ players`.

assets/css/editor.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Games Collector
3+
* https://github.com/jazzsequence/games-collector
4+
*
5+
* Copyright (c) 2017 Chris Reynolds
6+
* Licensed under the GPLv3+ license.
7+
*/

assets/css/games-collector.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

assets/css/main.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Games Collector
3+
* https://github.com/jazzsequence/games-collector
4+
*
5+
* Copyright (c) 2017 Chris Reynolds
6+
* Licensed under the GPLv3+ license.
7+
*/
8+
.games-filter-group {
9+
display: block;
10+
padding: 0 0 2em; }
11+
12+
.game-title {
13+
font-size: 1.2em; }
14+
15+
.game-single {
16+
margin: 0 0 1em; }
17+
18+
.game-info {
19+
font-size: 0.9em;
20+
line-height: 1.1em; }
21+
.game-info span.game-min-players, .game-info span.gc-attribute {
22+
padding-right: 0em; }
23+
24+
div.game-attributes {
25+
display: block; }
26+
27+
svg.gc-icon {
28+
height: 1.1em; }

assets/js/blocks/frontend.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Games Collector Frontend
3+
*
4+
* All the js that isn't relating to Isotope.
5+
*/
6+
7+
// Load the frontend styles.
8+
import '../../sass/style.scss'

assets/js/blocks/icons.js

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/blocks/index.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Games Collector Editor
3+
*
4+
* All the js that is admin-only (e.g. Gutenberg).
5+
*/
6+
7+
// Define the textdomain.
8+
wp.i18n.setLocaleData( { '': {} }, 'games-collector' );
9+
10+
// Load WP.
11+
// import WPAPI from 'wpapi';
12+
// import 'whatwg-fetch';
13+
// import apiFetch from '@wordpress/api-fetch';
14+
// import { addQueryArgs } from '@wordpress/url';
15+
16+
// Load the editor-specific styles.
17+
import '../../sass/editor.scss';
18+
19+
// Load front-end styles.
20+
import '../../sass/style.scss';
21+
22+
// Load the Gutenberg icons.
23+
import icons from './icons';
24+
25+
// Load internal Gutenberg stuff.
26+
const { __ } = wp.i18n;
27+
const { registerBlockType } = wp.blocks;
28+
const {
29+
Spinner,
30+
TextControl,
31+
} = wp.components;
32+
const { withSelect } = wp.data;
33+
34+
/**
35+
* Make the first letter of a string uppercase.
36+
*
37+
* Mirror's PHP's ucfirst function.
38+
*
39+
* @param {string} string The string to process.
40+
* @return {string} The string with the first letter capitalized.
41+
*/
42+
function ucfirst( string ) {
43+
return string.charAt(0).toUpperCase() + string.slice(1);
44+
}
45+
46+
// Register the all games Gutenberg block.
47+
registerBlockType( 'games-collector/add-all-games', {
48+
title: __( 'All Games', 'games-collector' ),
49+
description: __( 'Add all games to any post or page.', 'games-collector' ),
50+
category: 'widgets',
51+
icon: {
52+
src: icons.dice
53+
},
54+
keywords: [
55+
__( 'Games Collector', 'games-collector' ),
56+
__( 'game list', 'games-collector' ),
57+
__( 'all games', 'games-collector' ),
58+
],
59+
edit: withSelect( query => {
60+
return {
61+
posts: query( 'core' ).getEntityRecords( 'postType', 'gc_game', { per_page: -1, orderby: 'title', order: 'asc' } )
62+
};
63+
} )( ( { posts, className, isSelected } ) => {
64+
if ( ! posts ) {
65+
return (
66+
<p className={ className } >
67+
<Spinner />
68+
{ __( 'Loading Posts', 'games-collector' ) }
69+
</p>
70+
);
71+
}
72+
if ( 0 === posts.length ) {
73+
return <p>{ __( 'No Posts', 'games-collector' ) }</p>;
74+
}
75+
return (
76+
<div className={ className }>
77+
{ posts.map( post => {
78+
let divId = `game-${ post.id }-info`,
79+
title = ( 'undefined' !== typeof post.url ) ? `
80+
<a href=${ post.url.toString() }><span className="game-title" id="game-${ post.id }-title">${ post.title.rendered }</span></a>` : `<span className="game-title" id="game-${ post.id }-title">${ post.title.rendered }</span>`,
81+
numPlayers = {
82+
id: `game-${ post.id }-num-players`,
83+
total: (
84+
'undefined' === typeof post.max_players ||
85+
post.min_players[0] === post.max_players[0]
86+
) ? post.min_players[0] : `${ post.min_players[0] } - ${ post.max_players[0] }`,
87+
},
88+
playingTime = {
89+
id: `game-${ post.id }-playing-time`,
90+
message: `${ post.time } minutes`,
91+
},
92+
age = {
93+
id: `game-${ post.id }-age`,
94+
message: `${ post.age }+`,
95+
},
96+
difficulty = {
97+
id: `game-${ post.id }-difficulty`,
98+
},
99+
attributes = {
100+
id: `game-${ post.id }-attributes`,
101+
message: `${ post.attributes.join( ', ' ) }`,
102+
};
103+
104+
return (
105+
<div className={ className }>
106+
<div dangerouslySetInnerHTML={{ __html: title }} />
107+
<div className="game-info" id={ divId }>
108+
<span className="gc-icon icon-game-players">{ icons.players }</span><span className="game-num-players" id={ numPlayers.id }>{ numPlayers.total }</span>
109+
<span className="gc-icon icon-game-time">{ icons.time }</span><span className="game-playing-time" id={ playingTime.id }>{ playingTime.message }</span>
110+
<span className="gc-icon icon-game-age">{ icons.age }</span><span className="game-age" id={ age.id }>{ age.message }</span>
111+
<span className="gc-icon icon-game-difficulty">{ icons.difficulty }</span><span className="game-difficulty" id={ difficulty.id }>{ ucfirst( post.difficulty[0] ) }</span>
112+
<div className="game-attributes">
113+
<span className="gc-icon icon-game-attributes">{ icons.tags }</span><span className="game-attributes" id={ attributes.id }>{ attributes.message }</span>
114+
</div>
115+
</div>
116+
</div>
117+
);
118+
}) }
119+
</div>
120+
);
121+
} ) // end withSelect
122+
, // end edit
123+
save() {
124+
// Rendering in PHP
125+
return null;
126+
},
127+
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
window.GamesCollector = {};
55
( function( window, $, plugin ) {
66

7+
var Isotope = require( 'isotope-layout' );
8+
79
// Constructor.
810
plugin.init = function() {
911
plugin.cache();
@@ -19,7 +21,7 @@ window.GamesCollector = {};
1921
window: $(window),
2022
list: $( '.games-collector-list' ),
2123
buttons: $( '.games-filter-group' ),
22-
grid: $( '.games-collector-list' ).isotope({
24+
grid: new Isotope( '.games-collector-list', {
2325
itemSelector: '.game-single',
2426
vertical: {
2527
horizontalAlignment: 0

0 commit comments

Comments
 (0)