mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import { Link } from 'react-router';
|
|
import { provide } from '../../fx/TypedRedux';
|
|
import { ApplicationState } from '../../store';
|
|
import * as GenreList from '../../store/GenreList';
|
|
|
|
class Genres extends React.Component<GenresProps, void> {
|
|
componentWillMount() {
|
|
if (!this.props.genres.length) {
|
|
this.props.requestGenresList();
|
|
}
|
|
}
|
|
|
|
public render() {
|
|
let { genres } = this.props;
|
|
|
|
return <div>
|
|
<h3>Browse Genres</h3>
|
|
|
|
<p>Select from { genres.length || '...' } genres:</p>
|
|
|
|
<ul className="list-group">
|
|
{genres.map(genre =>
|
|
<li key={ genre.GenreId } className="list-group-item">
|
|
<Link to={ '/genre/' + genre.GenreId }>
|
|
{ genre.Name }
|
|
</Link>
|
|
</li>
|
|
)}
|
|
</ul>
|
|
</div>;
|
|
}
|
|
}
|
|
|
|
// Selects which part of global state maps to this component, and defines a type for the resulting props
|
|
const provider = provide(
|
|
(state: ApplicationState) => state.genreList,
|
|
GenreList.actionCreators
|
|
);
|
|
type GenresProps = typeof provider.allProps;
|
|
export default provider.connect(Genres);
|