Skip to content

Commit

Permalink
fix: home and latest user and blog #424
Browse files Browse the repository at this point in the history
home and latest users and blog page rendering issue fixed
  • Loading branch information
jasirtp committed Nov 9, 2021
1 parent 842aacc commit a528342
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
1 change: 0 additions & 1 deletion component/layout/SectionUsers/SectionUsers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ 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) {
notify(err?.response?.data?.message ?? err?.message, 'error');
return { props: { blog: [] } };
}
}

export default function Home({ posts, user }) {
// console.log(user,'s');

// console.log(process.env.ENV, baseUrl, clientUrl);
return (
<div className="wrap">
Expand Down Expand Up @@ -78,7 +78,7 @@ export default function Home({ posts, user }) {
</Head>
<SiteHeader />
<HomeSpotlight />
{posts && posts[0] && <SectionBlogs posts={posts} />}
{posts && <SectionBlogs posts={posts} />}

<SectionVideos />
{user && <SectionUsers user={user} />}
Expand Down
1 change: 0 additions & 1 deletion services/PostService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 18 additions & 26 deletions services/UserService.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
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;
}
}

//Api call for fetching userdetails
async function getUserByUsername(username) {
// let url = getUrl();

try {
const { data } = await axios.get(
Expand Down Expand Up @@ -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;

0 comments on commit a528342

Please sign in to comment.