芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/Articles/Articles.jsx
"use client" import React, { useEffect, useState } from 'react' import { AiOutlineUnorderedList } from "react-icons/ai"; import { RiGridFill } from "react-icons/ri"; import { IoMdArrowDropright } from "react-icons/io"; import Breadcrumb from "@/Components/Breadcrumb/Breadcrumb"; import { GetAllArticlesApi } from "@/store/actions/campaign"; import ArticleCard from "@/Components/Cards/ArticleCard"; import Skeleton from "react-loading-skeleton"; import ArticleCardSkeleton from "@/Components/Skeleton/ArticleCardSkeleton"; import ArticleHorizonatalCard from "@/Components/Cards/ArticleHorizonatalCard"; import { translate } from "@/utils"; import { useDispatch, useSelector } from "react-redux"; import { languageData } from "@/store/reducer/languageSlice"; import { settingsData } from "@/store/reducer/settingsSlice"; import NoData from "@/Components/NoDataFound/NoData"; import { articlecachedataCategoryId, categoriesCacheData, getArticleId } from "@/store/reducer/momentSlice"; import Layout from '../Layout/Layout'; const Articles = () => { const dispatch = useDispatch(); const [isLoading, setIsLoading] = useState(false); const [expandedStates, setExpandedStates] = useState([]); const [grid, setGrid] = useState(false); const [getArticles, setGetArticles] = useState(); const [total, setTotal] = useState(); const lang = useSelector(languageData); const Categorydata = useSelector(categoriesCacheData); const ArticleCateId = useSelector(articlecachedataCategoryId); useEffect(() => { }, [ArticleCateId]) useEffect(() => { }, [lang]); useEffect(() => { }, [grid]); // GET ARTICLES useEffect(() => { setIsLoading(true); GetAllArticlesApi( "", ArticleCateId ? ArticleCateId : "", "", "", (response) => { const Articles = response.data; setTotal(response.total); setIsLoading(false); setGetArticles(Articles); getArticleId("") setExpandedStates(new Array(Articles.length).fill(false)); }, (error) => { console.log(error); } ); }, []); const SettingsData = useSelector(settingsData); const PlaceHolderImg = SettingsData?.web_placeholder_logo; const getArticleByCategory = (cateId) => { setIsLoading(true); GetAllArticlesApi( "", cateId, "", "", (response) => { const Articles = response.data; if (response.total) { setTotal(response.total); } else { setTotal("0"); } setIsLoading(false); setGetArticles(Articles); setExpandedStates(new Array(Articles.length).fill(false)); }, (error) => { console.log(error); } ); }; const getGeneralArticles = () => { setIsLoading(true); GetAllArticlesApi( "", "", "", "", (response) => { const Articles = response.data; setTotal(response.total); setIsLoading(false); setGetArticles(Articles); setExpandedStates(new Array(Articles.length).fill(false)); }, (error) => { console.log(error); } ); }; return (
{total ? ( <>
{total > 0 ? total : 0} {translate("articleFound")}
setGrid(true)}>
setGrid(false)}>
> ) : (
)} {getArticles && getArticles.length > 0 ? ( !grid ? ( // Row cards
{isLoading ? // Show skeleton loading when data is being fetched Array.from({ length: getArticles ? getArticles.length : 6 }).map((_, index) => (
)) : getArticles?.map((ele, index) => (
))}
) : (
{isLoading ? // Show skeleton loading when data is being fetched Array.from({ length: getArticles ? getArticles.length : 6 }).map((_, index) => (
)) : getArticles?.map((ele, index) => (
))}
) ) : (
)}
{translate("categories")}
{translate("General")}
{Categorydata && Categorydata.map((elem, index) => (
{elem.category}
{ getArticleByCategory(elem.id); }} />
))}
{/*
Popular Tags
apartment
modern
building
luxarious
real estate
Villa
*/}
) } export default Articles