aboutsummaryrefslogtreecommitdiff
path: root/src/components/navigation/navigation.js
blob: face430ed71efc0d66d7a62bb9c7133c23f788a5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export const USERNAME_ROUTES = new Set([
  'bookmarks',
  'dms',
  'interactions',
  'notifications',
  'chat',
  'chats',
  'user-profile'
])

export const TIMELINES = {
  home: {
    route: 'friends',
    icon: 'home',
    label: 'nav.home_timeline',
    criteria: ['!private']
  },
  public: {
    route: 'public-timeline',
    anon: true,
    icon: 'users',
    label: 'nav.public_tl',
    criteria: ['!private']
  },
  twkn: {
    route: 'public-external-timeline',
    anon: true,
    icon: 'globe',
    label: 'nav.twkn',
    criteria: ['!private', 'federating']
  },
  bookmarks: {
    route: 'bookmarks',
    icon: 'bookmark',
    label: 'nav.bookmarks'
  },
  favorites: {
    routeObject: { name: 'user-profile', query: { tab: 'favorites' } },
    icon: 'star',
    label: 'user_card.favorites'
  },
  dms: {
    route: 'dms',
    icon: 'envelope',
    label: 'nav.dms'
  }
}

export const ROOT_ITEMS = {
  interactions: {
    route: 'interactions',
    icon: 'bell',
    label: 'nav.interactions'
  },
  chats: {
    route: 'chats',
    icon: 'comments',
    label: 'nav.chats',
    badgeGetter: 'unreadChatCount',
    criteria: ['chats']
  },
  friendRequests: {
    route: 'friend-requests',
    icon: 'user-plus',
    label: 'nav.friend_requests',
    criteria: ['lockedUser'],
    badgeGetter: 'followRequestCount'
  },
  about: {
    route: 'about',
    anon: true,
    icon: 'info-circle',
    label: 'nav.about'
  },
  announcements: {
    route: 'announcements',
    icon: 'bullhorn',
    label: 'nav.announcements',
    badgeGetter: 'unreadAnnouncementCount',
    criteria: ['announcements']
  }
}

export function routeTo (item, currentUser) {
  if (!item.route && !item.routeObject) return null

  let route

  if (item.routeObject) {
    route = item.routeObject
  } else {
    route = { name: (item.anon || currentUser) ? item.route : item.anonRoute }
  }

  if (USERNAME_ROUTES.has(route.name)) {
    route.params = { username: currentUser.screen_name, name: currentUser.screen_name }
  }

  return route
}