mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
Refactor isFeatured / isTagged
This commit is contained in:
@@ -166,3 +166,4 @@ export function insertCommentsSorted(nodes, comments, sortOrder = 'CHRONOLOGICAL
|
||||
throw new Error(`Unknown sort order ${sortOrder}`);
|
||||
}
|
||||
|
||||
export const isTagged = (tags, which) => tags.some((t) => t.tag.name === which);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {capitalize} from 'coral-framework/helpers/strings';
|
||||
import withMutation from 'coral-framework/hocs/withMutation';
|
||||
import withFragments from 'coral-framework/hocs/withFragments';
|
||||
import {addNotification} from 'coral-framework/actions/notification';
|
||||
import {forEachError} from 'coral-framework/utils';
|
||||
import {forEachError, isTagged} from 'coral-framework/utils';
|
||||
|
||||
export default (tag) => (WrappedComponent) => {
|
||||
if (typeof tag !== 'string') {
|
||||
@@ -28,9 +28,6 @@ export default (tag) => (WrappedComponent) => {
|
||||
}
|
||||
`;
|
||||
|
||||
const isTagged = (tags) =>
|
||||
!!tags.filter((t) => t.tag.name === Tag.toUpperCase()).length;
|
||||
|
||||
const withAddTag = withMutation(
|
||||
gql`
|
||||
mutation AddTag($id: ID!, $asset_id: ID!, $name: String!) {
|
||||
@@ -163,7 +160,7 @@ export default (tag) => (WrappedComponent) => {
|
||||
render() {
|
||||
const {comment} = this.props;
|
||||
|
||||
const alreadyTagged = isTagged(comment.tags);
|
||||
const alreadyTagged = isTagged(comment.tags, Tag.toUpperCase());
|
||||
|
||||
return <WrappedComponent
|
||||
user={this.props.user}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export {insertCommentsSorted} from 'coral-framework/utils';
|
||||
export {isTagged, insertCommentsSorted} from 'coral-framework/utils';
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import React from 'react';
|
||||
import styles from './styles.css';
|
||||
import {t} from 'plugin-api/beta/client/services';
|
||||
|
||||
const isOffTopic = (tags) => !!tags.filter((t) => t.tag.name === 'OFF_TOPIC').length;
|
||||
import {isTagged} from 'plugin-api/beta/client/utils';
|
||||
|
||||
export default (props) => (
|
||||
<span>
|
||||
{
|
||||
isOffTopic(props.comment.tags) && props.depth === 0 ? (
|
||||
isTagged(props.comment.tags, 'OFF_TOPIC') && props.depth === 0 ? (
|
||||
<span className={styles.tag}>
|
||||
{t('off_topic')}
|
||||
</span>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import React from 'react';
|
||||
import styles from './FeaturedTag.css';
|
||||
import {t} from 'plugin-api/beta/client/services';
|
||||
|
||||
const isFeatured = (tags) => !!tags.filter((t) => t.tag.name === 'FEATURED').length;
|
||||
import {isTagged} from 'plugin-api/beta/client/utils';
|
||||
|
||||
export default (props) => (
|
||||
<span>
|
||||
{
|
||||
isFeatured(props.comment.tags) && props.depth === 0 ? (
|
||||
isTagged(props.comment.tags, 'FEATURED') && props.depth === 0 ? (
|
||||
<span className={styles.tag}>
|
||||
{t('featured')}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user