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
Add Job Data block #1286
Closed
Closed
Add Job Data block #1286
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b022c96
Add Job Listing Gutenberg block
donnapep 3c6fa6e
Add block build configuration
donnapep 5d939b0
Include block PHP file
donnapep e737193
Show Gutenberg editor for Job Listings CPT
donnapep 1d95d70
Add job listing block to new job listing CPT
donnapep f9bd0b9
Don't show meta box in Gutenberg editor
donnapep a49627b
Show job types and categories in Gutenberg sidebar
donnapep b26c169
Update deprecated Gutenberg components
donnapep 1859b01
Fix SVG icon
donnapep 01fa3d4
Use server-side API to manage scripts and styles
donnapep 1e16d30
Use default Babel preset for WordPress development
donnapep ff30d87
package-lock.json is intended to be checked into source control
donnapep cd004a0
Add additional TODOs
donnapep ae9e726
Fix file upload functionality
donnapep 5c137e0
Continue to use featured image for company logo
donnapep 42c057f
Job listing description will come from the post content
donnapep 959e0ea
Rename block to Job Data
donnapep File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": [ "@wordpress/default" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const BriefcaseIcon = () => ( | ||
<svg | ||
aria-hidden | ||
className="job-data__briefcase-icon" | ||
role="img" | ||
focusable="false" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="20" | ||
height="20" | ||
viewBox="0 0 1792 1792"> | ||
<path d="M640 256h512v-128h-512v128zm1152 640v480q0 66-47 113t-113 47h-1472q-66 0-113-47t-47-113v-480h672v160q0 26 19 45t45 19h320q26 0 45-19t19-45v-160h672zm-768 0v128h-256v-128h256zm768-480v384h-1792v-384q0-66 47-113t113-47h352v-160q0-40 28-68t68-28h576q40 0 68 28t28 68v160h352q66 0 113 47t47 113z" /> | ||
</svg> | ||
); | ||
|
||
export default BriefcaseIcon; |
53 changes: 53 additions & 0 deletions
53
includes/blocks/job-data/class-wp-job-manager-block-job-data.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Job Data Block | ||
*/ | ||
|
||
class WP_Job_Manager_Block_Job_Data { | ||
private static $_instance = null; | ||
|
||
public static function instance() { | ||
if ( is_null( self::$_instance ) ) { | ||
self::$_instance = new self(); | ||
} | ||
|
||
return self::$_instance; | ||
} | ||
|
||
public function __construct() { | ||
add_action( 'init', array( $this, 'register_block' ) ); | ||
} | ||
|
||
public function register_block() { | ||
if ( function_exists( 'register_block_type' ) ) { | ||
wp_register_script( | ||
'wpjm-job-data', | ||
plugins_url( 'build/index.js', __FILE__ ), | ||
array( 'wp-blocks', 'wp-i18n' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'build/index.js' ) | ||
); | ||
|
||
wp_register_style( | ||
'wpjm-job-data-editor', | ||
plugins_url( 'build/editor.css', __FILE__ ), | ||
array( 'wp-edit-blocks' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'build/editor.css' ) | ||
); | ||
|
||
wp_register_style( | ||
'wpjm-job-data', | ||
plugins_url( 'build/style.css', __FILE__ ), | ||
array( 'wp-edit-blocks' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'build/style.css' ) | ||
); | ||
|
||
register_block_type( 'wpjm/job-data', array( | ||
'editor_script' => 'wpjm-job-data', | ||
'editor_style' => 'wpjm-job-data-editor', | ||
'style' => 'wpjm-job-data', | ||
) ); | ||
} | ||
} | ||
} | ||
|
||
WP_Job_Manager_Block_Job_Data::instance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.wp-block-wpjm-job-data .job-data__upload-button.button { | ||
margin-right: 5px; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__upload-button.button .dashicon { | ||
vertical-align: middle; | ||
margin-bottom: 3px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
const { __ } = wp.i18n; | ||
const { | ||
registerBlockType, | ||
InspectorControls, | ||
RichText, | ||
} = wp.blocks; | ||
const { | ||
withState, | ||
PanelBody, | ||
TextControl, | ||
ToggleControl, | ||
} = wp.components; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
import './style.scss'; | ||
import BriefcaseIcon from './briefcase-icon'; | ||
|
||
registerBlockType( 'wpjm/job-data', { | ||
title: __( 'Job Data' ), | ||
category: 'widgets', | ||
description: __( 'Shows additional information about a job listing.' ), | ||
icon: BriefcaseIcon, | ||
attributes: { | ||
alt: { | ||
type: 'string', | ||
source: 'attribute', | ||
selector: 'img', | ||
attribute: 'alt', | ||
}, | ||
id: { | ||
type: 'number', | ||
}, | ||
url: { | ||
type: 'string', | ||
source: 'attribute', | ||
selector: 'img', | ||
attribute: 'src', | ||
}, | ||
}, | ||
edit: withState( { | ||
editable: 'location', | ||
} )( ( { attributes, className, editable, isSelected, setAttributes, setState } ) => { | ||
const { | ||
alt, | ||
application, | ||
company, | ||
expiryDate, | ||
featuredListing, | ||
id, | ||
location, | ||
positionFilled, | ||
tagline, | ||
twitter, | ||
url, | ||
} = attributes; | ||
|
||
const onSetActiveEditable = newEditable => () => setState( { editable: newEditable } ); | ||
const updateLogo = ( { alt, id, url } ) => setAttributes( { alt, id, url } ); | ||
const updateToggle = field => () => setAttributes( { [ field ]: ! attributes[ field ] } ); | ||
const updateValue = field => value => setAttributes( { [ field ]: value } ); | ||
|
||
return ( | ||
<div className={ className }> | ||
{ isSelected && ( | ||
<InspectorControls key="inspector"> | ||
<PanelBody title={ __( 'Job Data Settings' ) }> | ||
<ToggleControl | ||
checked={ positionFilled } | ||
label={ __( 'Position Filled' ) } | ||
onChange={ updateToggle( 'positionFilled' ) } /> | ||
|
||
<ToggleControl | ||
checked={ featuredListing } | ||
label={ __( 'Featured Listing' ) } | ||
onChange={ updateToggle( 'featuredListing' ) } /> | ||
|
||
<TextControl | ||
label={ __( 'Application Email or URL' ) } | ||
onChange={ updateValue( 'application' ) } | ||
value={ application } /> | ||
|
||
<TextControl | ||
label={ __( 'Expiry Date' ) } | ||
onChange={ updateValue( 'expiryDate' ) } | ||
value={ expiryDate } /> | ||
</PanelBody> | ||
</InspectorControls> | ||
) } | ||
|
||
<div className="job-data__details"> | ||
{ /* TODO: Show when at least one job type is selected. */ } | ||
{ false && ( | ||
<ul className="job-data__type-list"> | ||
{ /* TODO: Dynamically add list item when job type is selected. */ } | ||
<li className="job-data__type is-full-time"> | ||
{ __( 'Full Time' ) } | ||
</li> | ||
<li className="job-data__type is-freelance"> | ||
{ __( 'Freelance' ) } | ||
</li> | ||
</ul> | ||
) } | ||
|
||
<div className="job-data__meta"> | ||
<RichText | ||
isSelected={ isSelected && editable === 'location' } | ||
onChange={ updateValue( 'location' ) } | ||
onFocus={ onSetActiveEditable( 'location' ) } | ||
placeholder={ __( 'Enter job location…' ) } | ||
tagName="span" | ||
wrapperClassName="job-data__location" | ||
value={ location } | ||
keepPlaceholderOnFocus /> | ||
|
||
{ /* TODO: Show once job is saved. */ } | ||
{ false && ( | ||
<span className="job-data__date-posted"> | ||
<time dateTime="2017-08-31"> | ||
{ __( 'Posted 1 minute ago' ) } | ||
</time> | ||
</span> | ||
) } | ||
</div> | ||
|
||
<div className="job-data__company-details"> | ||
<RichText | ||
isSelected={ isSelected && editable === 'company' } | ||
onChange={ updateValue( 'company' ) } | ||
onFocus={ onSetActiveEditable( 'company' ) } | ||
placeholder={ __( 'Enter company name…' ) } | ||
tagName="span" | ||
value={ company } | ||
keepPlaceholderOnFocus /> | ||
<RichText | ||
isSelected={ isSelected && editable === 'tagline' } | ||
onChange={ updateValue( 'tagline' ) } | ||
onFocus={ onSetActiveEditable( 'tagline' ) } | ||
placeholder={ __( 'Enter company tagline…' ) } | ||
tagName="span" | ||
value={ tagline } | ||
keepPlaceholderOnFocus /> | ||
<RichText | ||
isSelected={ isSelected && editable === 'twitter' } | ||
onChange={ updateValue( 'twitter' ) } | ||
onFocus={ onSetActiveEditable( 'twitter' ) } | ||
placeholder={ __( 'Enter company Twitter account…' ) } | ||
tagName="span" | ||
value={ twitter } | ||
wrapperClassName="job-data__twitter" | ||
keepPlaceholderOnFocus /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} ), | ||
save: () => { | ||
// TODO | ||
return null; | ||
} | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
$full-time: #90da36; | ||
$freelance: #3399cc; | ||
|
||
%display-icon { | ||
display: inline-block; | ||
width: 16px; | ||
height: 16px; | ||
-webkit-font-smoothing: antialiased; | ||
font-size: 16px; | ||
font-family: "job-manager" !important; | ||
text-decoration: none; | ||
font-weight: normal; | ||
font-style: normal; | ||
vertical-align: top; | ||
margin: 0 2px 0 0; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__details { | ||
margin-top: 1em; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__type-list { | ||
list-style: none; | ||
margin: 0 0 .5em; | ||
padding: 0; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__type { | ||
display: inline-block; | ||
padding: .5em; | ||
margin: 0 1em 0 0; | ||
line-height: 1em; | ||
color: #fff; | ||
|
||
&.is-freelance { | ||
background-color: $freelance; | ||
} | ||
|
||
&.is-full-time { | ||
background-color: $full-time; | ||
} | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__meta { | ||
margin-bottom: 1em; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__location { | ||
display: inline-block; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__location, | ||
.wp-block-wpjm-job-data .job-data__date-posted { | ||
margin-right: 1em; | ||
color: #999; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__location:before { | ||
@extend %display-icon; | ||
content: '\e81d'; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__date-posted:before { | ||
@extend %display-icon; | ||
content: '\e80f'; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__twitter:before { | ||
@extend %display-icon; | ||
content: '\e80a'; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__company-details { | ||
border: 1px solid #eee; | ||
padding: 1em; | ||
margin: 0 0 2em; | ||
min-height: 3em; | ||
box-shadow: 0 1px 1px rgba(0,0,0,0.1); | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__application-wrapper { | ||
margin: 0 0 1em; | ||
} | ||
|
||
.wp-block-wpjm-job-data .job-data__application { | ||
display: inline-block; | ||
margin: 0 .5em 0 0; | ||
padding: 1em 2em; | ||
text-align: center; | ||
font-size: 1.1em; | ||
line-height: 1em; | ||
outline: 0; | ||
} | ||
|
||
/** | ||
* Small devices (landscape phones, 576px and up) | ||
*/ | ||
@media screen and (min-width: 576px) { | ||
.wp-block-wpjm-job-data .job-data__type-list, | ||
.wp-block-wpjm-job-data .job-data__meta { | ||
display: inline-block; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could be replaced with WordPress' presets:
https://github.com/WordPress/gutenberg/blob/master/package.json#L99-L102
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.
Nice!