{"size": 763, "ext": "js", "max_stars_repo_path": "renderer/add.js", "max_stars_repo_name": "wangping1511/simplemusicplayer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "renderer/add.js", "max_issues_repo_name": "wangping1511/simplemusicplayer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "renderer/add.js", "max_forks_repo_name": "wangping1511/simplemusicplayer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.3103448276, "max_line_length": 71, "alphanum_fraction": 0.6408912189}
const {ipcRenderer} = require('electron')
const {$} = require('./helper')
const path = require('path')
let musicPaths = []

$('select-music-btn').addEventListener('click', () => {
  ipcRenderer.send('select-music-window')
})

$('upload-music-btn').addEventListener('click', () => {
  ipcRenderer.send('add-tracks', musicPaths)
})

const renderListHTML = (paths) => {
  const musicList = $('musicList')
  const musicItemHtml = paths.reduce((html, music) => {
    html += `<li class="list-group-item">${path.basename(music)}</li>`;
    return html
  }, '')
  musicList.innerHTML = `<ul class="list-group">${musicItemHtml}</ul>`
}

ipcRenderer.on('selected-file', (event, args) => {
  if (Array.isArray(args)) {
    renderListHTML(args)
    musicPaths = args
  }
})
