-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs-user-mixin.html
62 lines (54 loc) · 1.45 KB
/
fs-user-mixin.html
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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../fs-api-aware/fs-api-aware.html">
<link rel="import" href="../fs-request/fs-request.html">
<script>
/**
* `fs-user-mixin`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
const FsUserMixin = Polymer.dedupingMixin((superClass) => class extends FSApiAwareMixin(superClass) {
static get properties() {
return {
userId: {
type: String,
notify: true
},
user: {
type: Object,
notify: true
},
/** Whether the API request is loading */
loading: {
type: Boolean,
value: false
}
};
}
ready() {
super.ready();
if(!this.user) {
this._loadUser();
}
}
_loadUser() {
const request = document.createElement('fs-request');
request.url = `/platform/users/current`;
request.requireAuthentication = true;
request.clientName = this.clientName;
request.addEventListener('response', this._handleUserResponse.bind(this));
request.delegateEvents(this);
request.generateRequest();
}
_handleUserResponse(e) {
const response = e.detail.response;
if(response.data && Array.isArray(response.data.users)) {
this.user = response.data.users[0];
this.userId = this.user.id;
}
}
});
</script>