Skip to content

Commit 2c5d0a7

Browse files
SpotiftMessage feature added.
1 parent e3856c1 commit 2c5d0a7

6 files changed

Lines changed: 67 additions & 2 deletions

File tree

example/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class App extends Component {
4646
}
4747

4848
token() {
49-
return (parseInt(Math.random() * 10 % 5));
49+
return (parseInt(Math.random() * 10 % 6));
5050
}
5151

5252
photo(size) {
@@ -77,6 +77,9 @@ export class App extends Component {
7777
case 3:
7878
type = 'location';
7979
break;
80+
case 4:
81+
type = 'spotify';
82+
break;
8083
default:
8184
type = 'text';
8285
statu = 'read';
@@ -89,7 +92,7 @@ export class App extends Component {
8992
type: type,
9093
title: loremIpsum({ count: 2, units: 'words' }),
9194
titleColor: this.getRandomColor(),
92-
text: loremIpsum({ count: 1, units: 'sentences' }),
95+
text: type === 'spotify' ? 'spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf' : loremIpsum({ count: 1, units: 'sentences' }),
9396
data: {
9497
uri: `data:image/png;base64,${this.photo(150)}`,
9598
status: {

src/MessageBox/MessageBox.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PhotoMessage from '../PhotoMessage/PhotoMessage';
55
import FileMessage from '../FileMessage/FileMessage';
66
import SystemMessage from '../SystemMessage/SystemMessage';
77
import LocationMessage from '../LocationMessage/LocationMessage';
8+
import SpotifyMessage from '../SpotifyMessage/SpotifyMessage';
89

910
import FaForward from 'react-icons/lib/fa/mail-forward';
1011
import FaReply from 'react-icons/lib/fa/mail-reply';
@@ -77,6 +78,7 @@ export class MessageBox extends Component {
7778
height={this.props.height}
7879
text={this.props.text} />
7980
}
81+
8082
{
8183
this.props.type === 'file' &&
8284
<FileMessage
@@ -86,6 +88,15 @@ export class MessageBox extends Component {
8688
text={this.props.text} />
8789
}
8890

91+
{
92+
this.props.type === 'spotify' &&
93+
<SpotifyMessage
94+
width={this.props.width}
95+
height={this.props.height}
96+
data={this.props.data}
97+
uri={this.props.uri || this.props.text} />
98+
}
99+
89100
<div className="rce-mbox-time">
90101
{
91102
this.props.date &&
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.rce-mbox-spotify {
2+
margin-top: -2px;
3+
overflow: hidden;
4+
margin-right: -5px;
5+
margin-left: -5px;
6+
display: flex;
7+
border-radius: 5px;
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { Component } from 'react';
2+
import './SpotifyMessage.css';
3+
4+
const classNames = require('classnames');
5+
6+
export class SpotifyMessage extends Component {
7+
render() {
8+
if (!this.props.uri)
9+
return null;
10+
return (
11+
<div className="rce-mbox-spotify">
12+
<iframe
13+
src={"https://open.spotify.com/embed?uri=" + this.props.uri}
14+
width={this.props.width}
15+
height={this.props.height}
16+
frameBorder="0"
17+
allowTransparency="true"></iframe>
18+
</div>
19+
);
20+
}
21+
}
22+
23+
SpotifyMessage.defaultProps = {
24+
width: 300,
25+
height: 380,
26+
}
27+
28+
export default SpotifyMessage;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { Component } from 'react';
2+
import { shallow } from 'enzyme';
3+
import toJson from 'enzyme-to-json';
4+
import SpotifyMessage from '../SpotifyMessage';
5+
6+
describe('SpotifyMessage component', () => {
7+
it('should render without issues', () => {
8+
const component = shallow(<SpotifyMessage />);
9+
expect(component.length).toBe(1);
10+
expect(toJson(component)).toMatchSnapshot();
11+
});
12+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SpotifyMessage component should render without issues 1`] = `null`;

0 commit comments

Comments
 (0)