joinpeertube/src/components/ContentSelections.vue

76 lines
2 KiB
Vue
Raw Normal View History

<template>
2019-10-24 10:53:33 +00:00
<div id="content-selections">
<div class="content-selection" v-for="contentSelection in getContentSelections()" :key="contentSelection.url">
<content-selection :type="contentSelection.type" :title="contentSelection.title"
2019-10-31 10:46:59 +00:00
:thumbnail-name="contentSelection.thumbnailName" :url="contentSelection.url" :tags="contentSelection.tags"
:description="contentSelection.description"
>
</content-selection>
</div>
</div>
</template>
2019-10-24 10:53:33 +00:00
<style lang="scss">
@import '../scss/_variables';
2019-10-24 10:53:33 +00:00
#content-selections {
.content-selection {
margin-bottom: 80px;
}
2019-10-24 10:53:33 +00:00
.discover-instances {
display: flex;
justify-content: flex-end;
}
}
</style>
<script>
import ContentSelection from './ContentSelection'
import ContentSelectionsEN from '../mixins/ContentSelectionsEN'
import ContentSelectionsFR from '../mixins/ContentSelectionsFR'
import sampleSize from 'lodash/sampleSize'
export default {
mixins: [
ContentSelectionsEN,
ContentSelectionsFR
],
props: {
sampleSizeEach: Number
},
components: {
ContentSelection
},
methods: {
getContentSelections () {
if (this.$language.current.startsWith('fr_')) {
return this.sampleIfNeeded(this.contentSelectionsFR)
}
return this.sampleIfNeeded(this.contentSelectionsEN)
},
sampleIfNeeded (objects) {
const videos = []
const channels = []
const instances = []
for (const o of objects) {
if (o.type === 'video') videos.push(o)
else if (o.type === 'channel') channels.push(o)
else if (o.type === 'instance') instances.push(o)
else console.error('Unknown content selection type %s.', o.type)
}
return sampleSize(videos, this.sampleSizeEach || videos.length)
.concat(sampleSize(channels, this.sampleSizeEach || channels.length))
.concat(sampleSize(instances, this.sampleSizeEach || instances.length))
}
}
}
</script>