aboutsummaryrefslogtreecommitdiff
path: root/src/components/timeline_menu/timeline_menu_content.js
blob: c5b1cff21b73409780e7dde6ab3c2d2c2937eb4a (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 {
  faUsers,
  faGlobe,
  faBookmark,
  faEnvelope,
  faHome
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faUsers,
  faGlobe,
  faBookmark,
  faEnvelope,
  faHome
)

const TimelineMenuContent = {
  props: ['content'],
  methods: {
    isPinned (item) {
      return this.pinnedItems.has(item)
    },
    togglePin (item) {
      if (this.isPinned(item)) {
        this.$store.commit('removeCollectionPreference', { path: 'collections.pinnedNavItems', value: item })
      } else {
        this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value: item })
      }
    }
  },
  computed: {
    ...mapState({
      currentUser: state => state.users.currentUser,
      privateMode: state => state.instance.private,
      federating: state => state.instance.federating,
      pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedNavItems)
    }),
    list () {
      return (this.content || []).filter(({ criteria, anon, anonRoute }) => {
        const set = new Set(criteria || [])
        if (!this.federating && set.has('federating')) return false
        if (this.private && set.has('!private')) return false
        if (!this.currentUser && !(anon || anonRoute)) return false
        return true
      })
    }
  }
}

export default TimelineMenuContent