Commit dff8066d authored by Phạm Quang Bảo's avatar Phạm Quang Bảo

Merge branch 'feat/loading' into 'develop'

update/feature loading content

See merge request !47
parents 1242be99 724f942d
...@@ -26,7 +26,7 @@ function Events() { ...@@ -26,7 +26,7 @@ function Events() {
<div className="flex flex-col md:flex-row gap-5"> <div className="flex flex-col md:flex-row gap-5">
{isLoading ? ( {isLoading ? (
<div className="container w-full h-[80vh] flex justify-center items-center"> <div className="flex flex-col justify-center items-center w-full min-h-[180px] sm:min-h-[220px] p-3">
<Spinner /> <Spinner />
</div> </div>
) : ( ) : (
......
...@@ -7,9 +7,10 @@ import Link from "next/link"; ...@@ -7,9 +7,10 @@ import Link from "next/link";
import { Swiper, SwiperSlide } from "swiper/react"; import { Swiper, SwiperSlide } from "swiper/react";
import { Autoplay, Grid } from "swiper/modules"; import { Autoplay, Grid } from "swiper/modules";
import BASE_URL from "@/links/index"; import BASE_URL from "@/links/index";
import { Spinner } from "@/components/ui/spinner";
function FeaturedNews() { function FeaturedNews() {
const { data } = useGetNews<GetNewsResponseType>( const { data, isLoading } = useGetNews<GetNewsResponseType>(
{ {
pageSize: '10', pageSize: '10',
} }
...@@ -26,7 +27,11 @@ function FeaturedNews() { ...@@ -26,7 +27,11 @@ function FeaturedNews() {
<div className="flex-1 h-px bg-linear-to-l from-transparent via-gray-300 to-gray-400"></div> <div className="flex-1 h-px bg-linear-to-l from-transparent via-gray-300 to-gray-400"></div>
</div> </div>
</div> </div>
{isLoading ? (
<div className="flex justify-center items-center w-full h-64">
<Spinner />
</div>
) : (
<Swiper <Swiper
modules={[Autoplay]} modules={[Autoplay]}
autoplay={{ delay: 4000, disableOnInteraction: false }} autoplay={{ delay: 4000, disableOnInteraction: false }}
...@@ -61,6 +66,7 @@ function FeaturedNews() { ...@@ -61,6 +66,7 @@ function FeaturedNews() {
</SwiperSlide> </SwiperSlide>
))} ))}
</Swiper> </Swiper>
)}
</section> </section>
); );
} }
......
...@@ -7,12 +7,13 @@ import { ChevronsRight } from "lucide-react"; ...@@ -7,12 +7,13 @@ import { ChevronsRight } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import stripImagesAndHtml from "@/helpers/stripImageAndHtml"; import stripImagesAndHtml from "@/helpers/stripImageAndHtml";
import CardNews from "./components/card-news"; import CardNews from "./components/card-news";
import { Spinner } from "@/components/ui/spinner";
const News = () => { const News = () => {
const [tab, setTab] = useState("all"); const [tab, setTab] = useState("all");
const { data: newsSpecial } = useGetNews<GetNewsResponseType>({ pageSize: '1' }); const { data: newsSpecial, isLoading: isLoadingSpecial } = useGetNews<GetNewsResponseType>({ pageSize: '1' });
const { data: newsFilters } = useGetNews<GetNewsResponseType>( const { data: newsFilters, isLoading: isLoadingFilters } = useGetNews<GetNewsResponseType>(
{ {
pageSize: '5', pageSize: '5',
filters: tab === "all" ? `` : `page_config.code @=${tab}`, filters: tab === "all" ? `` : `page_config.code @=${tab}`,
...@@ -38,7 +39,12 @@ const News = () => { ...@@ -38,7 +39,12 @@ const News = () => {
<hr className="border-[#063e8e] mb-4" /> <hr className="border-[#063e8e] mb-4" />
<div className="flex flex-col md:flex-row gap-5"> <div className="flex flex-col md:flex-row gap-5">
{newsSpecial?.responseData.rows {isLoadingSpecial ? (
<div className="flex justify-center items-center flex-col w-full md:w-1/2 min-h-[180px] sm:min-h-[220px] gap-3 mb-3">
<Spinner />
</div>
) : (
newsSpecial?.responseData.rows
.slice(0, 1) .slice(0, 1)
.map((news: NewsItem) => ( .map((news: NewsItem) => (
<Link <Link
...@@ -64,8 +70,8 @@ const News = () => { ...@@ -64,8 +70,8 @@ const News = () => {
<p className="line-clamp-4 text-justify">{stripImagesAndHtml(news.description)}</p> <p className="line-clamp-4 text-justify">{stripImagesAndHtml(news.description)}</p>
</div> </div>
</Link> </Link>
))} ))
)}
<div className="w-full md:w-1/2"> <div className="w-full md:w-1/2">
<div className="flex flex-wrap gap-2 sm:gap-3 mb-5"> <div className="flex flex-wrap gap-2 sm:gap-3 mb-5">
<button <button
...@@ -105,9 +111,15 @@ const News = () => { ...@@ -105,9 +111,15 @@ const News = () => {
</button> </button>
</div> </div>
{newsFilters?.responseData?.rows.slice(0, 4).map((news) => ( {isLoadingFilters ? (
<div className="flex justify-center py-10">
<Spinner />
</div>
) : (
newsFilters?.responseData?.rows.slice(0, 4).map((news) => (
<CardNews key={news.id} news={news} /> <CardNews key={news.id} news={news} />
))} ))
)}
</div> </div>
</div> </div>
</div> </div>
......
import Image from "next/image"; import Image from "next/image";
import { useState } from "react"; import { useEffect, useState } from "react";
const ImageNext = ({ src, alt, width, height, className, onError }: any) => { const ImageNext = ({ src, alt, width, height, className, fallback = "/img-error.png" }: any) => {
const [imgSrc, setImgSrc] = useState(src); const [imgSrc, setImgSrc] = useState(src);
useEffect(() => {
setImgSrc(src);
}, [src]);
return ( return (
<Image <Image
src={imgSrc} src={imgSrc}
...@@ -11,7 +15,8 @@ const ImageNext = ({ src, alt, width, height, className, onError }: any) => { ...@@ -11,7 +15,8 @@ const ImageNext = ({ src, alt, width, height, className, onError }: any) => {
width={width} width={width}
height={height} height={height}
className={className} className={className}
onError={() => setImgSrc(onError || "/img-error.png")} onError={() => setImgSrc(fallback)}
unoptimized
/> />
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment