From 4bb4cf4ec0fcbd3c4829b31b77b5a926f5ab88c1 Mon Sep 17 00:00:00 2001 From: David Inga Date: Thu, 5 Oct 2023 11:48:34 +0200 Subject: [PATCH] LMS-42 fetch latest articles from Landgriffon Medium account --- .../src/components/blog-card/component.tsx | 20 ++- .../src/containers/blog-posts/component.tsx | 134 ++++++++---------- marketing/src/hooks/posts/index.ts | 39 +++++ 3 files changed, 108 insertions(+), 85 deletions(-) create mode 100644 marketing/src/hooks/posts/index.ts diff --git a/marketing/src/components/blog-card/component.tsx b/marketing/src/components/blog-card/component.tsx index 0c1b2382c..21458e707 100644 --- a/marketing/src/components/blog-card/component.tsx +++ b/marketing/src/components/blog-card/component.tsx @@ -1,22 +1,28 @@ +/* eslint-disable @next/next/no-img-element */ import { FC } from 'react'; -import Image from 'next/image'; - export interface BlogProps { title: string; - subtitle: string; + description: string; url: string; image: string; } -const BlogCard: FC = ({ title, subtitle, url, image }: BlogProps) => { +const BlogCard: FC = ({ title, description, url, image }: BlogProps) => { return (
- +
+ {title} +
-
{title}
-

{subtitle}

+

+ {title} +

+
diff --git a/marketing/src/containers/blog-posts/component.tsx b/marketing/src/containers/blog-posts/component.tsx index 2945507cc..7d40fc0fc 100644 --- a/marketing/src/containers/blog-posts/component.tsx +++ b/marketing/src/containers/blog-posts/component.tsx @@ -4,51 +4,14 @@ import cx from 'classnames'; import Carousel from 'components/carousel'; import FadeIn from 'components/fade'; import BlogCard from 'components/blog-card'; - -const BLOGPOSTS = [ - { - id: '1', - content: ( -
- -
- ), - }, - { - id: '2', - content: ( -
- -
- ), - }, - { - id: '3', - content: ( -
- -
- ), - }, -]; +import usePosts from 'hooks/posts'; const BlogPosts: FC = () => { const [slide, setSlide] = useState(1); + const { data, isFetched } = usePosts(); + + const posts = data?.items?.slice(0, 4); // Taking the first 4 posts + console.log(posts); return (
@@ -60,42 +23,57 @@ const BlogPosts: FC = () => {
- -
-
- { - setSlide(i); - }} - /> -
-
-
- {BLOGPOSTS.map((post, i) => { - return ( - - ); - })} -
- + {isFetched && data && ( + <> + +
+
+ ({ + id: guid, + content: ( +
+ +
+ ), + }))} + autoplay={0} + options={{ circular: true, bound: false }} + onChange={setSlide} + /> +
+
+
+ {posts.map((post, i) => { + return ( + + ); + })} +
+ + + )}
); diff --git a/marketing/src/hooks/posts/index.ts b/marketing/src/hooks/posts/index.ts new file mode 100644 index 000000000..a409b7ba0 --- /dev/null +++ b/marketing/src/hooks/posts/index.ts @@ -0,0 +1,39 @@ +import axios from 'axios'; +import { useQuery } from 'react-query'; + +type PostItem = { + title: string; + pubDate: string; + link: string; + guid: string; + thumbnail: string; + description: string; + content: string; + categories: string[]; +}; + +type PostsResponse = { + status: string; + feed: { + url: string; + title: string; + link: string; + author: string; + description: string; + image: string; + }; + items: PostItem[]; +}; + +function usePosts() { + const getPosts = async () => { + const { data } = await axios.get( + 'https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@landgriffon', + ); + return data; + }; + + return useQuery('posts', getPosts); +} + +export default usePosts;