-
Notifications
You must be signed in to change notification settings - Fork 123
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
Author Select #328
Author Select #328
Changes from 11 commits
07e647f
12cf0f6
c8f5aaf
682d12f
9fc4c68
bc1e022
4e15644
cb58425
f74898e
ffcde3e
fca2723
77274cf
96a3879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,24 @@ public static function get_post_id() { | |
return self::$post_id; | ||
} | ||
|
||
/** | ||
* Get current user | ||
*/ | ||
public static function get_current_user() { | ||
if (!self::is_liveblog_editable()) { | ||
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. Could do with updating the spacing here. |
||
return false; | ||
} | ||
|
||
$user = wp_get_current_user(); | ||
|
||
return array( | ||
'id' => $user->ID, | ||
'key' => strtolower($user->user_nicename), | ||
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. Spacing :) |
||
'name' => $user->display_name, | ||
'avatar' => get_avatar( $user->ID, 20 ), | ||
); | ||
} | ||
|
||
/** | ||
* This is where a majority of the magic happens. | ||
* | ||
|
@@ -550,6 +568,8 @@ public static function ajax_crud_entry() { | |
$args['post_id'] = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0; | ||
$args['content'] = isset( $_POST['content'] ) ? $_POST['content'] : ''; | ||
$args['entry_id'] = isset( $_POST['entry_id'] ) ? intval( $_POST['entry_id'] ) : 0; | ||
$args['author_id'] = isset( $_POST['author_id'] ) ? intval( $_POST['author_id'] ) : false; | ||
$args['contributor_ids'] = isset( $_POST['contributor_ids'] ) ? intval( $_POST['contributor_ids'] ) : false; | ||
|
||
$entry = self::do_crud_entry($crud_action, $args); | ||
|
||
|
@@ -952,6 +972,8 @@ public static function enqueue_scripts() { | |
'post_id' => get_the_ID(), | ||
'state' => self::get_liveblog_state(), | ||
'is_liveblog_editable' => self::is_liveblog_editable(), | ||
'current_user' => self::get_current_user(), | ||
'author_edit_enabled' => WPCOM_Liveblog_Entry::is_author_select_enabled(), | ||
'socketio_enabled' => WPCOM_Liveblog_Socketio_Loader::is_enabled(), | ||
|
||
'key' => self::key, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class AuthorSelectOption extends Component { | ||
handleMouseDown(event) { | ||
const { onSelect, option } = this.props; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
onSelect(option, event); | ||
} | ||
|
||
handleMouseEnter(event) { | ||
this.props.onFocus(this.props.option, event); | ||
} | ||
|
||
handleMouseMove(event) { | ||
const { isFocused, onFocus, option } = this.props; | ||
if (isFocused) return; | ||
onFocus(option, event); | ||
} | ||
|
||
render() { | ||
const { className, option } = this.props; | ||
return ( | ||
<div | ||
className={`${className} liveblog-popover-item`} | ||
onMouseDown={this.handleMouseDown.bind(this)} | ||
onMouseEnter={this.handleMouseEnter.bind(this)} | ||
onMouseMove={this.handleMouseMove.bind(this)} | ||
> | ||
<div dangerouslySetInnerHTML={{ __html: option.avatar }} /> | ||
{option.name} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
AuthorSelectOption.propTypes = { | ||
onSelect: PropTypes.func, | ||
option: PropTypes.object, | ||
onFocus: PropTypes.func, | ||
isFocused: PropTypes.bool, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default AuthorSelectOption; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { timeAgo, formattedTime } from '../utils/utils'; | ||
|
||
const EntryMeta = ({ entry, authorEditEnabled }) => ( | ||
<header className="liveblog-meta"> | ||
<div className="liveblog-meta-time"> | ||
<span>{timeAgo(entry.entry_time)}</span> | ||
<span>{formattedTime(entry.entry_time)}</span> | ||
</div> | ||
<div className="liveblog-meta-author"> | ||
<div | ||
className="liveblog-meta-authour-avatar" | ||
dangerouslySetInnerHTML={{ __html: entry.author.avatar }} /> | ||
<span className="liveblog-meta-author-name" | ||
dangerouslySetInnerHTML={{ __html: entry.author.name }} /> | ||
</div> | ||
{ | ||
authorEditEnabled && | ||
<div className="liveblog-meta-contributors"> | ||
{ | ||
entry.contributors.map(contributor => ( | ||
<div className="liveblog-meta-author" key={contributor.id}> | ||
<div | ||
className="liveblog-meta-authour-avatar" | ||
dangerouslySetInnerHTML={{ __html: contributor.avatar }} /> | ||
<span className="liveblog-meta-author-name" | ||
dangerouslySetInnerHTML={{ __html: contributor.name }} /> | ||
</div> | ||
)) | ||
} | ||
</div> | ||
} | ||
</header> | ||
); | ||
|
||
EntryMeta.propTypes = { | ||
entry: PropTypes.object, | ||
authorEditEnabled: PropTypes.bool, | ||
}; | ||
|
||
export default EntryMeta; |
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.
Minor, but can we fix the spacing here?