render tag

This commit is contained in:
Sergey Yarkov 2020-07-06 22:45:20 +03:00
parent 11d7f91fdc
commit bd45a806f9
4 changed files with 23 additions and 16 deletions

View File

@ -1,12 +1,16 @@
import React from 'react'; import React from 'react';
import useTagsQuery from '../../hooks/useTagsQuery'
import './Offers.scss' import './Offers.scss'
import Tags from './Tags/Tags' import Tags from './Tags/Tags'
import TagItem from './Tags/TagItem'
import PopularIcon from '../../images/popular-icon.svg' import PopularIcon from '../../images/popular-icon.svg'
import ViewsIcon from '../../images/views-icon.svg' import ViewsIcon from '../../images/views-icon.svg'
import BooksIcon from '../../images/books-icon.svg' import BooksIcon from '../../images/books-icon.svg'
const Offers = () => { const Offers = () => {
const { tags } = useTagsQuery()
return ( return (
<div className="offers"> <div className="offers">
<div className="offers-popular offer-box"> <div className="offers-popular offer-box">
@ -25,7 +29,9 @@ const Offers = () => {
</div>)} </div>)}
</div> </div>
</div> </div>
<Tags /> <Tags>
{tags.map(({ node }, i) => <TagItem key={i} title={node.frontmatter.title} />)}
</Tags>
<div className="offers-books offer-box"> <div className="offers-books offer-box">
<div className="offers-books__heading offer-heading"> <div className="offers-books__heading offer-heading">
<BooksIcon /> <BooksIcon />

View File

@ -0,0 +1,13 @@
import React from 'react';
import { Link } from 'gatsby'
import sligify from '../../../helpers/slugify'
const TagItem = ({ title }) => {
return (
<div className="tag-item">
<Link to={`/tag/${sligify(title)}`}>{title}</Link>
</div>
)
}
export default TagItem

View File

@ -1,20 +1,8 @@
import React from 'react' import React from 'react'
import { Link } from 'gatsby'
import sligify from '../../../helpers/slugify'
import useTagsQuery from '../../../hooks/useTagsQuery'
import TagIcon from '../../../images/tag-icon.svg' import TagIcon from '../../../images/tag-icon.svg'
const TagItem = ({ title }) => { const Tags = ({ children }) => {
return (
<div className="tag-item">
<Link to={`/tag/${sligify(title)}`}>{title}</Link>
</div>
)
}
const Tags = () => {
const { edges } = useTagsQuery()
return ( return (
<div className="offers-tags offer-box"> <div className="offers-tags offer-box">
@ -23,7 +11,7 @@ const Tags = () => {
Тэги Тэги
</div> </div>
<div className="offers-tags__content"> <div className="offers-tags__content">
{edges.map(({ node }, i) => <TagItem key={i} title={node.frontmatter.title} />)} {children}
</div> </div>
</div> </div>
) )

View File

@ -14,7 +14,7 @@ const useTagsQuery = () => {
} }
} }
`) `)
return { edges } return { tags: edges }
} }
export default useTagsQuery export default useTagsQuery