feat: Implement blog API service and refactor components for improved data fetching

This commit is contained in:
Wini_Fy
2026-02-04 15:33:02 +07:00
parent d46c420aaf
commit 9a71d39ebf
16 changed files with 790 additions and 149 deletions

View File

@@ -53,8 +53,10 @@ export const fetchBlogList = async (
headers: {
'Content-Type': 'application/json',
},
// Next.js: cache và revalidate
next: { revalidate: 60 }, // Revalidate mỗi 60 giây
// Next.js: cache và revalidate (disabled)
// next: { revalidate: 60 }, // Revalidate mỗi 60 giây
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -89,7 +91,8 @@ export const fetchBlogDetail = async (
headers: {
'Content-Type': 'application/json',
},
// No cache for blog detail so comments/replies show immediately after submit + refresh
// No cache for blog detail (disabled caching)
// no-cache
cache: 'no-store',
});
@@ -128,7 +131,9 @@ export const fetchFeaturedBlogs = async (
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 60 },
// next: { revalidate: 60 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -163,7 +168,9 @@ export const fetchRecentBlogs = async (
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 60 },
// next: { revalidate: 60 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -195,7 +202,9 @@ export const fetchCategories = async (): Promise<CategoryListResponse> => {
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 }, // Categories ít thay đổi, cache lâu hơn
// next: { revalidate: 300 }, // Categories ít thay đổi, cache lâu hơn
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -230,7 +239,9 @@ export const fetchCategoryDetail = async (
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 },
// next: { revalidate: 300 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -265,7 +276,9 @@ export const fetchTags = async (): Promise<TagListResponse> => {
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 },
// next: { revalidate: 300 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -300,7 +313,9 @@ export const fetchPopularTags = async (
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 },
// next: { revalidate: 300 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {
@@ -335,7 +350,9 @@ export const fetchTagDetail = async (
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 },
// next: { revalidate: 300 },
// no-cache
cache: 'no-store',
});
if (!response.ok) {

View File

@@ -1,4 +1,4 @@
/**
* Export all API functions
*/
export * from './blog';
export * from './blogsApi';