Skip to content

Commit

Permalink
Merge pull request steemit#2705 from kirkins/filter
Browse files Browse the repository at this point in the history
filter non-string tags
  • Loading branch information
bnchdrff authored Apr 12, 2018
2 parents 9b1b32d + 20f31c3 commit 7fa0663
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/app/components/elements/TagList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Link } from 'react-router';
import { filterTags } from 'app/utils/StateFunctions';
import DropdownMenu from 'app/components/elements/DropdownMenu';

export default ({ post, horizontal, single }) => {
Expand Down Expand Up @@ -32,10 +33,7 @@ export default ({ post, horizontal, single }) => {
// Category should always be first.
tags.unshift(post.category);

// Uniqueness filter.
tags = tags.filter(
(value, index, self) => value && self.indexOf(value) === index
);
tags = filterTags(tags);

if (horizontal) {
// show it as a dropdown in Preview
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/pages/TagsIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Link } from 'react-router';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import { numberWithCommas } from 'app/utils/StateFunctions';
import { filterTags, numberWithCommas } from 'app/utils/StateFunctions';
import tt from 'counterpart';

export default class TagsIndex extends React.Component {
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class TagsIndex extends React.Component {
const { tagsAll } = this.props;
//console.log('-- TagsIndex.render -->', tagsAll.toJS());
const { order } = this.state;
let tags = tagsAll;
let tags = filterTags(tagsAll);

const rows = tags
.filter(
Expand Down
7 changes: 7 additions & 0 deletions src/app/utils/StateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export function contentStats(content) {
tags = [];
}
tags.push(content.get('category'));
tags = filterTags(tags);
const isNsfw = tags.filter(tag => tag && tag.match(/^nsfw$/i)).length > 0;

return {
Expand All @@ -189,3 +190,9 @@ export function contentStats(content) {
hasPendingPayout,
};
}

export function filterTags(tags) {
return tags
.filter(tag => typeof tag === 'string')
.filter((value, index, self) => value && self.indexOf(value) === index);
}

0 comments on commit 7fa0663

Please sign in to comment.