-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from thebishaldeb/master
#29: migration from js to ts.
- Loading branch information
Showing
22 changed files
with
14,599 additions
and
149 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import Story from "./Story"; | ||
import Job from "./Job"; | ||
import { getItem } from "../utils/Api"; | ||
import CustomLoader from "./CustomLoader"; | ||
|
||
const Item = (props: any) => { | ||
const [item, setItem]: any = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchAndSetItem = async () => { | ||
const result = await getItem(props.id); | ||
if (result.resolved) { | ||
setItem(result.data); | ||
} | ||
}; | ||
fetchAndSetItem(); | ||
}, [props.id]); | ||
|
||
if (!item) { | ||
return <CustomLoader />; | ||
} | ||
if (item!.type === "story") { | ||
return <Story item={item} />; | ||
} | ||
if (item!.type === "job") { | ||
return <Job item={item} />; | ||
} | ||
return <div>Rendering of {item!.type} is not currently supported :(</div>; | ||
}; | ||
|
||
export default Item; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import { Card, CardBody, CardTitle } from "reactstrap"; | ||
import { handleClick } from "../utils/helper"; | ||
|
||
const Job = ({ item }: any) => { | ||
return ( | ||
<Card onClick={() => (item.url ? window.open(item.url, "_blank") : null)}> | ||
<CardBody> | ||
<CardTitle>{item.title}</CardTitle> | ||
<p className="card-text"> | ||
{item.score} points by{" "} | ||
<u onClick={event => handleClick(event, "user", item.by)}> | ||
{item.by} | ||
</u>{" "} | ||
|{" "} | ||
<u onClick={event => handleClick(event, "item", item.id)}> | ||
view full description | ||
</u> | ||
</p> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default Job; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import Item from "./Item"; | ||
import { getList } from "../utils/Api"; | ||
import InfiniteScroll from "react-infinite-scroller"; | ||
import paginate from "paginate-array"; | ||
|
||
const Stories = (props: any) => { | ||
const [stories, setStories] = useState(null); | ||
const [renderlist, setrenderlist] = useState(Array()); | ||
const [hasMoreItems, sethasMoreItems] = useState(true); | ||
const [initialLoad, setinitialLoad] = useState(true); | ||
|
||
useEffect(() => { | ||
const fetchAndSetStories = async () => { | ||
const result = await getList(props.storytype); | ||
if (result.resolved) { | ||
setStories(result.data); | ||
} | ||
}; | ||
fetchAndSetStories(); | ||
}, [props.storytype]); | ||
|
||
const loadItems = (pageNumber: any) => { | ||
const pageItems = paginate(stories, pageNumber, 10); //10 items per page | ||
setrenderlist([...renderlist, ...pageItems.data]); | ||
setinitialLoad(false); | ||
sethasMoreItems(pageItems.currentPage !== pageItems.totalPages); | ||
}; | ||
|
||
if (!stories) { | ||
return null; | ||
} | ||
const loader = <div className="loader">Loading ...</div>; | ||
|
||
return ( | ||
<InfiniteScroll | ||
pageStart={0} | ||
loadMore={loadItems} | ||
hasMore={hasMoreItems} | ||
initialLoad={initialLoad} | ||
loader={loader} | ||
> | ||
<div className="stories"> | ||
{renderlist.map(id => ( | ||
<Item key={id} id={id} /> | ||
))} | ||
</div> | ||
</InfiniteScroll> | ||
); | ||
}; | ||
|
||
export default Stories; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import { Card, CardBody, CardTitle } from "reactstrap"; | ||
import { handleClick } from "../utils/helper"; | ||
|
||
const Story = ({ item }: any) => { | ||
return ( | ||
<Card onClick={() => (item.url ? window.open(item.url, "_blank") : null)}> | ||
<CardBody> | ||
<CardTitle>{item.title}</CardTitle> | ||
<p className="card-text"> | ||
{item.score} points by{" "} | ||
<u onClick={event => handleClick(event, "user", item.by)}> | ||
{item.by} | ||
</u>{" "} | ||
|{" "} | ||
<u onClick={event => handleClick(event, "item", item.id)}> | ||
{item.kids ? item.kids.length : 0} comments | ||
</u> | ||
</p> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default Story; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="react-scripts" /> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import axios from "axios"; | ||
import { API_URL } from "./constants"; | ||
|
||
export async function getItem(id: any) { | ||
try { | ||
const itemResonse = await axios.get(`${API_URL}/item/${id}.json`); | ||
return { resolved: true, data: itemResonse.data }; | ||
} catch (error) { | ||
return { resolved: false, data: error }; | ||
} | ||
} | ||
|
||
export async function getList(name: any) { | ||
try { | ||
const itemResonse = await axios.get(`${API_URL}/${name}.json`); | ||
return { resolved: true, data: itemResonse.data }; | ||
} catch (error) { | ||
return { resolved: false, data: error }; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./built", | ||
"allowJs": true, | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react", | ||
"noImplicitAny": false | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
] | ||
} |
Oops, something went wrong.