Skip to content

Commit

Permalink
feat(home): integrate youtube videos (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosirera committed Aug 26, 2020
1 parent c468ce1 commit d61ccb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
40 changes: 20 additions & 20 deletions components/home/YoutubeVideos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
{{ $t('home.lastVideos') }}
</h2>
<a
v-for="(video, index) in videos"
v-for="(video, index) in allVideos"
:key="index"
class="flex justify-start mb-4 cursor-pointer p-2 rounded hover:bg-green-main-700-40"
@click="showVideo(video.id)"
@click="showVideo(video.shortId)"
>
<img
:src="`https://i3.ytimg.com/vi/${video.id}/mqdefault.jpg`"
:src="`https://i3.ytimg.com/vi/${video.shortId}/mqdefault.jpg`"
:alt="video.title"
loading="lazy"
class="w-40 h-24 rounded"
Expand Down Expand Up @@ -43,27 +43,27 @@
<script>
export default {
name: 'YoutubeVideos',
props: {
videos: {
type: Array,
default: () => [],
},
},
data: () => ({
shouldShowVideo: false,
videoId: null,
// TODO: maybe translate this
// TODO: integrate with youtube api
videos: [
{
title: 'Añadir modo oscuro a una aplicación VUE | 🔴 Live Coding #12',
id: 'FcxlrEwrJkw',
},
{
title:
'Mejorando nuestra aplicación con Vue y FIREBASE | 🔴 Live Coding #11',
id: 'McZZrYNBhTc',
},
{
title: 'Crear un blog con Nuxt y Nuxt Content + SEO tips | 🔴 Live',
id: '1W_3c7O9E8k',
},
],
}),
computed: {
allVideos() {
return this.videos.map((video) => {
return {
title: video.snippet.title,
id: video.id,
shortId: video.snippet.resourceId.videoId,
}
})
},
},
methods: {
showVideo(videoId) {
this.videoId = videoId
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default {
GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID,
APP_TITLE: process.env.APP_TITLE,
APP_DESC: process.env.APP_DESC,
YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY,
},
/*
** color mode config
Expand Down
11 changes: 9 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
/>
</div>
</section>
<section class="mt-12 md:grid md:grid-cols-2 md:gap-8">
<YoutubeVideos />
<section class="mt-12 md:grid md:grid-cols-2 md:gap-4">
<YoutubeVideos :videos="videos" />
<ListPosts :posts="posts" />
</section>
</section>
Expand All @@ -61,8 +61,15 @@ export default {
.limit(3)
.fetch()
const videosResponse = await fetch(
`https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUl41m8HBifhzM6Dh1V04wqA&maxResults=3&key=${process.env.YOUTUBE_API_KEY}`
)
const jsonVideos = await videosResponse.json()
const videos = jsonVideos.items
return {
posts,
videos,
}
},
}
Expand Down

0 comments on commit d61ccb3

Please sign in to comment.