Files
Iris/src/js/services/core/actions.js

267 lines
6.3 KiB
JavaScript
Raw Normal View History

import * as helpers from '../../helpers'
2017-08-22 20:44:36 +12:00
var spotifyActions = require('../../services/spotify/actions')
var mopidyActions = require('../../services/mopidy/actions')
export function getBroadcasts(){
return (dispatch, getState) => {
var config = {
method: 'GET',
timeout: 15000,
url: 'https://gist.githubusercontent.com/jaedb/b677dccf80daf3ccb2ef12e96e495677/raw'
}
2017-10-10 13:05:28 +13:00
$.ajax(config).then(
response => {
dispatch({
type: 'BROADCASTS_LOADED',
broadcasts: JSON.parse(response)
})
},
(xhr, status, error) => {
dispatch(
handleException(
'Could not fetch broadcasts from GitHub',
{
config: config,
xhr: xhr,
status: status,
error: error
}
)
);
}
)
}
}
export function startSearch(search_type, query, only_mopidy = false){
return {
type: 'SEARCH_STARTED',
search_type: search_type,
query: query,
only_mopidy: only_mopidy
}
}
2017-10-26 19:26:38 +13:00
export function handleException(message, data = {}, description = null){
2017-09-19 16:57:59 +12:00
return {
type: 'HANDLE_EXCEPTION',
message: message,
2017-10-26 19:26:38 +13:00
description: description,
2017-09-19 16:57:59 +12:00
data: data
}
}
export function debugResponse(response){
return {
type: 'DEBUG',
response: response
}
}
2017-10-10 13:05:28 +13:00
export function set(data){
return {
type: 'CORE_SET',
data: data
}
}
export function clearCurrentTrack(){
return {
type: 'CLEAR_CURRENT_TRACK'
}
}
/**
* Playlist manipulation
**/
2017-10-10 13:05:28 +13:00
export function reorderPlaylistTracks(uri, indexes, insert_before, snapshot_id = false){
2017-11-10 15:56:01 +13:00
var range = helpers.createRange(indexes);
switch(helpers.uriSource(uri)){
case 'spotify':
return {
type: 'SPOTIFY_REORDER_PLAYLIST_TRACKS',
key: uri,
range_start: range.start,
range_length: range.length,
insert_before: insert_before,
snapshot_id: snapshot_id
}
case 'm3u':
return {
type: 'MOPIDY_REORDER_PLAYLIST_TRACKS',
key: uri,
range_start: range.start,
range_length: range.length,
insert_before: insert_before
}
}
}
export function savePlaylist(uri, name, description = '', is_public = false, is_collaborative = false){
2017-08-22 20:44:36 +12:00
switch (helpers.uriSource(uri)){
case 'spotify':
return {
type: 'SPOTIFY_SAVE_PLAYLIST',
key: uri,
name: name,
description: (description == '' ? null : description),
is_public: is_public,
is_collaborative: is_collaborative
}
case 'm3u':
return {
type: 'MOPIDY_SAVE_PLAYLIST',
key: uri,
name: name
}
}
return false
}
export function createPlaylist(scheme, name, description = '', is_public = false, is_collaborative = false){
2017-08-22 20:44:36 +12:00
switch (scheme){
case 'spotify':
2017-08-22 20:44:36 +12:00
if (description == ''){
description = null
}
2017-10-10 13:05:28 +13:00
return spotifyActions.createPlaylist(name, description, is_public, is_collaborative )
2017-08-22 20:44:36 +12:00
default:
return mopidyActions.createPlaylist(name, scheme)
}
return false
}
export function deletePlaylist(uri){
switch (helpers.uriSource(uri)){
case 'spotify':
return spotifyActions.following(uri, 'DELETE')
default:
return mopidyActions.deletePlaylist(uri)
}
return false
}
2017-10-10 13:05:28 +13:00
export function removeTracksFromPlaylist(uri, tracks_indexes){
switch(helpers.uriSource(uri )){
case 'spotify':
return {
type: 'SPOTIFY_REMOVE_PLAYLIST_TRACKS',
key: uri,
tracks_indexes: tracks_indexes
}
case 'm3u':
return {
type: 'MOPIDY_REMOVE_PLAYLIST_TRACKS',
key: uri,
tracks_indexes: tracks_indexes
}
}
}
2017-10-10 13:05:28 +13:00
export function addTracksToPlaylist(uri, tracks_uris){
switch(helpers.uriSource(uri )){
case 'spotify':
return {
type: 'SPOTIFY_ADD_PLAYLIST_TRACKS',
key: uri,
tracks_uris: tracks_uris
}
case 'm3u':
return {
type: 'MOPIDY_ADD_PLAYLIST_TRACKS',
key: uri,
tracks_uris: tracks_uris
}
}
}
2017-08-11 21:59:14 +12:00
/**
* Asset libraries
**/
export function getLibraryPlaylists(){
return {
type: 'GET_LIBRARY_PLAYLISTS'
}
}
export function getLibraryAlbums(){
return {
type: 'GET_LIBRARY_ALBUMS'
}
}
export function getLibraryArtists(){
return {
type: 'GET_LIBRARY_ARTISTS'
}
}
2017-08-11 21:59:14 +12:00
/**
* Assets loaded
**/
export function loadedMore(parent_type, parent_key, records_type, records_data){
return {
type: 'LOADED_MORE',
parent_type: parent_type,
parent_key: parent_key,
records_type: records_type,
records_data: records_data
}
}
2017-11-09 09:12:23 +13:00
export function tracksLoaded(tracks){
return {
2017-11-09 09:12:23 +13:00
type: 'TRACKS_LOADED',
tracks: tracks
}
}
export function albumsLoaded(albums){
return {
type: 'ALBUMS_LOADED',
albums: albums
}
}
export function artistsLoaded(artists){
return {
2017-12-30 10:49:56 +13:00
type: 'ARTISTS_LOADED',
artists: artists
}
}
2017-11-09 09:12:23 +13:00
export function playlistsLoaded(playlists){
return {
2017-11-09 09:12:23 +13:00
type: 'PLAYLISTS_LOADED',
playlists: playlists
}
}
2017-11-09 09:12:23 +13:00
export function usersLoaded(users){
return {
2017-11-09 09:12:23 +13:00
type: 'USERS_LOADED',
users: users
}
}