mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
tag fixes
This commit is contained in:
parent
74dccbc76f
commit
0d93d7e672
@ -1,7 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Link } from 'gatsby'
|
import { Link } from 'gatsby'
|
||||||
import shortid from 'shortid'
|
import shortid from 'shortid'
|
||||||
import slugify from 'slugify'
|
|
||||||
import styles from './Tags.module.css'
|
import styles from './Tags.module.css'
|
||||||
|
|
||||||
declare type TagsProps = {
|
declare type TagsProps = {
|
||||||
@ -13,15 +12,11 @@ declare type TagsProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Tag = ({ tag, noLinks }: { tag: string; noLinks?: boolean }) => {
|
const Tag = ({ tag, noLinks }: { tag: string; noLinks?: boolean }) => {
|
||||||
// TODO: we should slugify all tags upon publish, so only
|
|
||||||
// slug-style tags should be allowed.
|
|
||||||
const cleanTag = slugify(tag).toLowerCase()
|
|
||||||
|
|
||||||
return noLinks ? (
|
return noLinks ? (
|
||||||
<span className={styles.tag}>{cleanTag}</span>
|
<span className={styles.tag}>{tag}</span>
|
||||||
) : (
|
) : (
|
||||||
<Link to={`/search?tags=${tag}`} className={styles.tag} title={cleanTag}>
|
<Link to={`/search?tags=${tag}`} className={styles.tag} title={tag}>
|
||||||
{cleanTag}
|
{tag}
|
||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -35,7 +30,8 @@ const Tags: React.FC<TagsProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
max = max || items.length
|
max = max || items.length
|
||||||
const remainder = items.length - max
|
const remainder = items.length - max
|
||||||
const tags = items.slice(0, max)
|
// filter out empty array items, and restrict to `max`
|
||||||
|
const tags = items.filter((tag) => tag !== '').slice(0, max)
|
||||||
const shouldShowMore = showMore && remainder > 0
|
const shouldShowMore = showMore && remainder > 0
|
||||||
const classes = className ? `${styles.tags} ${className}` : styles.tags
|
const classes = className ? `${styles.tags} ${className}` : styles.tags
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import styles from './Preview.module.css'
|
|||||||
import File from '../../atoms/File'
|
import File from '../../atoms/File'
|
||||||
import { MetadataPublishForm } from '../../../@types/MetaData'
|
import { MetadataPublishForm } from '../../../@types/MetaData'
|
||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
|
import { transformTags } from './utils'
|
||||||
|
|
||||||
export default function Preview({
|
export default function Preview({
|
||||||
values
|
values
|
||||||
@ -72,7 +73,7 @@ export default function Preview({
|
|||||||
Download Sample
|
Download Sample
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{values.tags && <Tags items={values.tags.split(',')} />}
|
{values.tags && <Tags items={transformTags(values.tags)} />}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div className={styles.metaFull}>
|
<div className={styles.metaFull}>
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
import { MetadataMarket, MetadataPublishForm } from '../../../@types/MetaData'
|
import { MetadataMarket, MetadataPublishForm } from '../../../@types/MetaData'
|
||||||
import { toStringNoMS } from '../../../utils'
|
import { toStringNoMS } from '../../../utils'
|
||||||
import AssetModel from '../../../models/Asset'
|
import AssetModel from '../../../models/Asset'
|
||||||
|
import slugify from '@sindresorhus/slugify'
|
||||||
|
|
||||||
|
export function transformTags(value: string): string[] {
|
||||||
|
const originalTags = value?.split(',')
|
||||||
|
const transformedTags = originalTags?.map((tag) => slugify(tag).toLowerCase())
|
||||||
|
return transformedTags
|
||||||
|
}
|
||||||
|
|
||||||
export function transformPublishFormToMetadata(
|
export function transformPublishFormToMetadata(
|
||||||
data: Partial<MetadataPublishForm>
|
data: Partial<MetadataPublishForm>
|
||||||
@ -33,7 +40,7 @@ export function transformPublishFormToMetadata(
|
|||||||
...AssetModel.additionalInformation,
|
...AssetModel.additionalInformation,
|
||||||
description,
|
description,
|
||||||
copyrightHolder,
|
copyrightHolder,
|
||||||
tags: tags?.split(','),
|
tags: transformTags(tags),
|
||||||
links: typeof links !== 'string' && links,
|
links: typeof links !== 'string' && links,
|
||||||
termsAndConditions
|
termsAndConditions
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user