Advertisement
RupeshAcharya60

landing page gpt 2

May 4th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. import React, { useState, useEffect } from 'react';
  2. import { useSelector } from 'react-redux';
  3. import axios from 'axios';
  4. import { Card, CardBody, CardHeader, CardFooter, Typography } from '@material-tailwind/react';
  5. import { TbCurrencyRupeeNepalese } from 'react-icons/tb';
  6. import { BiMap } from 'react-icons/bi';
  7. import Navbar from './Navbar';
  8.  
  9. function LandingPage() {
  10. const { user } = useSelector((state) => state);
  11. const [posts, setPosts] = useState([]);
  12. const [recommendedPosts, setRecommendedPosts] = useState([]);
  13.  
  14. useEffect(() => {
  15. axios.get('http://localhost:8000/post/').then((response) => {
  16. setPosts(response.data);
  17. });
  18.  
  19. axios.get(`http://localhost:8000/recommendation/${user.userState.id}`).then((response) => {
  20. setRecommendedPosts(response.data);
  21. });
  22. }, [user]);
  23.  
  24. return (
  25. <div>
  26. <Navbar />
  27. <div className="container mx-auto px-4 py-8">
  28. <div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
  29. {posts.map((post) => (
  30. <Card key={post.id}>
  31. <CardHeader color="blue" className="relative h-56">
  32. <img src="https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fhouses%2F&psig=AOvVaw0Y4vxWl-iqPSGZNeng5MI1&ust=1683309597455000&source=images&cd=vfe&ved=0CBEQjRxqFwoTCICDmoaf3P4CFQAAAAAdAAAAABAE" alt="" className="h-full w-full object-cover" />
  33. </CardHeader>
  34. <CardBody className="text-center">
  35. <Typography variant="h5" className="mb-2 text-left">
  36. {post.title}
  37. </Typography>
  38. <Typography className="text-left">
  39. {post.content.length > 100 ? post.content.slice(0, 100) + '...' : post.content}
  40. </Typography>
  41. </CardBody>
  42. <CardFooter divider className="flex items-center justify-between py-3">
  43. <div className="flex items-center gap-1">
  44. <TbCurrencyRupeeNepalese />
  45. <Typography>{post.price}</Typography>
  46. </div>
  47. <Typography variant="small" color="gray" className="flex gap-1 items-center">
  48. <BiMap />
  49. <Typography>{post.location.split(',').at(-3)}</Typography>
  50. </Typography>
  51. </CardFooter>
  52. </Card>
  53. ))}
  54. </div>
  55.  
  56. <div className="mt-12">
  57. <Typography variant="h3" className="mb-4">
  58. Recommended Posts
  59. </Typography>
  60.  
  61. <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
  62. {recommendedPosts.map((post) => (
  63. <Card key={post.id}>
  64. <CardHeader color="blue" className="relative h-56">
  65. <img src="https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fhouses%2F&psig=AOvVaw0Y4vxWl-iqPSGZNeng5MI1&ust=1683309597455000&source=images&cd=vfe&ved=0CBEQjRxqFwoTCICDmoaf3P4CFQAAAAAdAAAAABAE" alt="" className="h-full w-full object-cover" />
  66. </CardHeader>
  67. <CardBody className="text-center">
  68. <Typography variant="h5" className="mb-2 text-left">
  69. {post.title}
  70. </Typography>
  71. <Typography className="text-left">
  72. {post.content.length > 100 ? post.content.slice(0, 100) + '...' : post.content}
  73. </Typography>
  74. </CardBody>
  75. <CardFooter divider className="flex items-center justify-between py-3">
  76. <div className="flex items-center gap-1">
  77. <TbCurrencyRupeeNepalese />
  78. <Typography>{post.price}</Typography>
  79. </div>
  80. <Typography variant="small" color="gray" className="flex gap-1 items-center">
  81. <BiMap />
  82. <Typography>{post.location.split(',').at(-3)}</Typography>
  83. </Typography>
  84. </CardFooter>
  85. </Card>
  86. ))}
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. )}
  92.  
  93. export default LandingPage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement