Skip to content

Commit aaff242

Browse files
committed
Complete details
1 parent 456d4ba commit aaff242

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/routes/Commits/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ export const Commits: RouteDefinitions = {
1818
},
1919
getLayout: getHeaderLayout
2020
},
21-
'/:id': id => ({
21+
// Example of providing additional sources based on route parameters
22+
'/:sha': sha => ({
2223
getComponent: async () => {
2324
const { Details } = await import(/* webpackChunkName: "CommitDetails" */'./routes/Details');
2425
return Details;
2526
},
2627
sources: {
27-
id$: xs.of(id)
28+
sha$: xs.of(sha)
2829
},
2930
getLayout: getHeaderLayout
3031
})
Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
1-
import { RouteComponent } from 'routes';
1+
import { Sources as RouteComponentSources, Sinks } from 'components/App';
22
import { Stream } from 'xstream';
3-
import { div, h2 } from '@cycle/dom';
3+
import { div, h2, h3, hr, p, h4, strong, em } from '@cycle/dom';
44
import { BackButton } from 'components/BackButton';
55
import { style } from 'typestyle';
66
import { rem } from 'csx';
7+
import { Commit } from 'drivers/github';
8+
9+
interface Sources extends RouteComponentSources {
10+
sha$: Stream<string>;
11+
}
712

813
const className = style({
914
display: 'inline',
1015
marginLeft: rem(1)
1116
});
1217

13-
export const Details: RouteComponent = ({ dom, history, github }) => {
18+
const xs = Stream;
19+
20+
const initialCommit: Commit = {
21+
sha: '',
22+
commit: {
23+
author: {
24+
name: 'Loading...',
25+
email: 'Loading...',
26+
date: undefined
27+
},
28+
message: 'Loading...'
29+
}
30+
};
31+
32+
export const Details: (sources: Sources) => Partial<Sinks> = ({ dom, github, sha$ }) => {
1433
const backButton = BackButton({ dom });
34+
const details$ =
35+
sha$
36+
.map(sha => github.commits(sha).startWith(initialCommit))
37+
.flatten();
1538
const vdom$ =
16-
backButton.dom.map(button =>
17-
div([
18-
button,
19-
h2(`.${className}`, ['Details'])
20-
])
21-
);
39+
xs.combine(backButton.dom, details$)
40+
.map(([backButton, { sha, commit: { message, author: { name, email, date } } }]) =>
41+
div([
42+
backButton,
43+
h2(`.${className}`, ['Details']),
44+
hr(),
45+
h3([message.split('\n\n')[0]]),
46+
h4([strong([name])]),
47+
h4([email]),
48+
h4([em([date])]),
49+
p([message.split('\n\n')[1] || ''])
50+
])
51+
);
2252
return {
2353
dom: vdom$,
24-
history: backButton.history
54+
history: backButton.history,
55+
github: sha$
2556
};
2657
};

src/routes/Commits/routes/List/components/CommitListItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Sinks {
1616
const CommitListItemComponent = ({ dom, commit$ }: Sources): Sinks => {
1717
const navigateTo$ =
1818
commit$
19-
.map(({ sha }) => dom.select('li').events('click', { preventDefault: true }).map(ev => `/commits/s${sha}`))
19+
.map(({ sha }) => dom.select('li').events('click', { preventDefault: true }).map(ev => `/commits/${sha}`))
2020
.flatten();
2121
const vdom$ =
2222
commit$

0 commit comments

Comments
 (0)