brutal-legends/src/components/album.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-03-05 08:07:46 +01:00
import React from "react";
2020-03-05 18:09:48 +01:00
import { Album } from "../interfaces";
2020-03-05 08:07:46 +01:00
2020-03-05 18:09:48 +01:00
export default (props: Props) => {
2020-03-05 08:07:46 +01:00
const handleKeyPress = (e: KeyboardEvent, callback: Function) => {
const SPACE_KEY = 32;
const ENTER_KEY = 13;
if (e.charCode === SPACE_KEY || e.charCode === ENTER_KEY) {
e.preventDefault();
callback();
}
};
const { album, handleOnClick } = props;
const { id, artist, title, songs, year, img, purchased_on } = album;
const imagePath = `./covers/${img}`;
const song = songs.join(", ");
return (
<article
className="album"
tabIndex={0}
role="button"
onClick={() => handleOnClick(album)}
>
<figure className="album__cover">
<img
src={imagePath}
alt="cover"
className="album__cover__media"
/>
</figure>
<span>
#{("00" + id).substr(-2, 2)}: {artist} - {song}, från "{title}" ({year})<br />
2020-03-05 08:07:46 +01:00
<small> {purchased_on}</small>
</span>
</article>
);
};
2020-03-05 18:09:48 +01:00
type Props = {
key: number;
album: Album;
2020-03-05 21:48:45 +01:00
handleOnClick(album: Album): void;
2020-03-05 18:09:48 +01:00
};