Home.vue 2.42 KB
Newer Older
1
<template>
Bat's avatar
Bat committed
2
  <div v-title="'Home'">
3
4
5
6
    <div class="ui vertical stripe segment">
      <search :autofocus="true"></search>
    </div>
    <div class="ui vertical stripe segment">
Eliot Berriot's avatar
Eliot Berriot committed
7
      <div class="ui stackable three column grid">
8
9
10
        <div class="column">
          <h2 class="ui header">Latest artists</h2>
          <div :class="['ui', {'active': isLoadingArtists}, 'inline', 'loader']"></div>
Eliot Berriot's avatar
Eliot Berriot committed
11
          <div v-if="artists.length > 0" v-for="artist in artists.slice(0, 3)" :key="artist.id" class="ui cards">
12
13
14
15
16
17
18
19
20
            <artist-card :artist="artist"></artist-card>
          </div>
        </div>
        <div class="column">
          <h2 class="ui header">Radios</h2>
          <radio-card :type="'favorites'"></radio-card>
          <radio-card :type="'random'"></radio-card>
          <radio-card :type="'less-listened'"></radio-card>
        </div>
Eliot Berriot's avatar
Eliot Berriot committed
21
22
        <div class="column">
          <h2 class="ui header">Music requests</h2>
23
          <request-form v-if="$store.state.auth.authenticated"></request-form>
Eliot Berriot's avatar
Eliot Berriot committed
24
        </div>
25
26
27
28
29
30
      </div>
    </div>
  </div>
</template>

<script>
Eliot Berriot's avatar
Eliot Berriot committed
31
import axios from 'axios'
32
33
34
35
36
import Search from '@/components/audio/Search'
import backend from '@/audio/backend'
import logger from '@/logging'
import ArtistCard from '@/components/audio/artist/Card'
import RadioCard from '@/components/radios/Card'
Eliot Berriot's avatar
Eliot Berriot committed
37
import RequestForm from '@/components/requests/Form'
38

Eliot Berriot's avatar
Eliot Berriot committed
39
const ARTISTS_URL = 'artists/'
40
41

export default {
42
  name: 'library',
43
44
45
  components: {
    Search,
    ArtistCard,
Eliot Berriot's avatar
Eliot Berriot committed
46
47
    RadioCard,
    RequestForm
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  },
  data () {
    return {
      artists: [],
      isLoadingArtists: false
    }
  },
  created () {
    this.fetchArtists()
  },
  methods: {
    fetchArtists () {
      var self = this
      this.isLoadingArtists = true
      let params = {
        ordering: '-creation_date'
      }
      let url = ARTISTS_URL
      logger.default.time('Loading latest artists')
Eliot Berriot's avatar
Eliot Berriot committed
67
      axios.get(url, {params: params}).then((response) => {
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        self.artists = response.data.results
        self.artists.map((artist) => {
          var albums = JSON.parse(JSON.stringify(artist.albums)).map((album) => {
            return backend.Album.clean(album)
          })
          artist.albums = albums
          return artist
        })
        logger.default.timeEnd('Loading latest artists')
        self.isLoadingArtists = false
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>