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

library.add(faThumbtack)

const USERNAME_ROUTES = new Set([
  'bookmarks',
  'dms',
  'interactions',
  'notifications',
  'chat',
  'chats'
])

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