<template>
    <div class="content">
        <FilterBar
            :fetch-releases="fetchReleases"
            :is-home="true"
        />

        <div class="content-inner">
            <Releases :releases="releases" />
        </div>
    </div>
</template>

<script>
import FilterBar from '../header/filter-bar.vue';
import Releases from '../releases/releases.vue';

async function fetchReleases() {
    this.releases = await this.$store.dispatch('fetchReleases', {
        limit: (this.$route.query && this.$route.query.limit && Number(this.$route.query.limit)) || 30,
        range: this.$route.name,
    });
}

async function route() {
    await this.fetchReleases();
}

async function mounted() {
    this.pageTitle = '';

    await this.fetchReleases();
}

export default {
    components: {
        FilterBar,
        Releases,
    },
    data() {
        return {
            releases: [],
            networks: [],
            pageTitle: null,
            from: null,
        };
    },
    beforeRouteEnter(to, from, next) {
        next(vm => vm.$set(vm, 'from', from));
    },
    watch: {
        $route: route,
    },
    mounted,
    methods: {
        fetchReleases,
    },
};
</script>
