Przeglądaj źródła

:recycle: load past exhibitions or events if no upcoming

tags/0.9.0
j 4 lat temu
rodzic
commit
f9f2d9c913
1 zmienionych plików z 18 dodań i 10 usunięć
  1. 18
    10
      vue-theme/src/pages/index.vue

+ 18
- 10
vue-theme/src/pages/index.vue Wyświetl plik

@@ -23,6 +23,7 @@
23 23
             ul.w-max
24 24
                 li.shadow(v-for="post in [randomPostOfType(secondRow)]")
25 25
                     card(v-if="post" :content="post" :type="`${post.type}s`" :wide="true")
26
+
26 27
         //- (thirdRow) firstRow.flipped: ['guides', 'objects', 'techniques', 'talks', 'center'], exceprt on guides only
27 28
         section
28 29
             ul.flipped
@@ -47,23 +48,29 @@ export default {
47 48
             thirdRow: ['episodes', 'exhibitions', 'events', 'artists', 'posts'],
48 49
         }
49 50
     },
50
-    created() {
51
+    async created() {
51 52
         // console.log(wp)
52
-        postTypes.forEach(type => {
53
-            const capitalizedType = convertTitleCase(type)
53
+        const omit = ['events', 'exhibitions']
54
+        for (let type of postTypes) {
55
+            const action = `getAll${convertTitleCase(type)}`
54 56
 
55 57
             // We try and fetch EVERYTHING except
56
-            // for EVENTS and EXHIBITIONS we only grab
57
-            // the current or upcoming on load
58
-            if (!['events', 'exhibitions'].includes(type)) {
59
-                this.$store.dispatch(`getAll${capitalizedType}`)
58
+            // for EVENTS and EXHIBITIONS
59
+            if (!omit.includes(type)) {
60
+                this.$store.dispatch(action)
60 61
             } else {
61
-                this.$store.dispatch(
62
-                    `getAll${capitalizedType}`,
62
+                // Only grab the current or upcoming on load
63
+                const eventsOrExhibitions = await this.$store.dispatch(
64
+                    action,
63 65
                     sortTypes.currentAndUpcoming,
64 66
                 )
67
+                // If no current or upcoming, get past events
68
+                // to fill in the blanks
69
+                if (eventsOrExhibitions.length < 1) {
70
+                    this.$store.dispatch(action, sortTypes.past)
71
+                }
65 72
             }
66
-        })
73
+        }
67 74
         this.checkAndSetHero('welcome')
68 75
     },
69 76
     methods: {
@@ -91,6 +98,7 @@ export default {
91 98
             const postsOfType = Object.values(
92 99
                 this[`all${convertTitleCase(type)}`],
93 100
             )
101
+            // console.log(postsOfType)
94 102
             const max = postsOfType.length
95 103
             const rand = Math.floor(Math.random() * max)
96 104
             return postsOfType[rand]

Ładowanie…
Anuluj
Zapisz