forked from trailheadapps/easy-spaces-lwc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreservationList.js
69 lines (62 loc) · 2.12 KB
/
reservationList.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
import { LightningElement, track, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getOpenReservations from '@salesforce/apex/reservationManagerController.getOpenReservations';
import { CurrentPageReference } from 'lightning/navigation';
import { registerListener, unregisterAllListeners, fireEvent } from 'c/pubsub';
export default class ReservationList extends LightningElement {
wiredResult;
reservationSelected = false;
selectedRecId;
_records = [];
@track reservations;
@track errorMsg;
@track msgForUser;
@track showDetails;
@track noRecords = false;
@wire(CurrentPageReference) pageRef;
connectedCallback() {
registerListener('flowexit', this.handleFlowExit, this);
}
disconnectedCallback() {
unregisterAllListeners(this);
}
@wire(getOpenReservations)
wiredReservations(value) {
this.wiredResult = value;
if (value.error) {
this.errorMsg = value.error;
this.msgForUser = 'There was an issue loading reservations.';
this.showDetails = false;
} else if (value.data) {
if (value.data.length) {
this._records = [...value.data];
this.handleMute();
if (this.noRecords) this.noRecords = false;
} else {
this.noRecords = true;
}
}
}
handleFlowExit() {
return refreshApex(this.wiredResult);
}
handleMute() {
if (!this.reservationSelected) {
let muted = '';
this.reservations = this._records.map(record => {
if (this.selectedRecId) {
this.reservationSelected = true;
muted = record.Id === this.selectedRecId ? false : true;
} else {
muted = false;
}
return { record, muted };
});
}
}
handleSelectEvent(event) {
this.selectedRecId = event.detail.reservationId;
fireEvent(this.pageRef, 'selectreservation', { detail: event.detail });
this.handleMute();
}
}