diff --git a/src/js/Maths/Count.js b/src/js/Maths/Count.js new file mode 100644 index 0000000..151a1ab --- /dev/null +++ b/src/js/Maths/Count.js @@ -0,0 +1,73 @@ +import React, { Component } from "react"; +const axios = require('axios'); + +import showMessage from "../Toast.js"; + +class Count extends Component { + + constructor(props){ + super(props); + this.state = { + playlists: [], + isLoading: true + } + this.getPlaylists(); + } + + getPlaylists(){ + axios.get('/api/playlists') + .then((response) => { + + var playlists = []; + + var playlist_in; + for(playlist_in of response.data.playlists) { + if(playlist_in['lastfm_stat_last_refresh'] != undefined){ + playlists.push(playlist_in); + } + } + + playlists.sort(function(a, b){ + return b['lastfm_stat_count'] - a['lastfm_stat_count']; + }); + + this.setState({ + playlists: playlists, + isLoading: false + }); + }) + .catch((error) => { + console.log(error); + showMessage(`error getting playlists (${error.response.status})`); + }); + } + + render() { + + var table = + + + + + + + {this.state.playlists.map((entry) => )} + +
+

scrobble counts

+
; + + const loadingMessage =

loading...

; + + return this.state.isLoading ? loadingMessage : table; + } +} + +function Row(props){ + return + {props.name} + {props.count.toLocaleString()} / {props.percent}% + ; +} + +export default Count; \ No newline at end of file diff --git a/src/js/Maths/Maths.js b/src/js/Maths/Maths.js index d9b6fe6..f8f9c42 100644 --- a/src/js/Maths/Maths.js +++ b/src/js/Maths/Maths.js @@ -1,13 +1,19 @@ import React, { Component } from "react"; import { BrowserRouter as Router, Route, Link, Switch, Redirect} from "react-router-dom"; +import Count from "./Count.js"; + class Maths extends Component { render() { return ( +
- + + } />
); } diff --git a/src/js/Playlist/View/Edit.js b/src/js/Playlist/View/Edit.js index 1d05420..1a41133 100644 --- a/src/js/Playlist/View/Edit.js +++ b/src/js/Playlist/View/Edit.js @@ -1,7 +1,7 @@ import React, { Component } from "react"; const axios = require('axios'); -import showMessage from "../../Toast.js" +import showMessage from "../../Toast.js"; var thisMonth = [ 'january', diff --git a/src/js/PlaylistManager.js b/src/js/PlaylistManager.js index 093452f..aee215c 100644 --- a/src/js/PlaylistManager.js +++ b/src/js/PlaylistManager.js @@ -58,7 +58,7 @@ class PlaylistManager extends Component { home playlists - {/* maths */} + maths settings { this.state.type == 'admin' && admin } logout