import React from 'react'; import axios from 'axios'; import './SoundList.scss'; export default class SoundList extends React.Component { constructor() { super(); this.state = { soundList: [], showAudioControls: [], }; } componentDidMount() { this.getSoundList(); } getSoundList() { if (!this.soundListCache) { axios.get("/soundlist").then((response) => { this.soundListCache = response.data; this.setState({ soundList: response.data, }); }).catch(() => { //console.warn(error.response.data); }); } else { this.setState({ soundList: this.soundListCache, }); } } checkExtension(extension) { switch(extension) { case "wav": return true; case "mp3": return true; case "mpeg": return true; default: return false; } } handleShowAudio(index) { let temp = this.state.showAudioControls; temp[index] = true; this.setState({ showAudioControls: temp, }); } render() { return (