|
1 | 1 | import { Card, CardActions } from '@material-ui/core'; |
2 | | -import React, { StatelessComponent } from 'react'; |
| 2 | +import { JSONSchema7 } from 'json-schema'; |
| 3 | +import React, { ComponentType, StatelessComponent } from 'react'; |
| 4 | +import { Observable } from 'rxjs'; |
3 | 5 | import { connect, createState } from '../../reactive'; |
4 | 6 | import { navigation, rels, store } from '../../stream-store'; |
5 | | -import { HalLinks } from '../../types'; |
| 7 | +import { HalLinks, HalResource } from '../../types'; |
6 | 8 | import FormButton from './FormButton'; |
7 | 9 | import LinkButton from './LinkButton'; |
8 | 10 |
|
9 | 11 | const isNotSelf = (rel: string, links: HalLinks): boolean => |
10 | 12 | links[rels.self] && links[rel][0].href !== links[rels.self][0].href; |
11 | 13 |
|
12 | | -const state$ = createState(store.url$.map(href => ['href', () => href])); |
| 14 | +interface HyperMediaControlsState { |
| 15 | + href: string; |
| 16 | +} |
| 17 | + |
| 18 | +const state$ = createState<HyperMediaControlsState>( |
| 19 | + store.url$.map(href => ['href', () => href]), |
| 20 | + Observable.of<HyperMediaControlsState>({ href: '' }), |
| 21 | +); |
13 | 22 |
|
14 | 23 | interface HyperMediaControlsProps { |
15 | 24 | actions: any; |
16 | | - href: string; |
17 | 25 | links: HalLinks; |
18 | | - forms: { [rel: string]: any }; |
| 26 | + forms: { [rel: string]: HalResource & JSONSchema7 }; |
19 | 27 | } |
20 | 28 |
|
21 | | -const HyperMediaControls: StatelessComponent<HyperMediaControlsProps> = ({ |
22 | | - forms, |
23 | | - href, |
24 | | - actions, |
25 | | - links, |
26 | | -}) => ( |
| 29 | +const HyperMediaControls: StatelessComponent< |
| 30 | + HyperMediaControlsProps & HyperMediaControlsState |
| 31 | +> = ({ actions, forms, href, links }) => ( |
27 | 32 | <Card> |
28 | 33 | <CardActions> |
29 | 34 | <div> |
@@ -54,4 +59,6 @@ const HyperMediaControls: StatelessComponent<HyperMediaControlsProps> = ({ |
54 | 59 | </Card> |
55 | 60 | ); |
56 | 61 |
|
57 | | -export default connect(state$)(HyperMediaControls); |
| 62 | +export default connect(state$)(HyperMediaControls) as ComponentType< |
| 63 | + HyperMediaControlsProps |
| 64 | +>; |
0 commit comments