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

update/fix search feature

parent 4badb076
...@@ -41,7 +41,6 @@ const Page = () => { ...@@ -41,7 +41,6 @@ const Page = () => {
} }
); );
console.log(newsData);
const { data: newsAll, isLoading: isLoadingNewsAll } = useGetNews<GetNewsResponseType>( const { data: newsAll, isLoading: isLoadingNewsAll } = useGetNews<GetNewsResponseType>(
{ {
pageSize: '10', pageSize: '10',
......
...@@ -7,7 +7,7 @@ import { Pagination } from "@/components/base/pagination"; ...@@ -7,7 +7,7 @@ import { Pagination } from "@/components/base/pagination";
import { ListFilter } from "@/components/base/list-filter"; import { ListFilter } from "@/components/base/list-filter";
import EventCalendar from "@/components/base/event-calendar"; import EventCalendar from "@/components/base/event-calendar";
import ListCategory from "@/components/base/list-category"; import ListCategory from "@/components/base/list-category";
import NewsContent from "@/components/base/card-news"; import CardNews from "@/components/base/card-news";
import Image from "next/image"; import Image from "next/image";
import parse from "html-react-parser"; import parse from "html-react-parser";
import dayjs from "dayjs"; import dayjs from "dayjs";
...@@ -108,7 +108,7 @@ export default function DynamicPage() { ...@@ -108,7 +108,7 @@ export default function DynamicPage() {
) : ( ) : (
<> <>
{news?.responseData.rows.map((item) => ( {news?.responseData.rows.map((item) => (
<NewsContent <CardNews
key={item.id} key={item.id}
news={item} news={item}
link={`/${url}/${item.id}`} link={`/${url}/${item.id}`}
......
"use client"; "use client";
import React, { useState, Suspense } from "react"; import React, { useState, Suspense } from "react";
import ListCategory from "@app/dai-dien-gioi-chu/components/list-category"; import ListCategory from "@/components/base/list-category";
import { OWNER_REPRESENTATIVES_CATEGORIES } from "@constants/categories"; import ListFilter from "@/components/base/list-filter";
import ListFilter from "@app/dai-dien-gioi-chu/components/list-filter"; import CardNews from "@/components/base/card-news";
import NewsContent from "@app/dai-dien-gioi-chu/components/card-news";
import { Pagination } from "@components/base/pagination"; import { Pagination } from "@components/base/pagination";
import Image from "next/image"; import Image from "next/image";
import { useGetNews } from "@api/endpoints/news"; import { useGetNews } from "@api/endpoints/news";
import { GetNewsResponseType } from "@api/types/NewsPage.type"; import { GetNewsResponseType } from "@api/types/NewsPage.type";
import { Spinner } from "@components/ui/spinner"; import { Spinner } from "@components/ui/spinner";
import { PATHS } from "@constants/paths";
import { useSearchParams } from 'next/navigation' import { useSearchParams } from 'next/navigation'
function SearchContent() { function SearchContent() {
...@@ -22,7 +20,7 @@ function SearchContent() { ...@@ -22,7 +20,7 @@ function SearchContent() {
currentPage: String(page), currentPage: String(page),
filters: query ? `title @=${query}` : undefined, filters: query ? `title @=${query}` : undefined,
}); });
return ( return (
<div className="min-h-screen container mx-auto p-4"> <div className="min-h-screen container mx-auto p-4">
<div className="w-full flex flex-col gap-5"> <div className="w-full flex flex-col gap-5">
...@@ -49,10 +47,10 @@ function SearchContent() { ...@@ -49,10 +47,10 @@ function SearchContent() {
) : ( ) : (
<> <>
{allData?.responseData.rows.map((news) => ( {allData?.responseData.rows.map((news) => (
<NewsContent <CardNews
key={news.id} key={news.id}
news={news} news={news}
link={`${PATHS.mediaInformation}/tin-vcci/${news.id}`} link={`${news.category}/${news.id}`}
/> />
))} ))}
......
export interface NewsDetailItem {
id: string
title: string
thumbnail: string
external_link: string
description: string
release_at: string
is_active: boolean
created_at: string
created_by: string | null
updated_at: string
updated_by: string | null
mode: 'NOW' | string
category: string
}
export interface NewsDetailResponseData {
count: number
rows: NewsDetailItem[]
totalPages: number
currentPage: number
}
export interface GetNewsDetailResponseType {
message: string
message_en: string
responseData: NewsDetailItem
status: 'success' | 'error'
timeStamp: string
violations: any | null
}
\ No newline at end of file
import { NewsItem } from '@app/dai-dien-gioi-chu/lib/types/NewsPage.type'; import { NewsDetailItem } from './CardNews.type';
import Links from '@links/index' import Links from '@links/index'
import dayjs from 'dayjs'; import dayjs from 'dayjs';
...@@ -19,8 +19,8 @@ const stripImagesAndHtml = (html?: string) => { ...@@ -19,8 +19,8 @@ const stripImagesAndHtml = (html?: string) => {
} }
return withoutImgs.replace(/<[^>]*>/g, '') return withoutImgs.replace(/<[^>]*>/g, '')
} }
function NewsContent({ news ,link}: { news: NewsItem ,link:string}) {
const CardNews = ({ news, link }: { news: NewsDetailItem, link: string }) => {
return ( return (
<a <a
href={`${link}`} href={`${link}`}
...@@ -30,14 +30,14 @@ function NewsContent({ news ,link}: { news: NewsItem ,link:string}) { ...@@ -30,14 +30,14 @@ function NewsContent({ news ,link}: { news: NewsItem ,link:string}) {
src={`${Links.imageEndpoint}${news.thumbnail}`} src={`${Links.imageEndpoint}${news.thumbnail}`}
alt={news.title} alt={news.title}
className="w-full sm:w-56 md:w-64 h-40 md:h-36 object-cover shrink-0" className="w-full sm:w-56 md:w-64 h-40 md:h-36 object-cover shrink-0"
onError={(e) => { onError={(e) => {
e.currentTarget.src = "/img-error.png" e.currentTarget.src = "/img-error.png"
}} }}
/> />
<div className="flex-1 min-w-0 pl-0 sm:pl-4"> <div className="flex-1 min-w-0 pl-0 sm:pl-4">
<p className="text-primary font-semibold text-base md:text-lg hover:underline line-clamp-2 wrap-break-word"> <p className="text-primary font-semibold text-base md:text-lg hover:underline line-clamp-2 wrap-break-word">
{news.title} {news.title}
</p> </p>
...@@ -51,4 +51,4 @@ function NewsContent({ news ,link}: { news: NewsItem ,link:string}) { ...@@ -51,4 +51,4 @@ function NewsContent({ news ,link}: { news: NewsItem ,link:string}) {
) )
} }
export default NewsContent; export default CardNews;
\ No newline at end of file \ No newline at end of file
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