|
1 |
| -import { RouteComponent } from 'routes'; |
| 1 | +import { Sources as RouteComponentSources, Sinks } from 'components/App'; |
2 | 2 | import { Stream } from 'xstream';
|
3 |
| -import { div, h2 } from '@cycle/dom'; |
| 3 | +import { div, h2, h3, hr, p, h4, strong, em } from '@cycle/dom'; |
4 | 4 | import { BackButton } from 'components/BackButton';
|
5 | 5 | import { style } from 'typestyle';
|
6 | 6 | import { rem } from 'csx';
|
| 7 | +import { Commit } from 'drivers/github'; |
| 8 | + |
| 9 | +interface Sources extends RouteComponentSources { |
| 10 | + sha$: Stream<string>; |
| 11 | +} |
7 | 12 |
|
8 | 13 | const className = style({
|
9 | 14 | display: 'inline',
|
10 | 15 | marginLeft: rem(1)
|
11 | 16 | });
|
12 | 17 |
|
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$ }) => { |
14 | 33 | const backButton = BackButton({ dom });
|
| 34 | + const details$ = |
| 35 | + sha$ |
| 36 | + .map(sha => github.commits(sha).startWith(initialCommit)) |
| 37 | + .flatten(); |
15 | 38 | 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 | + ); |
22 | 52 | return {
|
23 | 53 | dom: vdom$,
|
24 |
| - history: backButton.history |
| 54 | + history: backButton.history, |
| 55 | + github: sha$ |
25 | 56 | };
|
26 | 57 | };
|
0 commit comments