Skip to content
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

Sharable Entries #329

Merged
merged 5 commits into from
Feb 15, 2018
Merged
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
6 changes: 5 additions & 1 deletion assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@
flex-wrap: nowrap;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start; }
align-items: flex-start;
text-decoration: none; }

.liveblog-meta-time {
display: block; }

.liveblog-meta-time span {
display: block; }
Expand Down
4 changes: 2 additions & 2 deletions assets/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/app.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion assets/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
color: #666;
}

.liveblog-meta-time {
.entry-content .liveblog-meta-time {
-ms-flex-preferred-size: 60px;
flex-basis: 60px;
}

.entry-content .liveblog-meta-time,
.entry-content .liveblog-meta-time:hover,
.entry-content .liveblog-meta-time:focus {
-webkit-box-shadow: none;
box-shadow: none;
}

.liveblog-meta-time span {
font-size: 10px;
line-height: 12px;
Expand Down
6 changes: 4 additions & 2 deletions classes/class-wpcom-liveblog-entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public function get_timestamp() {

public function for_json() {
$entry_id = $this->replaces ? $this->replaces : $this->get_id();
$avatar_size = apply_filters( 'liveblog_entry_avatar_size', self::default_avatar_size );
$css_classes = implode( ' ', get_comment_class( '', $entry_id, $this->comment->comment_post_ID ) );
$avatar_size = apply_filters( 'liveblog_entry_avatar_size', self::default_avatar_size );
$css_classes = implode( ' ', get_comment_class( '', $entry_id, $this->comment->comment_post_ID ) );
$share_link = get_permalink( $this->get_post_id() ) . '#' . $entry_id;
$entry = array(
'id' => $entry_id,
'type' => $this->get_type(),
Expand All @@ -108,6 +109,7 @@ public function for_json() {
'avatar_img' => get_avatar( $this->comment->comment_author_email, $avatar_size ),
'author_link' => get_comment_author_link( $entry_id ),
'entry_time' => get_comment_date( 'U', $entry_id ),
'share_link' => $share_link,
);
$entry = apply_filters( 'liveblog_entry_for_json', $entry, $this );
return (object) $entry;
Expand Down
3 changes: 2 additions & 1 deletion src/react/actions/apiActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import types from './actionTypes';

export const getEntries = page => ({
export const getEntries = (page, hash = false) => ({
type: types.GET_ENTRIES,
page,
hash,
});

export const getEntriesPaginated = (page, scrollTo) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/react/containers/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AppContainer extends Component {
componentDidMount() {
const { loadConfig, getEntries, getEvents, startPolling } = this.props;
loadConfig(window.liveblog_settings);
getEntries(1);
getEntries(1, window.location.hash);
startPolling();
if (this.eventsContainer) getEvents();
}
Expand Down
4 changes: 2 additions & 2 deletions src/react/containers/EntryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class EntryContainer extends Component {
className={`liveblog-entry ${entry.key_event ? 'is-key-event' : ''} ${entry.css_classes}`}
>
<header className="liveblog-meta">
<div className="liveblog-meta-time">
<a className="liveblog-meta-time" href={entry.share_link} target="_blank">
<span>{timeAgo(entry.entry_time)}</span>
<span>{formattedTime(entry.entry_time)}</span>
</div>
</a>
<div className="liveblog-meta-author">
<div
className="liveblog-meta-authour-avatar"
Expand Down
22 changes: 18 additions & 4 deletions src/react/epics/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
deleteEntryFailed,
} from '../actions/apiActions';

import {
jumpToEvent,
} from '../actions/eventsActions';

import {
getEntries,
createEntry,
Expand All @@ -36,8 +40,18 @@ import {

const getEntriesEpic = (action$, store) =>
action$.ofType(types.GET_ENTRIES)
.switchMap(({ page }) =>
getEntries(page, store.getState().config, store.getState().api.newestEntry)
.switchMap(({ page, hash }) => {
/**
* If there is a has in the url, we check that it is a number
* and then we jump to the that entry. If the number isn't a valid
* id of an entry the jumpToEvent api will return the first page.
*/
if (hash) {
const id = hash.split('#')[1];
if (!isNaN(id)) return of(jumpToEvent(id));
}

return getEntries(page, store.getState().config, store.getState().api.newestEntry)
.timeout(10000)
.map(res =>
getEntriesSuccess(
Expand All @@ -49,8 +63,8 @@ const getEntriesEpic = (action$, store) =>
),
),
)
.catch(error => of(getEntriesFailed(error))),
);
.catch(error => of(getEntriesFailed(error)));
});

const getPaginatedEntriesEpic = (action$, store) =>
action$.ofType(types.GET_ENTRIES_PAGINATED)
Expand Down
11 changes: 7 additions & 4 deletions src/react/epics/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ const jumpToEventEpic = (action$, store) =>
.switchMap(({ payload }) =>
jumpToEvent(payload, store.getState().config, store.getState().api.newestEntry)
.timeout(10000)
.flatMap(res =>
concat(
.flatMap((res) => {
if (!res.response.entries.some(x => x.id === payload)) {
return of(getEntriesSuccess(res.response));
}
return concat(
of(getEntriesSuccess(res.response)),
of(scrollToEntry(`id_${payload}`)),
),
)
);
})
.catch(error => of(getEntriesFailed(error))),
);

Expand Down
9 changes: 9 additions & 0 deletions src/react/reducers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ export const api = (state = initialState, action) => {
},
};

case 'LOAD_CONFIG':
return {
...state,
newestEntry: {
id: action.payload.latest_entry_id,
timestamp: parseInt(action.payload.latest_entry_timestamp, 10),
},
};

default:
return state;
}
Expand Down
9 changes: 9 additions & 0 deletions src/react/reducers/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export const polling = (state = initialState, action) => {
entries: {},
};

case 'LOAD_CONFIG':
return {
...state,
newestEntry: {
id: action.payload.latest_entry_id,
timestamp: parseInt(action.payload.latest_entry_timestamp, 10),
},
};

default:
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions src/styles/core/app/_entry.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
display: flex;
flex-wrap: nowrap;
align-items: flex-start;
text-decoration: none;
}

.liveblog-meta-time {
display: block;
}

.liveblog-meta-time span {
Expand Down