Sfoglia il codice sorgente

:sparkles: sticky posts visible on the homepage template

tags/0.9.0
j 4 anni fa
parent
commit
9ebc2d96c8

+ 8
- 0
vue-theme/src/pages/index.vue Vedi File

2
 <template lang="pug">
2
 <template lang="pug">
3
 .page--index.f-row.between
3
 .page--index.f-row.between
4
     article.f-grow
4
     article.f-grow
5
+        .f-row
6
+            h3(v-if="!allStickyLoaded") loading...
7
+            section(v-else-if="allStickyLoaded").shadow
8
+                h4.t-cap sticky
9
+                ul
10
+                    li(v-for="sticky in allSticky")
11
+                        p {{ sticky.type }}: {{ sticky.title }}
5
         .f-row
12
         .f-row
6
             h3(v-if="!allPagesLoaded") loading...
13
             h3(v-if="!allPagesLoaded") loading...
7
             .content(v-else-if="allPages['welcome']" v-html="allPages['welcome'].content")
14
             .content(v-else-if="allPages['welcome']" v-html="allPages['welcome'].content")
44
     mixins: [postTypeGetters, scrollTop],
51
     mixins: [postTypeGetters, scrollTop],
45
     created() {
52
     created() {
46
         // console.log(wp)
53
         // console.log(wp)
54
+        this.$store.dispatch(`getAllSticky`)
47
         postTypes.forEach(type => {
55
         postTypes.forEach(type => {
48
             const capitalizedType = convertTitleCase(type)
56
             const capitalizedType = convertTitleCase(type)
49
             this.$store.dispatch(`getAll${capitalizedType}`)
57
             this.$store.dispatch(`getAll${capitalizedType}`)

+ 2
- 0
vue-theme/src/store/index.js Vedi File

11
 import episodes from './modules/episode'
11
 import episodes from './modules/episode'
12
 import events from './modules/event'
12
 import events from './modules/event'
13
 import exhibitions from './modules/exhibition'
13
 import exhibitions from './modules/exhibition'
14
+import sticky from './modules/sticky'
14
 
15
 
15
 const debug = process.env.NODE_ENV !== 'production'
16
 const debug = process.env.NODE_ENV !== 'production'
16
 
17
 
70
         episodes,
71
         episodes,
71
         events,
72
         events,
72
         exhibitions,
73
         exhibitions,
74
+        sticky,
73
     },
75
     },
74
     strict: debug,
76
     strict: debug,
75
 })
77
 })

+ 36
- 0
vue-theme/src/store/modules/sticky.js Vedi File

1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+}
7
+
8
+const getters = {
9
+    allSticky: state => state.all,
10
+    allStickyLoaded: state => state.loaded,
11
+}
12
+
13
+const actions = {
14
+    getAllSticky({ commit }, sortType) {
15
+        commit('CLEAR_POSTS')
16
+        commit('POSTS_LOADED', false)
17
+        return api.getSticky(posts => {
18
+            commit('STORE_FETCHED_POSTS', { posts })
19
+            commit('POSTS_LOADED', true)
20
+        })
21
+    },
22
+}
23
+
24
+const mutations = {
25
+    STORE_FETCHED_POSTS(state, { posts }) {
26
+        state.all = posts
27
+    },
28
+    CLEAR_POSTS(state) {
29
+        state.all = []
30
+    },
31
+    POSTS_LOADED(state, val) {
32
+        state.loaded = val
33
+    },
34
+}
35
+
36
+export default { state, getters, actions, mutations }

+ 10
- 0
vue-theme/src/utils/api.js Vedi File

51
             })
51
             })
52
     },
52
     },
53
 
53
 
54
+    getSticky(cb) {
55
+        axios
56
+            .get(SETTINGS.API_BASE_PATH + 'sticky')
57
+            .then(response => {
58
+                cb(response.data)
59
+            })
60
+            .catch(e => {
61
+                cb(e)
62
+            })
63
+    },
54
     getPosts(limit = 5, cb) {
64
     getPosts(limit = 5, cb) {
55
         axios
65
         axios
56
             .get(SETTINGS.API_BASE_PATH + 'posts')
66
             .get(SETTINGS.API_BASE_PATH + 'posts')

+ 3
- 2
vue-theme/src/utils/helpers.js Vedi File

27
     'events',
27
     'events',
28
     'posts',
28
     'posts',
29
     'pages',
29
     'pages',
30
+    'sticky',
30
 ]
31
 ]
31
 
32
 
32
 /**
33
 /**
59
         'youtu.be',
60
         'youtu.be',
60
         'www.youtube.com',
61
         'www.youtube.com',
61
         'youtube.com',
62
         'youtube.com',
62
-        'embed'
63
+        'embed',
63
     ]
64
     ]
64
     const videoId = url
65
     const videoId = url
65
         .split('/')
66
         .split('/')
66
         .filter(urlSection => !remove.includes(urlSection))
67
         .filter(urlSection => !remove.includes(urlSection))
67
-        
68
+
68
     // Uncomment to see what the url transformer is finding
69
     // Uncomment to see what the url transformer is finding
69
     // console.log('video:', videoId[0])
70
     // console.log('video:', videoId[0])
70
     let size = '0'
71
     let size = '0'

Loading…
Annulla
Salva