#4967 Fixed issue of post not getting updated after edit, if the post was focused. (#5149)

Этот коммит содержится в:
Debanshu Kundu
2017-01-25 17:48:35 +05:30
коммит произвёл Joram Wilander
родитель 88ce5d363c
Коммит 7bcea832cd
2 изменённых файлов: 21 добавлений и 10 удалений

Просмотреть файл

@@ -115,12 +115,16 @@ export function getFlaggedPosts() {
); );
} }
export function loadPosts(channelId = ChannelStore.getCurrentId()) { export function loadPosts(channelId = ChannelStore.getCurrentId(), isPost = false) {
const postList = PostStore.getAllPosts(channelId); const postList = PostStore.getAllPosts(channelId);
const latestPostTime = PostStore.getLatestPostFromPageTime(channelId); const latestPostTime = PostStore.getLatestPostFromPageTime(channelId);
if (!postList || Object.keys(postList).length === 0 || postList.order.length < Constants.POST_CHUNK_SIZE || latestPostTime === 0) { if (
loadPostsPage(channelId, Constants.POST_CHUNK_SIZE); !postList || Object.keys(postList).length === 0 ||
(!isPost && postList.order.length < Constants.POST_CHUNK_SIZE) ||
latestPostTime === 0
) {
loadPostsPage(channelId, Constants.POST_CHUNK_SIZE, isPost);
return; return;
} }
@@ -133,7 +137,8 @@ export function loadPosts(channelId = ChannelStore.getCurrentId()) {
id: channelId, id: channelId,
before: true, before: true,
numRequested: 0, numRequested: 0,
post_list: data post_list: data,
isPost
}); });
loadProfilesForPosts(data.posts); loadProfilesForPosts(data.posts);
@@ -145,7 +150,7 @@ export function loadPosts(channelId = ChannelStore.getCurrentId()) {
); );
} }
export function loadPostsPage(channelId = ChannelStore.getCurrentId(), max = Constants.POST_CHUNK_SIZE) { export function loadPostsPage(channelId = ChannelStore.getCurrentId(), max = Constants.POST_CHUNK_SIZE, isPost = false) {
const postList = PostStore.getAllPosts(channelId); const postList = PostStore.getAllPosts(channelId);
// if we already have more than POST_CHUNK_SIZE posts, // if we already have more than POST_CHUNK_SIZE posts,
@@ -168,7 +173,8 @@ export function loadPostsPage(channelId = ChannelStore.getCurrentId(), max = Con
numRequested: numPosts, numRequested: numPosts,
checkLatest: true, checkLatest: true,
checkEarliest: true, checkEarliest: true,
post_list: data post_list: data,
isPost
}); });
loadProfilesForPosts(data.posts); loadProfilesForPosts(data.posts);
@@ -365,11 +371,11 @@ export function createPost(post, doLoadPost, success, error) {
); );
} }
export function updatePost(post, success) { export function updatePost(post, success, isPost) {
Client.updatePost( Client.updatePost(
post, post,
() => { () => {
loadPosts(post.channel_id); loadPosts(post.channel_id, isPost);
if (success) { if (success) {
success(); success();

Просмотреть файл

@@ -93,7 +93,9 @@ export default class EditPostModal extends React.Component {
updatedPost, updatedPost,
() => { () => {
window.scrollTo(0, 0); window.scrollTo(0, 0);
}); },
Boolean(PostStore.getFocusedPostId()) // If there is focused post we need to update that post's store too.
);
$('#edit_post').modal('hide'); $('#edit_post').modal('hide');
} }
@@ -184,7 +186,10 @@ export default class EditPostModal extends React.Component {
onModalHide() { onModalHide() {
if (this.state.refocusId !== '') { if (this.state.refocusId !== '') {
setTimeout(() => { setTimeout(() => {
$(this.state.refocusId).get(0).focus(); const element = $(this.state.refocusId).get(0);
if (element) {
element.focus();
}
}); });
} }
} }