-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (51 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
Vue.use(Vuex)
export default new Vuex.Store({
state: {
videos: [],
selectedVideo: null,
videoComments: {}
},
getters: {
getVideoComments(state) {
return (videoId) => {
console.log('coments', state.videoComments[videoId])
return state.videoComments[videoId] || [];
}
}
},
mutations: {
SET_VIDEOS (state, videos) {
state.videos = videos;
},
SET_SELECTED_VIDEO (state, selectedVideo) {
state.selectedVideo = selectedVideo;
},
ADD_VIDEO_COMMENT(state, { videoId, comment }) {
if (state.videoComments[videoId]) {
state.videoComments[videoId].push(comment);
} else {
state.videoComments[videoId] = [];
state.videoComments[videoId].push(comment);
}
}
},
actions: {
onTermChange(ctx, searchTerm) {
axios
.get("https://www.googleapis.com/youtube/v3/search", {
params: {
key: process.env.VUE_APP_YT_API_KEY,
type: "video",
part: "snippet",
q: searchTerm
}
})
.then(({ data }) => {
ctx.commit('SET_VIDEOS', data.items);
});
}
}
});