1 | export default function initSelects ({ guilds, threads }) {
|
2 | if (guilds) {
|
3 | initChannels(guilds)
|
4 | initGuilds(guilds)
|
5 | }
|
6 | if (threads) initThreads(threads)
|
7 | }
|
8 |
|
9 | export function initThreads (threads) {
|
10 | $('.messenger-thread-select').select2({
|
11 | placeholder: 'Select a Messenger chat',
|
12 | data: threads
|
13 | .toArray()
|
14 | .map(thread => ({
|
15 | id: thread.id,
|
16 | text: thread.name
|
17 | }))
|
18 | })
|
19 | }
|
20 |
|
21 | export function initChannels (guilds) {
|
22 | $('.discord-channel-select').select2({
|
23 | placeholder: 'Select a Discord channel',
|
24 | data: guilds.map(guild => ({
|
25 | text: guild.name,
|
26 | children: guild.channels
|
27 | .filter(channel => channel.type === 'text')
|
28 | .toArray()
|
29 | .map(channel => ({
|
30 | id: channel.id,
|
31 | text: channel.category
|
32 | ? `[${guild.channels.get(channel.category).name}] #${channel.name}`
|
33 | : `#${channel.name}`
|
34 | }))
|
35 | }))
|
36 | })
|
37 | }
|
38 |
|
39 | export function initGuilds (guilds) {
|
40 | $('.discord-guild-select').select2({
|
41 | placeholder: 'Select a Discord server',
|
42 | data: guilds.map(guild => ({
|
43 | id: guild.id,
|
44 | text: guild.name
|
45 | }))
|
46 | })
|
47 | }
|
48 |
|
49 | export function initCategories (guild) {
|
50 | $('.discord-category-select').select2({
|
51 | placeholder: 'Select a category',
|
52 | data: guild.channels
|
53 | .filter(channel => channel.type === 'category')
|
54 | .toArray()
|
55 | .map(category => ({
|
56 | id: category.id,
|
57 | text: category.name
|
58 | }))
|
59 | })
|
60 | }
|