Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Maxence Bothorel
funkwhale
Commits
a34b1afd
Verified
Commit
a34b1afd
authored
Mar 19, 2018
by
Eliot Berriot
Browse files
Store for fetching user playlists
parent
15300e25
Changes
5
Hide whitespace changes
Inline
Side-by-side
front/src/store/auth.js
View file @
a34b1afd
...
...
@@ -91,6 +91,7 @@ export default {
commit
(
'
profile
'
,
data
)
commit
(
'
username
'
,
data
.
username
)
dispatch
(
'
favorites/fetch
'
,
null
,
{
root
:
true
})
dispatch
(
'
playlists/fetchOwn
'
,
null
,
{
root
:
true
})
Object
.
keys
(
data
.
permissions
).
forEach
(
function
(
key
)
{
// this makes it easier to check for permissions in templates
commit
(
'
permission
'
,
{
key
,
status
:
data
.
permissions
[
String
(
key
)].
status
})
...
...
front/src/store/index.js
View file @
a34b1afd
...
...
@@ -8,6 +8,7 @@ import instance from './instance'
import
queue
from
'
./queue
'
import
radios
from
'
./radios
'
import
player
from
'
./player
'
import
playlists
from
'
./playlists
'
import
ui
from
'
./ui
'
Vue
.
use
(
Vuex
)
...
...
@@ -20,6 +21,7 @@ export default new Vuex.Store({
instance
,
queue
,
radios
,
playlists
,
player
},
plugins
:
[
...
...
front/src/store/playlists.js
0 → 100644
View file @
a34b1afd
import
axios
from
'
axios
'
export
default
{
namespaced
:
true
,
state
:
{
playlists
:
[]
},
mutations
:
{
playlists
(
state
,
value
)
{
state
.
playlists
=
value
}
},
actions
:
{
fetchOwn
({
commit
,
rootState
})
{
let
userId
=
rootState
.
auth
.
profile
.
id
if
(
!
userId
)
{
return
}
return
axios
.
get
(
'
playlists/
'
,
{
params
:
{
user
:
userId
}}).
then
((
response
)
=>
{
commit
(
'
playlists
'
,
response
.
data
.
results
)
})
}
}
}
front/test/unit/specs/store/auth.spec.js
View file @
a34b1afd
...
...
@@ -180,7 +180,8 @@ describe('store/auth', () => {
{
type
:
'
permission
'
,
payload
:
{
key
:
'
admin
'
,
status
:
true
}
}
],
expectedActions
:
[
{
type
:
'
favorites/fetch
'
,
payload
:
null
,
options
:
{
root
:
true
}
}
{
type
:
'
favorites/fetch
'
,
payload
:
null
,
options
:
{
root
:
true
}
},
{
type
:
'
playlists/fetchOwn
'
,
payload
:
null
,
options
:
{
root
:
true
}
},
]
},
done
)
})
...
...
front/test/unit/specs/store/playlists.spec.js
0 → 100644
View file @
a34b1afd
var
sinon
=
require
(
'
sinon
'
)
import
moxios
from
'
moxios
'
import
store
from
'
@/store/playlists
'
import
{
testAction
}
from
'
../../utils
'
describe
(
'
store/playlists
'
,
()
=>
{
var
sandbox
beforeEach
(
function
()
{
sandbox
=
sinon
.
sandbox
.
create
()
moxios
.
install
()
})
afterEach
(
function
()
{
sandbox
.
restore
()
moxios
.
uninstall
()
})
describe
(
'
mutations
'
,
()
=>
{
it
(
'
set playlists
'
,
()
=>
{
const
state
=
{
playlists
:
[]
}
store
.
mutations
.
playlists
(
state
,
[{
id
:
1
,
name
:
'
test
'
}])
expect
(
state
.
playlists
).
to
.
deep
.
equal
([{
id
:
1
,
name
:
'
test
'
}])
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
fetchOwn does nothing with no user
'
,
(
done
)
=>
{
testAction
({
action
:
store
.
actions
.
fetchOwn
,
payload
:
null
,
params
:
{
state
:
{
playlists
:
[]
},
rootState
:
{
auth
:
{
profile
:
{}}}},
expectedMutations
:
[]
},
done
)
})
})
})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment