diff --git a/pages/home/index.tsx b/pages/home/index.tsx index c58d7a3..087f532 100644 --- a/pages/home/index.tsx +++ b/pages/home/index.tsx @@ -13,6 +13,7 @@ import Status from "../../src/Components/Blogs/Status" import Embark from "../../src/Components/Blogs/Embark" import Subspace from "../../src/Components/Blogs/Subspace" import Nimbus from "../../src/Components/Blogs/Nimbus" +import Keycard from "../../src/Components/Blogs/Keycard" // #endregion Local Imports @@ -30,6 +31,8 @@ const switchComponent = (active: Number) => { return case 3: return + case 4: + return } } @@ -71,6 +74,11 @@ Home.getInitialProps = async ( data: { }, }) ); + await ctx.store.dispatch( + HomeActions.GetKeycardData({ + data: { }, + }) + ); return { namespacesRequired: ["common"] }; }; diff --git a/src/Actions/HomeActions/index.ts b/src/Actions/HomeActions/index.ts index b68bfed..bde697e 100644 --- a/src/Actions/HomeActions/index.ts +++ b/src/Actions/HomeActions/index.ts @@ -24,6 +24,8 @@ const nimbusBlog = "https://our.status.im/ghost/api/v2/content/posts/?key=10e7f8 const subspaceBlog = "https://our.status.im/ghost/api/v2/content/posts/?key=10e7f8c1f793d2945ea1177076&filter=tag:tutorial-subspace&limit=all&include=authors"; +const keycardBlog = "https://news.keycard.tech//ghost/api/v2/content/posts/?key=d7ad0ac3484bdf01fadf32b59c&filter=tag:tutorial-keycard&limit=all&include=authors"; + let statusData: any = ''; let parsedStatusData:any = []; @@ -36,6 +38,9 @@ let parsedNimbusData:any = []; let subspaceData: any = ''; let parsedSubspaceData:any = []; +let keycardData: any = ''; +let parsedKeycardData:any = []; + interface StatusBlog { title: string; published_at: string; @@ -155,6 +160,24 @@ export const FetchSubspace = async () => { }) } +export const FetchKeycard = async () => { + await fetch(`${CORS_PROXY}`+ `${keycardBlog}`) + .then(response => response.json()) + .then(data => { + keycardData = data.posts + keycardData.forEach((entry: keycardBlog) => { + const postData: any = {} + postData.title = entry.title; + postData.published_at = entry.published_at; + postData.excerpt = entry.excerpt; + postData.author = entry.primary_author.name; + postData.feature_image = entry.feature_image; + postData.url = entry.url; + parsedKeycardData.push(postData); + }) + }) +} + export const HomeActions = { Map: (payload: {}) => ({ payload, @@ -220,6 +243,23 @@ export const HomeActions = { }, type: ActionConsts.Home.SetReducer, }); + + parsedSubspaceData = [] + }, + + GetKeycardData: (payload: IHomePage.Actions.KeycardData) => async ( + dispatch: Dispatch + ) => { + await FetchKeycard(); + + dispatch({ + payload: { + keycardData: parsedKeycardData, + }, + type: ActionConsts.Home.SetReducer, + }); + + parsedKeycardData = [] }, Active: (activeIndex: any) => async ( diff --git a/src/Components/Blogs/Keycard.tsx b/src/Components/Blogs/Keycard.tsx new file mode 100644 index 0000000..80dbeae --- /dev/null +++ b/src/Components/Blogs/Keycard.tsx @@ -0,0 +1,51 @@ +import React from "react"; +import { useSelector } from "react-redux"; +import { IStore } from "@Redux/IStore"; +import SearchBox from "./SearchBox"; +import { filterData } from "./utils"; + +const Keycard = () => { + const home = useSelector((state: IStore) => state.home); + const keycardData: any = home.keycardData; + const keyword: string = home.searchKeyword; + + let loadedAll = false; + if (keycardData) { + loadedAll = keycardData.length !== 0 + } + + let filteredData = filterData(keycardData, keyword) + + const reduceExcerpt = (string: String) => { + if (string.length >= 140) + return string.substring(0,140) + '...' + } + + return loadedAll ? ( + <> +
+
+
+
+ +
    + {filteredData.map((data: { url: string ; title: string; published_at: string; excerpt: string; author: string;}, i: any) => ( +
  • +
    +
    / Keycard
    +

    {data.title}

    +
    By
    {data.author}
    +
    {reduceExcerpt(data.excerpt)}
    +
    +
  • + ))} +
+
+
+
+
+ + ) : null +} + +export default Keycard; \ No newline at end of file diff --git a/src/Components/Header/index.tsx b/src/Components/Header/index.tsx index 08ff705..05143a3 100644 --- a/src/Components/Header/index.tsx +++ b/src/Components/Header/index.tsx @@ -28,6 +28,11 @@ const Header: React.FunctionComponent = (): JSX.Element => { setNowActive(3) dispatch({ type: 'NIMBUS' }); } + + const getKeycard = () => { + setNowActive(4) + dispatch({ type: 'KEYCARD' }); + } return (
@@ -44,6 +49,7 @@ const Header: React.FunctionComponent = (): JSX.Element => {
  • getEmbark()}>Embark
  • getSubspace()}>Subspace
  • getNimbus()}>Nimbus
  • +
  • getKeycard()}>Keycard
  • diff --git a/src/Interfaces/Pages/Home.d.ts b/src/Interfaces/Pages/Home.d.ts index 9b98905..7c33f35 100644 --- a/src/Interfaces/Pages/Home.d.ts +++ b/src/Interfaces/Pages/Home.d.ts @@ -28,6 +28,9 @@ declare namespace IHomePage { subspaceData: { data: Array; }; + keycardData: { + data: Array; + }; active: Number; searchKeyword: string; } @@ -52,6 +55,10 @@ declare namespace IHomePage { export interface SubspaceData { data: {}; } + + export interface KeycardData { + data: {}; + } } } diff --git a/src/Redux/Reducers/home/index.ts b/src/Redux/Reducers/home/index.ts index d3281fa..f600ec1 100644 --- a/src/Redux/Reducers/home/index.ts +++ b/src/Redux/Reducers/home/index.ts @@ -25,6 +25,9 @@ const INITIAL_STATE: IHomePage.IStateProps = { subspaceData: { data: [] }, + keycardData: { + data: [] + }, active: 0, searchKeyword: '', }; @@ -69,6 +72,12 @@ export const HomeReducer = ( active: 3 }; + case "KEYCARD": + return { + ...state, + active: 4 + }; + case "SEARCH": return { ...state,