Skip to content

Commit

Permalink
Using random Flickr image as genre title pic
Browse files Browse the repository at this point in the history
  • Loading branch information
Swizec committed May 15, 2017
1 parent 279847b commit 4e6a1cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion MusicApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"dependencies": {
"@shoutem/ui": "^0.14.2",
"flickr-sdk": "^2.1.0",
"react": "16.0.0-alpha.6",
"react-native": "0.43.0"
},
Expand Down
23 changes: 16 additions & 7 deletions MusicApp/src/Genres.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@
import React, { Component } from 'react';
import { ListView, GridView, GridRow, TouchableOpacity, Card, Image, View, Subtitle, Spinner } from '@shoutem/ui';

import Flickr from 'flickr-sdk';

const flickr = new Flickr({
apiKey: "8dacb3c2a9b8ff4016fab4a76df1441c",
apiSecret: "47a16c5f9512dbf8"
});
const Flickr = function (search) {
return fetch(
`https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&nojsoncallback=true&api_key=8dacb3c2a9b8ff4016fab4a76df1441c&text=${search} music&license=2&sort=interestingness-desc`
).then(res => res.json())
.then(json => {
return new Promise((resolve, reject) => {
const { farm, server, id, secret } = json.photos.photo[Math.round(Math.random()*10)];
resolve(`https://farm${farm}.staticflickr.com/${server}/${id}_${secret}_z.jpg`);
});
});
}

class GenreArt extends Component {
state = {
uri: null
}

componentDidMount() {

Flickr(this.props.name).then(uri => {
console.log(uri);
this.setState({ uri })
});
}

render() {
Expand All @@ -42,7 +51,7 @@ class Genres extends Component {
const cellViews = rowData.map((genre, id) => (
<TouchableOpacity key={id} styleName="flexible">
<View>
<GenreArt />
<GenreArt name={genre.name} />
<View styleName="content">
<Subtitle numberOfLines={1}>{genre.name}</Subtitle>
</View>
Expand Down

0 comments on commit 4e6a1cd

Please sign in to comment.