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

fix/url description

parent 6af58bbc
...@@ -6,7 +6,7 @@ import AppEditorContent from '@/components/shared/editor-content'; ...@@ -6,7 +6,7 @@ import AppEditorContent from '@/components/shared/editor-content';
function CardEvent({ event }: { event: EventItem }) { function CardEvent({ event }: { event: EventItem }) {
return ( return (
<a <a
href={`${event.id}`} href={`hoat-dong/su-kien/${event.id}`}
className='flex flex-row gap-2 mb-2 sm:gap-3 sm:mb-3 p-2 sm:p-3 border border-gray-200 bg-white rounded-md' className='flex flex-row gap-2 mb-2 sm:gap-3 sm:mb-3 p-2 sm:p-3 border border-gray-200 bg-white rounded-md'
> >
<img <img
......
...@@ -30,6 +30,23 @@ const Page = () => { ...@@ -30,6 +30,23 @@ const Page = () => {
const [currentIndex, setCurrentIndex] = useState(0); const [currentIndex, setCurrentIndex] = useState(0);
const swiperRef = useRef<SwiperType | null>(null); const swiperRef = useRef<SwiperType | null>(null);
// helpers
const stripImagesAndHtml = (html?: string) => {
if (!html) return ''
// remove img tags first
const withoutImgs = html.replace(/<img[^>]*>/gi, '')
// use DOMParser on client for robust extraction
if (typeof window !== 'undefined' && typeof DOMParser !== 'undefined') {
try {
const doc = new DOMParser().parseFromString(withoutImgs, 'text/html')
return doc.body.textContent || ''
} catch {
// fallback to regex
}
}
return withoutImgs.replace(/<[^>]*>/g, '')
}
const { data: categoryData, isLoading: isLoadingCategory } = useGetCategory<GetCategoryAdminResponseType>(); const { data: categoryData, isLoading: isLoadingCategory } = useGetCategory<GetCategoryAdminResponseType>();
const { data: newsData, isLoading: isLoadingNews } = useGetNews<GetNewsAdminResponseType>( const { data: newsData, isLoading: isLoadingNews } = useGetNews<GetNewsAdminResponseType>(
{ {
...@@ -37,7 +54,7 @@ const Page = () => { ...@@ -37,7 +54,7 @@ const Page = () => {
filters: tab === "all" ? `` : `category @=${tab}`, filters: tab === "all" ? `` : `category @=${tab}`,
} }
); );
const { data: newsSlider, isLoading: isLoadingNewsSlider } = useGetNews<GetNewsAdminResponseType>( const { data: newsAll, isLoading: isLoadingNewsAll } = useGetNews<GetNewsAdminResponseType>(
{ {
pageSize: '10', pageSize: '10',
} }
...@@ -146,7 +163,7 @@ const Page = () => { ...@@ -146,7 +163,7 @@ const Page = () => {
}} }}
className="pb-5" className="pb-5"
> >
{newsSlider?.responseData?.rows.map((news) => ( {newsAll?.responseData?.rows.map((news) => (
<SwiperSlide key={news.id}> <SwiperSlide key={news.id}>
<a <a
href={`/${news.id}`} href={`/${news.id}`}
...@@ -195,7 +212,7 @@ const Page = () => { ...@@ -195,7 +212,7 @@ const Page = () => {
<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">
{newsData?.responseData.rows {newsAll?.responseData.rows
.slice(0, 1) .slice(0, 1)
.map((news: NewsAdminItem) => ( .map((news: NewsAdminItem) => (
<a <a
...@@ -218,10 +235,7 @@ const Page = () => { ...@@ -218,10 +235,7 @@ const Page = () => {
<p className="text-gray-500 text-sm"> <p className="text-gray-500 text-sm">
{dayjs(news.release_at).format("DD/MM/YYYY")} {dayjs(news.release_at).format("DD/MM/YYYY")}
</p> </p>
<AppEditorContent <p className="line-clamp-4">{stripImagesAndHtml(news.description)}</p>
className="line-clamp-4"
value={news.description}
/>
</div> </div>
</a> </a>
))} ))}
...@@ -326,7 +340,7 @@ const Page = () => { ...@@ -326,7 +340,7 @@ const Page = () => {
.map((event: EventItem) => ( .map((event: EventItem) => (
<a <a
key={event.id} key={event.id}
href={`${event.id}`} href={`hoat-dong/su-kien/${event.id}`}
className="flex flex-col w-full md:w-1/2 min-h-[180px] sm:min-h-[220px] gap-3 mb-3 border border-gray-200 bg-white rounded-md p-3" className="flex flex-col w-full md:w-1/2 min-h-[180px] sm:min-h-[220px] gap-3 mb-3 border border-gray-200 bg-white rounded-md p-3"
> >
<div className="w-full aspect-3/2 overflow-hidden"> <div className="w-full aspect-3/2 overflow-hidden">
...@@ -348,10 +362,7 @@ const Page = () => { ...@@ -348,10 +362,7 @@ const Page = () => {
<p className="text-gray-500 text-sm my-1"> <p className="text-gray-500 text-sm my-1">
{dayjs(event.start_time).format("DD/MM/YYYY")} {dayjs(event.start_time).format("DD/MM/YYYY")}
</p> </p>
<AppEditorContent <p className="line-clamp-3">{stripImagesAndHtml(event.description)}</p>
className="line-clamp-3"
value={event.description}
/>
</div> </div>
</a> </a>
))} ))}
......
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