Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit f47ecdb

Browse files
committed
fix(): reduce the data request on home blog posts
1 parent 376dee0 commit f47ecdb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/pages/app-home/app-home.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export class AppHome {
7575

7676
async getFeaturedPost() {
7777
this.featuredIsLoading = true;
78-
this.featuredPost = await Fetch.fetchOneBlogPost();
79-
this.featuredPost1 = await Fetch.fetchOneBlogPost(1);
78+
const homePosts = await Fetch.fetchHomeBlogPosts();
79+
this.featuredPost = homePosts.first;
80+
this.featuredPost1 = homePosts.second;
8081
this.featuredIsLoading = false;
8182
}
8283

src/shared/fetch-handler.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ export async function fetchOneBlogPost(postNum: number = 0) {
1919
});
2020
}
2121

22+
export async function fetchHomeBlogPosts() {
23+
return await fetch(`${urlPosts}?${authToken}&page_size=2`)
24+
.then(res => res.json())
25+
.then(resp => {
26+
if (resp.data.length > 1) {
27+
return {
28+
first: resp.data[0],
29+
second: resp.data[1],
30+
};
31+
}
32+
return null;
33+
})
34+
.catch(resp => {
35+
console.log(resp);
36+
return null;
37+
});
38+
}
39+
2240
export async function fetchBlogPosts() {
2341
return await fetch(`${urlPosts}?${authToken}`)
2442
.then(res => res.json())

0 commit comments

Comments
 (0)