Skip to content

Commit eb0d042

Browse files
committed
Remove placeholder "Gists2" file; remove old Gists list
1 parent a7d4225 commit eb0d042

File tree

6 files changed

+88
-271
lines changed

6 files changed

+88
-271
lines changed

src/components/Gist2.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/components/Gists.js

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,37 @@
11
import React, { Component } from 'react';
2-
import { bindActionCreators } from 'redux';
3-
import { connect } from 'react-redux';
42
import { Link } from 'react-router-dom';
5-
import { getResources, getStatus } from 'react-redux-resource';
63
import './Gists.css';
7-
import { readManyUsersGists } from '../state/gists/action-creators';
4+
import { ReadUsersGists } from '../request-components/Gists';
85
import login from '../personal-access-token';
96

107
const username = login.username;
118

12-
class Gists extends Component {
13-
render() {
14-
const { usersGists, usersGistsStatus } = this.props;
15-
16-
return (
17-
<div className="Gists">
18-
{usersGistsStatus.pending && ('Loading gists...')}
19-
{usersGistsStatus.failed && (
20-
<span>
21-
There was an error loading gists. <button onClick={this.fetchUsersGists}>Try again.</button>
22-
</span>
23-
)}
24-
{usersGistsStatus.succeeded && (
25-
<ul className="Gists-list">
26-
{usersGists.map(gist => (
27-
<li key={gist.id} className="Gists-listItem">
28-
{username}&nbsp;/&nbsp;
29-
<Link to={`/${gist.id}`}>
30-
{Object.keys(gist.files)[0]}
31-
</Link>
32-
&nbsp;
33-
{!gist.public && '🔒'}
34-
</li>
35-
))}
36-
</ul>
37-
)}
38-
</div>
39-
);
40-
}
41-
42-
componentDidMount() {
43-
this.fetchUsersGists();
44-
}
45-
46-
componentWillUnmount() {
47-
if (this.readManyUsersGistsXhr) {
48-
this.readManyUsersGistsXhr.abort();
49-
}
50-
}
51-
52-
fetchUsersGists = () => {
53-
const { readManyUsersGists } = this.props;
54-
55-
if (this.readManyUsersGistsXhr) {
56-
this.readManyUsersGistsXhr.abort();
57-
}
58-
59-
this.readManyUsersGistsXhr = readManyUsersGists(username);
60-
}
9+
export default function Gists() {
10+
return (
11+
<ReadUsersGists username={username}>
12+
{({ status, lists, doFetch }) => (
13+
<div>
14+
{status.pending && 'Loading gists...'}
15+
{status.failed && (
16+
<span>
17+
There was an error loading gists.{' '}
18+
<button onClick={() => doFetch()}>Try again.</button>
19+
</span>
20+
)}
21+
{status.succeeded && (
22+
<ul className="Gists-list">
23+
{lists.usersGists.map(gist => (
24+
<li key={gist.id} className="Gists-listItem">
25+
{username}&nbsp;/&nbsp;
26+
<Link to={`/${gist.id}`}>{Object.keys(gist.files)[0]}</Link>
27+
&nbsp;
28+
{!gist.public && '🔒'}
29+
</li>
30+
))}
31+
</ul>
32+
)}
33+
</div>
34+
)}
35+
</ReadUsersGists>
36+
);
6137
}
62-
63-
function mapStateToProps(state) {
64-
const usersGists = getResources(state.gists, 'usersGists');
65-
const usersGistsStatus = getStatus(state, 'gists.requests.getUsersGists.status', true);
66-
67-
return {
68-
usersGists,
69-
usersGistsStatus
70-
};
71-
}
72-
73-
function mapDispatchToProps(dispatch) {
74-
return bindActionCreators({
75-
readManyUsersGists
76-
}, dispatch);
77-
}
78-
79-
export default connect(mapStateToProps, mapDispatchToProps)(Gists);

src/components/Gists2.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom';
55
import './index.css';
66
import App from './components/App';
77
import Gists from './components/Gists2';
8-
import Gist from './components/Gist2';
8+
import Gist from './components/Gist';
99
import CreateGist from './components/CreateGist';
1010
import store from './state/store';
1111

12-
ReactDOM.render((
12+
ReactDOM.render(
1313
<Provider store={store}>
1414
<BrowserRouter>
15-
<Route path="/" render={({ location }) => (
16-
<App location={location}>
17-
<Switch>
18-
<Route exact path="/" component={Gists}/>
19-
<Route exact path="/new" component={CreateGist}/>
20-
<Route exact path="/:gistId" component={Gist}/>
21-
</Switch>
22-
</App>
23-
)}/>
15+
<Route
16+
path="/"
17+
render={({ location }) => (
18+
<App location={location}>
19+
<Switch>
20+
<Route exact path="/" component={Gists} />
21+
<Route exact path="/new" component={CreateGist} />
22+
<Route exact path="/:gistId" component={Gist} />
23+
</Switch>
24+
</App>
25+
)}
26+
/>
2427
</BrowserRouter>
25-
</Provider>
26-
), document.getElementById('root'));
28+
</Provider>,
29+
document.getElementById('root')
30+
);

src/request-components/Gists.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,8 @@ export function ReadUsersGists({ username, children }) {
1414
<ResourceRequest
1515
treatNullAsPending
1616
resourceName="gists"
17-
request={request}
18-
children={children}
19-
/>
20-
);
21-
}
22-
23-
export function ReadGist({ gistId, children }) {
24-
const request = (
25-
<Fetch url={`https://api.github.com/gists/${gistId}`} headers={headers} />
26-
);
27-
28-
return (
29-
<ResourceRequest
30-
treatNullAsPending
31-
transformData={gist => [gist]}
32-
resourceName="gists"
17+
list="usersGists"
18+
mergeListIds={false}
3319
request={request}
3420
children={children}
3521
/>

0 commit comments

Comments
 (0)