|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
import api from '../../utils/api'
|
|
2
|
2
|
import { sortTypes } from '../../utils/helpers'
|
|
|
3
|
+import { repackBySort } from './arrangements'
|
|
3
|
4
|
|
|
4
|
5
|
const state = {
|
|
5
|
6
|
all: [],
|
|
|
@@ -18,92 +19,12 @@ const getters = {
|
|
18
|
19
|
allArtistsLoaded: state => state.loaded,
|
|
19
|
20
|
}
|
|
20
|
21
|
|
|
21
|
|
-
|
|
22
|
|
-const _arrangeByMaterial = artistsList => {
|
|
23
|
|
- const byMaterial = {
|
|
24
|
|
- clay: []
|
|
25
|
|
- }
|
|
26
|
|
- artistsList.forEach(artist => {
|
|
27
|
|
- artist.materials.forEach(mat => {
|
|
28
|
|
- if(!byMaterial[mat]) byMaterial[mat] = []
|
|
29
|
|
- byMaterial[mat].push(artist)
|
|
30
|
|
- })
|
|
31
|
|
- })
|
|
32
|
|
- const flatPacked = []
|
|
33
|
|
- Object.keys(byMaterial).forEach(material => {
|
|
34
|
|
- flatPacked.push({ slug: material, title: material, inbetween: true })
|
|
35
|
|
- byMaterial[material].forEach(artist => flatPacked.push(artist))
|
|
36
|
|
- })
|
|
37
|
|
- return flatPacked
|
|
38
|
|
-}
|
|
39
|
|
-
|
|
40
|
|
-const _arrangeByType = artistsList => {
|
|
41
|
|
- const byType = {}
|
|
42
|
|
- artistsList.forEach(artist => {
|
|
43
|
|
- const subtypes = artist.subtypes
|
|
44
|
|
- subtypes.forEach(type => {
|
|
45
|
|
- if(!byType[type]) byType[type] = []
|
|
46
|
|
- byType[type].push(artist)
|
|
47
|
|
- })
|
|
48
|
|
- })
|
|
49
|
|
- const flatPacked = []
|
|
50
|
|
- Object.keys(byType).forEach(type => {
|
|
51
|
|
- flatPacked.push({ slug: type, title: type, inbetween: true })
|
|
52
|
|
- byType[type].forEach(artist => flatPacked.push(artist))
|
|
53
|
|
- })
|
|
54
|
|
- return flatPacked
|
|
55
|
|
-}
|
|
56
|
|
-
|
|
57
|
|
-const _arrangeByAlpha = artistsList => {
|
|
58
|
|
- const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
|
|
59
|
|
- const flatPacked = []
|
|
60
|
|
-
|
|
61
|
|
- const storeTitle = letter => {
|
|
62
|
|
- if(state.seenTitles.includes(letter)) return
|
|
63
|
|
- flatPacked.push({ slug: letter, title: letter, inbetween: true })
|
|
64
|
|
- state.seenTitles.push(letter)
|
|
65
|
|
- }
|
|
66
|
|
-
|
|
67
|
|
- artistsList.forEach(artist => {
|
|
68
|
|
- const lastWord = artist.slug.split('-').filter(c => c).pop()
|
|
69
|
|
- const firstCharaOflastWord = lastWord[0]
|
|
70
|
|
- const firstCharaOfSortWord = artist.sortname ? artist.sortname[0] : 'z'
|
|
71
|
|
- const charaIndex = alphabet.indexOf(firstCharaOflastWord) < alphabet.indexOf(firstCharaOfSortWord) ? alphabet.indexOf(firstCharaOflastWord) : alphabet.indexOf(firstCharaOfSortWord)
|
|
72
|
|
-
|
|
73
|
|
- storeTitle(alphabet[charaIndex])
|
|
74
|
|
- flatPacked.push(artist)
|
|
75
|
|
- })
|
|
76
|
|
- return flatPacked
|
|
77
|
|
-}
|
|
78
|
|
-
|
|
79
|
|
-const _arrangeByEpisode = artistsList => {
|
|
80
|
|
- const byEpisode = {}
|
|
81
|
|
- artistsList.forEach(artist => {
|
|
82
|
|
- const relatedEpisode = artist.related_episode
|
|
83
|
|
- if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
|
|
84
|
|
- byEpisode[relatedEpisode].push(artist)
|
|
85
|
|
- })
|
|
86
|
|
- const flatPacked = []
|
|
87
|
|
- Object.keys(byEpisode).forEach(episode => {
|
|
88
|
|
- flatPacked.push({ slug: episode, title: episode, inbetween: true })
|
|
89
|
|
- byEpisode[episode].forEach(artist => flatPacked.push(artist))
|
|
90
|
|
- })
|
|
91
|
|
- return flatPacked
|
|
92
|
|
-}
|
|
93
|
|
-
|
|
94
|
22
|
const actions = {
|
|
95
|
23
|
getAllArtists({ commit }, { sortType, params }) {
|
|
96
|
24
|
commit('CLEAR_ARTISTS')
|
|
97
|
25
|
commit('ARTISTS_LOADED', false)
|
|
98
|
26
|
const storeFetch = (artists => {
|
|
99
|
|
- let repacked = artists
|
|
100
|
|
- if(sortType == sortTypes.material) {
|
|
101
|
|
- repacked = _arrangeByMaterial(artists)
|
|
102
|
|
- } else if(sortType == sortTypes.episode) {
|
|
103
|
|
- repacked = _arrangeByEpisode(artists)
|
|
104
|
|
- } else if(sortType == sortTypes.subtype) {
|
|
105
|
|
- repacked = _arrangeByType(artists)
|
|
106
|
|
- }
|
|
|
27
|
+ let repacked = repackBySort(artists, sortType)
|
|
107
|
28
|
commit('STORE_FETCHED_ARTISTS', { artists: repacked })
|
|
108
|
29
|
commit('ARTISTS_LOADED', true)
|
|
109
|
30
|
})
|
|
|
@@ -113,7 +34,7 @@ const actions = {
|
|
113
|
34
|
const storeFetch = (artists => {
|
|
114
|
35
|
let repacked = artists
|
|
115
|
36
|
if(sortType == sortTypes.alpha) {
|
|
116
|
|
- repacked = _arrangeByAlpha(artists)
|
|
|
37
|
+ repacked = repackBySort(artists, sortType)
|
|
117
|
38
|
}
|
|
118
|
39
|
commit('ADD_TO_FETCHED_ARTISTS', { artists: repacked })
|
|
119
|
40
|
commit('ARTISTS_LOADED', true)
|