Commit 4e4ad0ef authored by Genar Trias Ortiz's avatar Genar Trias Ortiz 🎉

adding settings providers to reducer

parent bbc82aee
Pipeline #57151691 passed with stages
in 6 minutes and 3 seconds
......@@ -57,10 +57,11 @@ describe('settings reducer', () => {
})
it('should handle ADD_PROVIDER', () => {
expect(reducer(undefined, {type: types.ADD_PROVIDER}))
expect(reducer(undefined, {type: types.ADD_PROVIDER, providerId: 'subsonic'}))
.toEqual(
{
...defaultState
...defaultState,
providers: [{key: 'subsonic-0'}]
}
)
})
......
......@@ -16,24 +16,7 @@ export const defaultState = {
saving: false,
settingsForm: settingsBuilder.getFormSchema(),
settings: {
providers: [
{
key: 'itunes',
enabled: false
},
{
key: 'mstream',
enabled: false,
baseUrl: '',
},
{
key: 'subsonic',
enabled: false,
baseUrl: '',
user: '',
password: ''
}
],
providers: [],
app: {
spectrum: {
enabled: true
......@@ -49,6 +32,19 @@ export default (state: State = defaultState, action: any = {}) => {
return {...state, settings: action.settings}
}
case types.ADD_PROVIDER: {
const { settings } = state
let providerAutoinc = 0
for (let i = 0; i < settings.providers.length; i++) {
if (settings.providers[i].key === action.providerId + '-' + i) {
providerAutoinc++
}
}
const newProvider = {key: action.providerId + '-' + providerAutoinc}
return {...state, providers: [...state.settings.providers, newProvider]}
}
default:
return state
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment