Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement 139 blog fsd #190

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 23 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 14 additions & 26 deletions src/components/BlogMain/BlogMain.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

К этому компоненту такой же вопрос

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот компонент почему остался в components?
Он используется?

Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import { FC, useState } from 'react'
import BlogItemForContainer from '../BlogItemForContainer/BlogItemForContainer'
import BlogItemForContainer from '@/entities/BlogItemForContainer/BlogItemForContainer'
import type { PropsBlog } from '@/models/PropsBlog'
import BlogTags from '../BlogTags/BlogTags'
import BlogCategories from '../BlogCategories/BlogCategories'
import BlogTags from '@/entities/BlogTags/BlogTags'
import BlogCategories from '@/entities/BlogCategories/BlogCategories'
import WrapperForMainContent from '../WrapperForMainContent/WrapperForMainContent'
import BlogMainItem from '../BlogMainItem/BlogMainItem'
import BlogMainItem from '@/entities/BlogMainItem/BlogMainItem'
import { Pagination } from '../Pagination/Pagination'
import Heading from '@/shared/ui/Heading/Heading'
import Subheading from '@/shared/ui/Subheading/Subheading'
import styles from './blog-main.module.scss'
/*import { TBlogItem } from '@/models/BlogItemModel'*/

const BlogMain: FC<PropsBlog> = props => {
const { cards } = props
const [items, setItems] = useState(cards)
const [itemNumber, setItemNumber] = useState(9)
const [currentPage, setCurrentPage] = useState(1)
const TOTAL_PAGES: number = Math.ceil(items.length / itemNumber)
const filterCategories = (curcat?: string) => {
const newItems = cards.filter(newVal => {
return newVal.category === curcat
// comparing category for displaying data
})
setItems(newItems)
}

const filterTags = (curcat: string) => {
const newItems = cards.filter(newVal => {
return newVal.tags.includes(curcat)
// comparing category for displaying data
})
setItems(newItems)
}

const TOTAL_PAGES: number = Math.ceil(cards.length / itemNumber)
console.log(setItems)
const handlePageChange = (pageNumber: number) => {
// Handle page change logic here
setCurrentPage(pageNumber)
Expand All @@ -51,15 +37,17 @@ const BlogMain: FC<PropsBlog> = props => {
</div>
<div className={styles.blog__wrapper}>
<div className={styles.blog__filters}>
<BlogCategories cards={cards} filterItems={filterCategories} />
<BlogTags cards={cards} filterItems={filterTags} />
<BlogCategories cards={cards} />
<BlogTags cards={cards} />
</div>
<section className={styles.wrapper}>
<BlogMainItem />
<ul>
{items.slice(currentPage == 1 ? 0 : itemNumber * (currentPage - 1), itemNumber * currentPage).map(item => (
<BlogItemForContainer key={item.id} card={item} />
))}
{items
.slice(currentPage == 1 ? 0 : itemNumber * (currentPage - 1), itemNumber * currentPage)
.map(item => (
<BlogItemForContainer key={item.id} card={item} />
))}
</ul>
</section>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import styles from './blog-categories.module.scss'
import { FC, useMemo } from 'react'
import type { PropsCategories } from '@/models/PropsBlog'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'
import Paragraph from '@/shared/ui/Paragraph/Paragraph'
import { TBlogItem } from '@/models/BlogItemModel'

const BlogCategories: FC<PropsCategories> = props => {
const { cards, filterItems } = props
const { cards } = props

const cat = useMemo(
() =>
Expand All @@ -15,7 +17,7 @@ const BlogCategories: FC<PropsCategories> = props => {
)

const result: {
key?: string
key: string
count: number
}[] = []
// Create a unique list of items to loop over
Expand All @@ -40,16 +42,24 @@ const BlogCategories: FC<PropsCategories> = props => {
key={item.key}
className={styles.cats__item}
onClick={() => {
filterItems(item.key)
filterCategories(item.key, cards)
}}>
{item.key}
<p className={styles.cats__count}>{item.count}</p>
<Paragraph className={styles.cats__count}>{item.count}</Paragraph>
</button>
)
}),
[[...new Set(cat)]]
)

const filterCategories = (curcat: string, cards: TBlogItem[]) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эту функцию можно вынести из компонента в utils

const newItems = cards.filter(newVal => {
return newVal.category === curcat
// comparing category for displaying data
})
return newItems
}

return (
<div className={styles.cats}>
<section className={styles.cats__container}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ViewIcon from '@/assets/images/blogMainItem/icon-views.svg'
import CommentIcon from '@/assets/images/blogMainItem/icon-comments.svg'
import { fromSS } from '@/shared/constants/constants'
import Link from '@/shared/ui/Link/Link'
import Paragraph from '@/shared/ui/Paragraph/Paragraph'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'

export type Props = {
card: TBlogItem
Expand All @@ -17,9 +19,9 @@ const BlogItemForContainer: FC<Props> = props => {
() =>
card.tags.map(item => {
return (
<p className={styles.card__tag} key={item}>
<Paragraph className={styles.card__tag} key={item}>
{item}
</p>
</Paragraph>
)
}),
[]
Expand All @@ -29,14 +31,14 @@ const BlogItemForContainer: FC<Props> = props => {
<Link to={''} className={styles.card}>
<img src={card.src} alt={card.alt} draggable="false" className={styles.card__im} />
<div className={styles.card__tags}>{tags}</div>
<h3>{card.title || ''}</h3>
<Heading type={HeadingType.NORMAL}>{card.title || ''}</Heading>
<div className={styles.card__info}>
<p className={styles.card__icons}>
<Paragraph className={styles.card__icons}>
<ViewIcon className={styles['card__icon']} /> {fromSS}
</p>
<p className={styles.card__icons}>
</Paragraph>
<Paragraph className={styles.card__icons}>
<CommentIcon className={styles['card__icon']} /> {card.comments.length}
</p>
</Paragraph>
</div>
<span>{card.date || ''}</span>
{card.promo ? <span className={styles.promo}>{TEXT_PROMO}</span> : null}
Expand Down
Loading
Loading