Skip to content

Commit

Permalink
add filter methed to filterObj and index description
Browse files Browse the repository at this point in the history
  • Loading branch information
GoreStarry committed Mar 26, 2018
1 parent 711bf47 commit c44853c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ducks/articleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ let isInCooldown = false;
let lastStringifiedFilter;
export const load = ({
q,
searchUserByArticleId,
filter = 'unsolved',
replyRequestCount = 2,
orderBy = 'createdAt',
before,
after,
}) => dispatch => {
const filterObject = getFilterObject(filter, q, replyRequestCount);
const filterObject = getFilterObject(
filter,
q,
replyRequestCount,
searchUserByArticleId
);
const stringifiedFilter = JSON.stringify(filterObject);

if (lastStringifiedFilter !== stringifiedFilter) {
Expand Down Expand Up @@ -207,7 +213,7 @@ function resetCooldown() {
isInCooldown = false;
}

function getFilterObject(filter, q, replyRequestCount) {
function getFilterObject(filter, q, replyRequestCount, searchUserByArticleId) {
const filterObj = {};
if (q) {
filterObj.moreLikeThis = { like: q, minimumShouldMatch: '0' };
Expand All @@ -223,6 +229,10 @@ function getFilterObject(filter, q, replyRequestCount) {
filterObj.replyCount = { EQ: 0 };
}

if (searchUserByArticleId) {
filterObj.fromUserOfArticleId = searchUserByArticleId;
}

// Return filterObj only when it is populated.
if (!Object.keys(filterObj).length) {
return undefined;
Expand Down
31 changes: 30 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ class Index extends ListPage {
);
};

renderDescriptionOfSearchedArticle = () => {
const { query: { searchUserByArticleId }, articles } = this.props;
const searchedArticle = articles.find(
article => article.get('id') === searchUserByArticleId
);
return (
<span>
<mark>{searchedArticle ? searchedArticle.get('text') : ''}</mark>{' '}
此篇文章相同回報者的列表
<style jsx>{`
mark {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
max-width: 15em;
display: inline-block;
vertical-align: bottom;
}
`}</style>
</span>
);
};

renderOrderBy = () => {
const { query: { orderBy, q } } = this.props;
if (q) {
Expand Down Expand Up @@ -207,14 +230,20 @@ class Index extends ListPage {
};

render() {
const { isLoading = false, query: { replyRequestCount } } = this.props;
const {
isLoading = false,
query: { replyRequestCount, searchUserByArticleId },
} = this.props;

return (
<main>
<Head>
<title>Cofacts 真的假的 - 轉傳訊息查證</title>
</Head>
<h2>文章列表</h2>
<h3>
{searchUserByArticleId && this.renderDescriptionOfSearchedArticle()}
</h3>
{this.renderSearch()}
<br />
Order By:
Expand Down

0 comments on commit c44853c

Please sign in to comment.