[MM-9216] Add date separator per search result item (#1583)

* add date separator per search result item

* rebase to latest and make each post of recent, flagged and search results have date separator
This commit is contained in:
Saturnino Abril 2018-04-14 01:30:15 +08:00 committed by Harrison Healey
parent e31fc00377
commit 2092d778f0
2 changed files with 3 additions and 20 deletions

View file

@ -24,6 +24,7 @@ import DateHeader from 'app/components/post_list/date_header';
import FormattedText from 'app/components/formatted_text';
import Loading from 'app/components/loading';
import PostListRetry from 'app/components/post_list_retry';
import PostSeparator from 'app/components/post_separator';
import SafeAreaView from 'app/components/safe_area_view';
import SearchBar from 'app/components/search_bar';
import StatusBar from 'app/components/status_bar';
@ -325,7 +326,7 @@ export default class Search extends PureComponent {
let separator;
const nextPost = postIds[index + 1];
if (nextPost && nextPost.indexOf(DATE_LINE) === -1) {
separator = this.renderPostSeparator();
separator = <PostSeparator theme={theme}/>;
}
return (
@ -355,17 +356,6 @@ export default class Search extends PureComponent {
);
};
renderPostSeparator = () => {
const {theme} = this.props;
const style = getStyleFromTheme(theme);
return (
<View style={[style.separatorContainer, style.postsSeparator]}>
<View style={style.separator}/>
</View>
);
};
renderSectionHeader = ({section}) => {
const {theme} = this.props;
const {title} = section;

View file

@ -93,7 +93,6 @@ export function makePreparePostIdsForSearchPosts() {
}
const out = [];
let lastDate = null;
for (let i = 0; i < posts.length; i++) {
const post = posts[i];
@ -106,17 +105,11 @@ export function makePreparePostIdsForSearchPosts() {
continue;
}
// Push on a date header if the last post was on a different day than the current one
const postDate = new Date(post.create_at);
if (!lastDate || lastDate.toDateString() !== postDate.toDateString()) {
out.push(DATE_LINE + postDate.toString());
lastDate = postDate;
}
out.push(post.id);
out.push(DATE_LINE + postDate.toString(), post.id);
}
// Flip it back to newest to oldest
return out;
}
);