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