From a08485bd1b075225e28f77995a2fc8df95edb2a1 Mon Sep 17 00:00:00 2001 From: Kakabay Date: Tue, 7 Mar 2023 15:22:59 +0500 Subject: [PATCH] News scroll lang added --- src/components/global/NewsScroll.tsx | 91 +++++++++++++++------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/src/components/global/NewsScroll.tsx b/src/components/global/NewsScroll.tsx index d658d68..5b7ab35 100644 --- a/src/components/global/NewsScroll.tsx +++ b/src/components/global/NewsScroll.tsx @@ -1,26 +1,26 @@ // Modules -import { useEffect, useState } from "react"; -import { v4 as uuidv4 } from "uuid"; -import { useSelector, useDispatch } from "react-redux"; +import { useEffect, useState } from 'react'; +import { v4 as uuidv4 } from 'uuid'; +import { useSelector, useDispatch } from 'react-redux'; // Components -import News from "../news/News"; -import SectionTitle from "./SectionTitle"; -import Loader from "./Loader"; -import Pagination from "./Pagination"; +import News from '../news/News'; +import SectionTitle from './SectionTitle'; +import Loader from './Loader'; +import Pagination from './Pagination'; // Api -import { url } from "../../url"; -import { Api } from "../../api/Api"; -import { newsScrollParams } from "../../api/params"; +import { url } from '../../url'; +import { Api } from '../../api/Api'; +import { newsScrollParams } from '../../api/params'; // Types -import { IPostsData } from "../../types/data.types"; -import { RootState } from "../../types/store.types"; +import { IPostsData } from '../../types/data.types'; +import { RootState } from '../../types/store.types'; // Actions -import { setNewsScroll } from "../../actions/setData"; -import { INewPostsData } from "../../types/posts.types"; +import { setNewsScroll } from '../../actions/setData'; +import { INewPostsData } from '../../types/posts.types'; interface Props { title: boolean; @@ -31,16 +31,16 @@ interface Props { const NewsScroll = ({ title, category, count, avoidFirst }: Props) => { const params = newsScrollParams.slice(); - category ? params.push({ name: "category", value: category }) : null; + category ? params.push({ name: 'category', value: category }) : null; count ? (params[0].value = count) : null; - const api = new Api(url + "/pagination/posts", params); + const api = new Api(url + '/pagination/posts', params); const language = api.language; const [lastLanguage, setLastLanguage] = useState(language); // redux - const rawData = useSelector( - (state) => state.newsScroll.data + const rawData = useSelector( + (state) => state.newsScroll.data, ); const dispatch = useDispatch(); @@ -58,9 +58,9 @@ const NewsScroll = ({ title, category, count, avoidFirst }: Props) => { } }, [language, lastLanguage]); - const [filteredData, setFilteredData] = useState< - INewPostsData["data"]["data"] - >(rawData.data.data); + const [filteredData, setFilteredData] = useState( + rawData.data.data, + ); useEffect(() => { const filtered = rawData.data.data.filter((el, index) => { @@ -76,31 +76,23 @@ const NewsScroll = ({ title, category, count, avoidFirst }: Props) => {
{title === true ? ( ) : null}
{filteredData.length > 0 ? ( - (filteredData as INewPostsData["data"]["data"])[0].id > -1 ? ( - (filteredData as INewPostsData["data"]["data"]).map( - (dataEl, index) => { - if (avoidFirst) { - if (index > 0) { - return ( - - ); - } - } else { + (filteredData as INewPostsData['data']['data'])[0].id > -1 ? ( + (filteredData as INewPostsData['data']['data']).map((dataEl, index) => { + if (avoidFirst) { + if (index > 0) { return ( { /> ); } + } else { + return ( + + ); } - ) + }) ) : ( )