-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappNavigation.js
79 lines (74 loc) · 2.75 KB
/
appNavigation.js
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
import { LightningElement, track } from 'lwc';
import { publish, subscribe } from 'services/pubsub';
// import { publish, MessageContext } from 'lightning/messageService';
// import STATE from '@salesforce/messageChannel/App_Service__c';
export default class AppNavigation extends LightningElement {
activeApp = 'Home';
// @wire(MessageContext)
// messageContext;
isVisible = true;
classCombinationActive =
'navItem slds-context-bar__item slds-shrink-none slds-is-active';
classCombinationInactive =
'navItem slds-context-bar__item slds-shrink-none';
connectedCallback() {
// const payload = {
// activeApp: this.activeApp
// };
// publish(this.messageContext, STATE, payload);
subscribe('appChannel', (data) => {
this.activeApp = data.activeApp;
this.navItems.map((item) => {
if (item.label === this.activeApp) {
item.classCombination = this.classCombinationActive;
} else {
item.classCombination = this.classCombinationInactive;
}
return item;
});
});
}
@track navItems = [
{
label: 'Home',
id: 'home',
classCombination:
'navItem slds-context-bar__item slds-shrink-none slds-is-active'
},
{
label: 'Log Viewer',
id: 'logViewer',
classCombination: 'navItem slds-context-bar__item slds-shrink-none'
}
];
handleNavigationItemClick(event) {
event.preventDefault();
// console.log(event.currentTarget.dataset.navitem);
const selectedNav = event.currentTarget.dataset.navitem;
// for (let i = 0; i < this.navItems.length; i++) {
// if (i === parseInt(selectedIdx, 10)) {
// const payload = {
// activeApp: this.navItems[i].label
// };
// publish('appChannel', payload);
// this.navItems[i].classCombination = this.classCombinationActive;
// } else {
// this.navItems[i].classCombination =
// this.classCombinationInactive;
// }
// }
this.navItems.map((item) => {
if (item.id === selectedNav) {
item.classCombination = this.classCombinationActive;
const payload = {
activeApp: item.label
};
publish('appChannel', payload);
} else {
item.classCombination = this.classCombinationInactive;
}
return item;
});
// console.log(JSON.stringify(this.navItems));
}
}