opt
This commit is contained in:
parent
e099423688
commit
ac3baf77a1
|
|
@ -1,20 +1,20 @@
|
||||||
// Modules
|
// Modules
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
import { Dispatch, SetStateAction } from "react";
|
import { Dispatch, SetStateAction } from 'react';
|
||||||
import { DispatchProp, useSelector } from "react-redux";
|
import { DispatchProp, useSelector } from 'react-redux';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { IurlParamAdder } from "../types/api.types";
|
import { IurlParamAdder } from '../types/api.types';
|
||||||
import { RootState } from "../types/store.types";
|
import { RootState } from '../types/store.types';
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
import { urlParamAdder } from "../helpers/urlParamAdder";
|
import { urlParamAdder } from '../helpers/urlParamAdder';
|
||||||
|
|
||||||
export class Api {
|
export class Api {
|
||||||
private url: string = "";
|
private url: string = '';
|
||||||
private params?: IurlParamAdder[];
|
private params?: IurlParamAdder[];
|
||||||
public language = useSelector<RootState, RootState["language"]["title"]>(
|
public language = useSelector<RootState, RootState['language']['title']>(
|
||||||
(state) => state.language.title
|
(state) => state.language.title,
|
||||||
);
|
);
|
||||||
|
|
||||||
constructor(url: string, params?: IurlParamAdder[]) {
|
constructor(url: string, params?: IurlParamAdder[]) {
|
||||||
|
|
@ -23,13 +23,7 @@ export class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
get(state: any, setState: Dispatch<SetStateAction<any>>) {
|
get(state: any, setState: Dispatch<SetStateAction<any>>) {
|
||||||
const locale = { name: "locale", value: this.language };
|
const locale = { name: 'locale', value: this.language };
|
||||||
if (
|
|
||||||
this.url.match(
|
|
||||||
"^(http(s)://.)[-a-zA-Z0-9@:%._+~#=]{2,256}.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
throw new Error("Bad URL");
|
|
||||||
axios
|
axios
|
||||||
.get(urlParamAdder(locale, this.url, this.params))
|
.get(urlParamAdder(locale, this.url, this.params))
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,37 @@
|
||||||
// Modules
|
// Modules
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from 'react';
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import News from "../news/News";
|
import News from '../news/News';
|
||||||
import SectionTitle from "./SectionTitle";
|
import SectionTitle from './SectionTitle';
|
||||||
import Loader from "./Loader";
|
import Loader from './Loader';
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
import { url } from "../../url";
|
import { url } from '../../url';
|
||||||
import { Api } from "../../api/Api";
|
import { Api } from '../../api/Api';
|
||||||
import { newsScrollParams } from "../../api/params";
|
import { newsScrollParams } from '../../api/params';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { IPostsData } from "../../types/data.types";
|
import { IPostsData } from '../../types/data.types';
|
||||||
import { RootState } from "../../types/store.types";
|
import { RootState } from '../../types/store.types';
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import { setNewsScroll } from "../../actions/setData";
|
import { setNewsScroll } from '../../actions/setData';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: boolean;
|
title: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NewsScroll = ({ title }: Props) => {
|
const NewsScroll = ({ title }: Props) => {
|
||||||
const api = new Api(url + "/posts", newsScrollParams);
|
const api = new Api(url + '/posts', newsScrollParams);
|
||||||
const language = api.language;
|
const language = api.language;
|
||||||
const [lastLanguage, setLastLanguage] = useState<string>(language);
|
const [lastLanguage, setLastLanguage] = useState<string>(language);
|
||||||
|
|
||||||
// redux
|
// redux
|
||||||
const data = useSelector<RootState, RootState["newsScroll"]["data"]>(
|
const data = useSelector<RootState, RootState['newsScroll']['data']>(
|
||||||
(state) => state.newsScroll.data
|
(state) => state.newsScroll.data,
|
||||||
);
|
);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
|
@ -47,13 +47,10 @@ const NewsScroll = ({ title }: Props) => {
|
||||||
<SectionTitle title="Лента новостей" />
|
<SectionTitle title="Лента новостей" />
|
||||||
<div className="news-scroll-wrapper">
|
<div className="news-scroll-wrapper">
|
||||||
{title === true ? (
|
{title === true ? (
|
||||||
<SectionTitle
|
<SectionTitle title="Лента новостей" linkData={{ link: '/', title: 'Посмотреть все' }} />
|
||||||
title="Лента новостей"
|
|
||||||
linkData={{ link: "/", title: "Посмотреть все" }}
|
|
||||||
/>
|
|
||||||
) : null}
|
) : null}
|
||||||
<div className="news-scroll-inner">
|
<div className="news-scroll-inner">
|
||||||
{data ? (
|
{(data as IPostsData[])[0].id > -1 ? (
|
||||||
(data as IPostsData[]).map((dataEl) => {
|
(data as IPostsData[]).map((dataEl) => {
|
||||||
return (
|
return (
|
||||||
<News
|
<News
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
// Modules
|
// Modules
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from 'react-router-dom';
|
||||||
import { LazyLoadImage } from "react-lazy-load-image-component";
|
import { LazyLoadImage } from 'react-lazy-load-image-component';
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
// Images
|
|
||||||
import { ReactComponent as ArrRight } from "../../assets/icons/arrow-right.svg";
|
|
||||||
// Components
|
// Components
|
||||||
import NewsCategory from "../global/NewsCategory";
|
import NewsCategory from '../global/NewsCategory';
|
||||||
import NewsDate from "../global/NewsDate";
|
import NewsDate from '../global/NewsDate';
|
||||||
import { IPostsData } from "../../types/data.types";
|
import { IPostsData } from '../../types/data.types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id: IPostsData["id"];
|
id: IPostsData['id'];
|
||||||
title: IPostsData["title"];
|
title: IPostsData['title'];
|
||||||
text: IPostsData["content_html"];
|
text: IPostsData['content_html'];
|
||||||
categories: IPostsData["categories"];
|
categories: IPostsData['categories'];
|
||||||
date: IPostsData["published_at"];
|
date: IPostsData['published_at'];
|
||||||
img: IPostsData["featured_images"][0]["path"];
|
img: IPostsData['featured_images'][0]['path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const News = ({ id, title, text, categories, date, img }: Props) => {
|
const News = ({ id, title, text, categories, date, img }: Props) => {
|
||||||
|
|
@ -23,12 +22,7 @@ const News = ({ id, title, text, categories, date, img }: Props) => {
|
||||||
<div className="news">
|
<div className="news">
|
||||||
<div className="news-wrapper">
|
<div className="news-wrapper">
|
||||||
<Link to={`/news/${id}`} className="news-image">
|
<Link to={`/news/${id}`} className="news-image">
|
||||||
<LazyLoadImage
|
<LazyLoadImage src={img} alt="image" useIntersectionObserver effect="blur" />
|
||||||
src={img}
|
|
||||||
alt="image"
|
|
||||||
useIntersectionObserver
|
|
||||||
effect="blur"
|
|
||||||
/>
|
|
||||||
</Link>
|
</Link>
|
||||||
<div className="news-info">
|
<div className="news-info">
|
||||||
<div className="news-info-inner">
|
<div className="news-info-inner">
|
||||||
|
|
@ -38,23 +32,14 @@ const News = ({ id, title, text, categories, date, img }: Props) => {
|
||||||
<div className="news-status">
|
<div className="news-status">
|
||||||
<div className="news-status-left">
|
<div className="news-status-left">
|
||||||
{categories.map((category) => {
|
{categories.map((category) => {
|
||||||
return (
|
return <NewsCategory key={uuidv4()} title={category.name} id={category.id} />;
|
||||||
<NewsCategory
|
|
||||||
key={uuidv4()}
|
|
||||||
title={category.name}
|
|
||||||
id={category.id}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="news-status-right">
|
<div className="news-status-right">
|
||||||
<NewsDate date={date} />
|
<NewsDate date={date} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div className="news-text" dangerouslySetInnerHTML={{ __html: text }}></div>
|
||||||
className="news-text"
|
|
||||||
dangerouslySetInnerHTML={{ __html: text }}
|
|
||||||
></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue