summaryrefslogtreecommitdiffstats
path: root/src/views/Home.vue
blob: 2954857392430b3003fc3f4424d0e58e690cc962 (plain)
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
54
<template>
  <div class="home" v-hotkey="keymap">
    Hi {{get_username}}!
    <input type="button" value="Logout!" @click="logout">
    <Searcher v-if="show" @close="hide" />
  </div>
</template>

<script>
import Searcher from '@/components/Searcher.vue'

export default {
  data() {
    return {
      show: false,
    }
  },

  methods: {
    logout() {
      this.$store.dispatch('logout')
      this.$router.push('/login')
    },
    
    toogleShow() { this.show = !this.show },
    hide() { this.show = false }
  },

  computed: {
    get_username() {
      return this.$store.getters['get_user'].username
    },

    keymap() {
      return { 
        'ctrl+esc': this.toogleShow,
        'ctrl+shift+p': this.toogleShow,
        'esc': this.hide
      }
    }
  },

  components: {
    Searcher
  },

  created() {
    if(!this.$store.getters['is_logged_in']) {
      this.$router.push('/login')
    }
  }
  
}
</script>