import React, { Component, PropTypes } from "react";
import { Link} from "react-router";
import CSSModules from "react-css-modules";
import { defineMessages, FormattedMessage } from "react-intl";
import FontAwesome from "react-fontawesome";
import Immutable from "immutable";
import Fuse from "fuse.js";
import FilterBar from "./elements/FilterBar";
import Pagination from "./elements/Pagination";
import { formatLength, messagesMap } from "../utils";
import commonMessages from "../locales/messagesDescriptors/common";
import messages from "../locales/messagesDescriptors/Songs";
import css from "../styles/Songs.scss";
const songsMessages = defineMessages(messagesMap(Array.concat([], commonMessages, messages)));
class SongsTableRowCSS extends Component {
render () {
const length = formatLength(this.props.song.time);
const linkToArtist = "/artist/" + this.props.song.artist.id;
const linkToAlbum = "/album/" + this.props.song.album.id;
return (
{this.props.song.name}
{this.props.song.artist.name}
{this.props.song.album.name}
{this.props.song.genre}
{length}
);
}
}
SongsTableRowCSS.propTypes = {
song: PropTypes.object.isRequired
};
export let SongsTableRow = CSSModules(SongsTableRowCSS, css);
class SongsTableCSS extends Component {
render () {
var displayedSongs = this.props.songs;
if (this.props.filterText) {
// Use Fuse for the filter
displayedSongs = new Fuse(
this.props.songs.toArray(),
{
"keys": ["name"],
"threshold": 0.4,
"include": ["score"]
}).search(this.props.filterText);
// Keep only items in results
displayedSongs = displayedSongs.map(function (item) { return item.item; });
}
var rows = [];
displayedSongs.forEach(function (song) {
rows.push();
});
var loading = null;
if (rows.length == 0 && this.props.isFetching) {
// If we are fetching and there is nothing to show
loading = (