up 25/03
This commit is contained in:
@@ -4,6 +4,7 @@ import { JobDetailDataType } from "@/types/job";
|
||||
|
||||
// Hàm chung để gọi API
|
||||
const apiRequest = async (endpoint: string, method: string = "GET", body?: object) => {
|
||||
try {
|
||||
const response = await fetch(`http://localhost:5000${endpoint}`, {
|
||||
method,
|
||||
headers: {
|
||||
@@ -14,6 +15,10 @@ const apiRequest = async (endpoint: string, method: string = "GET", body?: objec
|
||||
|
||||
if (!response.ok) throw new Error(`Error: ${response.statusText}`);
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
console.error("API Request failed:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
// API cho bài viết
|
||||
export const fetchListArticles = () => apiRequest("/list_article");
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ArticleListDataType } from "@/types/article";
|
||||
import { fetchListArticles } from "@/api/apiService";
|
||||
|
||||
export default function Home() {
|
||||
const [articleList, setArticleList] = useState<ArticleListDataType | null>(
|
||||
const [articlesList, setArticleList] = useState<ArticleListDataType | null>(
|
||||
null
|
||||
);
|
||||
|
||||
@@ -24,9 +24,13 @@ export default function Home() {
|
||||
homePageEffect.startCarousel("#navheight", true, 3000);
|
||||
|
||||
const fetchArticleNews = async () => {
|
||||
try {
|
||||
const data = await fetchListArticles();
|
||||
setArticleList(data.list);
|
||||
setLoadingUI(false);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch articles", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchArticleNews();
|
||||
@@ -606,9 +610,9 @@ export default function Home() {
|
||||
<div className="image-right bg-gray-100 h-[370px] rounded-[12px]"></div>
|
||||
</div>
|
||||
</div>
|
||||
) : Array.isArray(articleList) && articleList.length > 0 ? (
|
||||
) : Array.isArray(articlesList) && articlesList.length > 0 ? (
|
||||
<div className="content-item-article" id="js-article-new">
|
||||
{articleList.slice(0, 1).map((item) => (
|
||||
{articlesList.slice(0, 1).map((item) => (
|
||||
<div className="flex" key={item.id}>
|
||||
<div className="info">
|
||||
<div className="tag-blog flex items-center">
|
||||
|
||||
Reference in New Issue
Block a user