From a5283428f7cfdb4eeeb2de61cf890276627b99f2 Mon Sep 17 00:00:00 2001 From: jasirtp Date: Tue, 9 Nov 2021 17:41:01 +0530 Subject: [PATCH] fix: home and latest user and blog #424 home and latest users and blog page rendering issue fixed --- .../layout/SectionUsers/SectionUsers.jsx | 1 - pages/index.js | 22 +++++----- services/PostService.js | 1 - services/UserService.js | 44 ++++++++----------- 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/component/layout/SectionUsers/SectionUsers.jsx b/component/layout/SectionUsers/SectionUsers.jsx index 69dfcdc9..6b2681a5 100644 --- a/component/layout/SectionUsers/SectionUsers.jsx +++ b/component/layout/SectionUsers/SectionUsers.jsx @@ -5,7 +5,6 @@ import Link from "next/link"; import Image from "next/image"; export default class SimpleSlider extends Component { render() { - // console.log(this.props.user); const settings = { dots: false, arrows: false, diff --git a/pages/index.js b/pages/index.js index 9a2e23ba..78144a9f 100644 --- a/pages/index.js +++ b/pages/index.js @@ -16,24 +16,23 @@ import notify from "../lib/notify"; export async function getServerSideProps(context) { try { const postParams = { - sort_field: "published_at", + // sort_field: "published_at", status: "published", - order: "ASC", + // order: "ASC", limit: 4, page: 1, - with_table: "users" + // with_table: "users" }; const userParams = { limit: 10 }; - const responsePost = await PostService.getLatestPosts(postParams); - // console.log(responsePost.posts[0].user); - const responseUser = await UserService.getLatestUsers(userParams); - // console.log(responseUser); + const responsePost = await PostService.getPostsByUserId(postParams); + console.log(responsePost.data.posts, 'h'); + const { data } = await UserService.getLatestUsers(userParams); return { props: { - posts: responsePost.posts || [], - user: responseUser + posts: responsePost.data.posts || [], + user: data.users || [], } }; } catch (err) { @@ -41,8 +40,9 @@ export async function getServerSideProps(context) { return { props: { blog: [] } }; } } - export default function Home({ posts, user }) { + // console.log(user,'s'); + // console.log(process.env.ENV, baseUrl, clientUrl); return (
@@ -78,7 +78,7 @@ export default function Home({ posts, user }) { - {posts && posts[0] && } + {posts && } {user && } diff --git a/services/PostService.js b/services/PostService.js index f4a6872e..d055761b 100644 --- a/services/PostService.js +++ b/services/PostService.js @@ -20,7 +20,6 @@ async function getPostsByUserId(reqData) { const { data } = await axios.get(`${baseUrl}/${postsUrl}`, { params: reqData }); - console.log(data ,); return data; } catch (err) { throw err; diff --git a/services/UserService.js b/services/UserService.js index fb63d4ee..1e265222 100644 --- a/services/UserService.js +++ b/services/UserService.js @@ -1,18 +1,11 @@ const axios = require("axios"); import { baseUrl, usersUrl, userUrl } from "../config/config"; -import { getUrl } from "../lib/getUrl"; +// import { getUrl } from "../lib/getUrl"; async function getLatestUsers(reqParams) { - let url = getUrl(); try { - const { - data: { - data: { users } - } - } = await axios.get(`${url}/${usersUrl}`, { - params: reqParams - }); - return users; + const { data } = await axios.get(`${baseUrl}/${usersUrl}`,reqParams); + return data; } catch (err) { throw err; } @@ -20,7 +13,6 @@ async function getLatestUsers(reqParams) { //Api call for fetching userdetails async function getUserByUsername(username) { - // let url = getUrl(); try { const { data } = await axios.get( @@ -52,26 +44,26 @@ async function updateProfileByUserId(userCookie, reqData) { } //get user profile details by user Id -async function getProfileByUserId(userCookie) { - let url = getUrl(); - try { - const { data } = await axios.get(`${url}/${usersUrl}/${userCookie.id}`, { - headers: { - "x-access-token": `${userCookie.accessToken}` - } - }); - // console.log({ data }); - return data; - } catch (err) { - throw err; - } -} +// async function getProfileByUserId(userCookie) { +// let url = getUrl(); +// try { +// const { data } = await axios.get(`${url}/${usersUrl}/${userCookie.id}`, { +// headers: { +// "x-access-token": `${userCookie.accessToken}` +// } +// }); +// // console.log({ data }); +// return data; +// } catch (err) { +// throw err; +// } +// } const UserService = { getLatestUsers, getUserByUsername, updateProfileByUserId, - getProfileByUserId + // getProfileByUserId }; module.exports = UserService;