aboutsummaryrefslogtreecommitdiff
path: root/src/components/navigation/navigation_entry.js
blob: d8866c12b63a59fc7b731c68b1fd47d3a20a5f5d (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
import { mapState } from 'vuex'
import { USERNAME_ROUTES } from 'src/components/navigation/navigation.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faThumbtack } from '@fortawesome/free-solid-svg-icons'

library.add(faThumbtack)

const NavigationEntry = {
  props: ['item', 'showPin'],
  methods: {
    isPinned (value) {
      return this.pinnedItems.has(value)
    },
    togglePin (value) {
      if (this.isPinned(value)) {
        this.$store.commit('removeCollectionPreference', { path: 'collections.pinnedNavItems', value })
      } else {
        this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value })
      }
      this.$store.dispatch('pushServerSideStorage')
    }
  },
  computed: {
    routeTo () {
      if (this.item.routeObject) {
        return this.item.routeObject
      }
      const route = { name: (this.item.anon || this.currentUser) ? this.item.route : this.item.anonRoute }
      if (USERNAME_ROUTES.has(route.name)) {
        route.params = { username: this.currentUser.screen_name }
      }
      return route
    },
    getters () {
      return this.$store.getters
    },
    ...mapState({
      currentUser: state => state.users.currentUser,
      pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedNavItems)
    })
  }
}

export default NavigationEntry