add track Redux store && TODO -> complete track store

develop
TBS093A 2020-08-07 20:52:51 +02:00
parent 6561a90f17
commit 553feb7c62
5 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import types from './types'
const getOne = item => ({
type: types.GET_ONE, item
})
const update = item => ({
type: types.UPDATE, item
})
const addRow = item => ({
type: types.ADD_ROW, item
})
export default ({
getOne,
update,
addRow
})

View File

@ -0,0 +1,5 @@
import trackReducer from './reducers'
export { default as trackTypes } from './types'
export { default as trackActions } from './actions'
export default trackReducer

View File

@ -0,0 +1,76 @@
import AppService from '../../AppService'
import actions from './actions'
const trackEndpoint = 'track/'
const trackRowEndpoint = 'track-row/'
// Track CRUD
export const getOneTrack = ( id ) => async (dispatch) => {
return await AppService._getOne(
trackEndpoint + id + '/'
).then( response => {
dispatch( actions.getOne( response ) )
return response
})
}
export const createTrack = async ( track, token ) => {
return await AppService._post(
trackEndpoint,
track,
token
)
}
export const updateTrack = async ( id, track, token ) => {
return await AppService._patch(
trackEndpoint + id + '/',
track,
token
)
}
export const deleteTrack = async ( id ) => {
return await AppService._delete(
trackEndpoint + id + '/',
token
)
}
// Track Row CRUD
export const getOneTrackRow = ( id ) => async (dispatch) => {
return await AppService._getOne(
trackRowEndpoint + id + '/'
).then( response => {
dispatch( actions.getOne( response ) )
return response
})
}
export const createTrackRow = async ( track, token ) => {
return await AppService._post(
trackRowEndpoint,
track,
token
)
}
export const updateTrackRow = async ( id, track, token ) => {
return await AppService._patch(
trackRowEndpoint + id + '/',
track,
token
)
}
export const deleteTrackRow = async ( id ) => {
return await AppService._delete(
trackRowEndpoint + id + '/',
token
)
}
// Track Ratings CRUD

View File

@ -0,0 +1,54 @@
import types from './types'
const INITIAL_STATE = {
id: -1,
album_id: -1,
user_id: -1,
title: '',
description: '',
text: '',
image: '',
audio: '',
url_code: '',
track_rows: []
}
const trackReducer = ( state = INITIAL_STATE, action ) => {
switch(action.type) {
case types.GET_ONE:
return {
id: action.item.id,
album_id: action.item.album_id,
user_id: action.item.user_id,
title: action.item.title,
description: action.item.description,
text: action.item.text,
image: action.item.image,
audio: action.item.audio,
url_code: action.item.url_code,
track_rows: action.item.track_rows
}
case types.UPDATE:
return {
...state,
id: action.item.id,
album_id: action.item.album_id,
user_id: action.item.user_id,
title: action.item.title,
description: action.item.description,
text: action.item.text,
image: action.item.image,
audio: action.item.audio,
url_code: action.item.url_code,
}
case types.ADD_ROW:
return {
...state,
track_rows: [ ...state.track_rows, action.item ]
}
default:
return state
}
}
export default trackReducer

View File

@ -0,0 +1,9 @@
const GET_ONE = 'GET_ONE'
const UPDATE = 'UPDATE'
const ADD_ROW = 'ADD_ROW'
export default ({
GET_ONE,
UPDATE,
ADD_ROW
})