Переглянути джерело

:recycle: simplifying singlee watcher | addressing #125

tags/0.9.0
J 4 роки тому
джерело
коміт
52ef76a28e

+ 2
- 6
vue-theme/src/pages/single.vue Переглянути файл

223
     watch: {
223
     watch: {
224
         slug(newSlug, oldSlug) {
224
         slug(newSlug, oldSlug) {
225
             // ONLY load post data when navigating TO a single page
225
             // ONLY load post data when navigating TO a single page
226
-            if(newSlug && !oldSlug) {
227
-                this._clearHero(this.$store)
228
-                this.loadPostData()
229
-            }
230
-            // ONLY load post data when navigating TO a single page from a single page
231
-            if(newSlug && oldSlug) {
226
+            // OR when navigating TO a single page from a single page
227
+            if(newSlug && !oldSlug || newSlug && oldSlug) {
232
                 this._clearHero(this.$store)
228
                 this._clearHero(this.$store)
233
                 this.loadPostData()
229
                 this.loadPostData()
234
             }
230
             }

+ 8
- 17
vue-theme/src/store/modules/artist.js Переглянути файл

36
     return flatPacked
36
     return flatPacked
37
 }
37
 }
38
 
38
 
39
+let seenTitles = []
39
 const _arrangeByAlpha = artistsList => {
40
 const _arrangeByAlpha = artistsList => {
40
     const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
41
     const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
41
     const flatPacked = []
42
     const flatPacked = []
42
-    let seen = 0
43
-    let hasTitle = []
44
 
43
 
45
     const storeTitle = letter => {
44
     const storeTitle = letter => {
46
-        if(hasTitle.includes(letter)) return
45
+        if(seenTitles.includes(letter)) return
47
         flatPacked.push({ slug: letter, title: letter, inbetween: true })
46
         flatPacked.push({ slug: letter, title: letter, inbetween: true })
48
-        hasTitle.push(letter)
47
+        seenTitles.push(letter)
49
     }
48
     }
50
 
49
 
51
-    artistsList.forEach((artist, i) => {
50
+    artistsList.forEach(artist => {
52
         const lastWord = artist.slug.split('-').filter(c => c).pop()
51
         const lastWord = artist.slug.split('-').filter(c => c).pop()
52
+        const firstCharaOflastWord = lastWord[0]
53
         const firstCharaOfSortWord = artist.sortname ? artist.sortname[0] : 'z'
53
         const firstCharaOfSortWord = artist.sortname ? artist.sortname[0] : 'z'
54
-        const charaIndex = alphabet.indexOf(lastWord[0]) < alphabet.indexOf(firstCharaOfSortWord) ? alphabet.indexOf(lastWord[0]) : alphabet.indexOf(firstCharaOfSortWord)
55
-        
56
-        // The first artist you've seen in THIS BATCH
57
-        if(i == 0) {
58
-            seen = charaIndex
59
-            storeTitle(alphabet[seen])
60
-        }
61
-        if (charaIndex == seen + 1) {
62
-            seen++
63
-            if(seen > alphabet.length) seen = 0
64
-            storeTitle(alphabet[seen])
65
-        }
54
+        const charaIndex = alphabet.indexOf(firstCharaOflastWord) < alphabet.indexOf(firstCharaOfSortWord) ? alphabet.indexOf(firstCharaOflastWord) : alphabet.indexOf(firstCharaOfSortWord)
55
+
56
+        storeTitle(alphabet[charaIndex])
66
         flatPacked.push(artist)
57
         flatPacked.push(artist)
67
     })
58
     })
68
     return flatPacked
59
     return flatPacked

Завантаження…
Відмінити
Зберегти