Created
April 1, 2019 02:34
-
-
Save ddoronin/920e5c7961e08adac4ae24ca36064550 to your computer and use it in GitHub Desktop.
History React Component
This file contains hidden or 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
import * as React from "react"; | |
import { useRx } from "src/useRx"; | |
import { AppStateContext } from "src/state/AppState"; | |
import { some } from "monas"; | |
import styles from "./styles.module.scss"; | |
import { IRequest } from "src/models/request-composer"; | |
export default function History() { | |
const appState = React.useContext(AppStateContext); | |
const [requests] = useRx(appState.last5$, []); | |
const restore = (req: IRequest) => () => { | |
appState.setRequest(some({ ...req, time: Date.now() })); | |
}; | |
return ( | |
<article> | |
<header> | |
<h2>History</h2> | |
</header> | |
<section> | |
<ul className={styles.list}> | |
{requests.map(req => ( | |
<li key={req.time} className={styles.listItem}> | |
<h2>{req.uri}</h2> | |
<pre>{JSON.stringify(req, null, " ")}</pre> | |
<button onClick={restore(req)}>Restore</button> | |
</li> | |
))} | |
</ul> | |
</section> | |
</article> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment