Skip to content

Commit

Permalink
[people-picker] adding repeat instead of map, also caching images
Browse files Browse the repository at this point in the history
  • Loading branch information
vogtn committed Aug 23, 2019
1 parent c99e5fd commit 844a4a7
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/components/mgt-people-picker/mgt-people-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { LitElement, html, customElement, property } from 'lit-element';
import { repeat } from 'lit-html/directives/repeat';
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';

import { Providers } from '../../Providers';
Expand Down Expand Up @@ -214,12 +215,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
});
}

for (let person of people) {
// set image to @ to flag the mgt-person component to
// query the image from the graph
person.image = '@';
}

this.people = this.filterPeople(people);
this.isLoading = false;
}
Expand Down Expand Up @@ -356,7 +351,21 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {

private renderPeopleList() {
let people: any = this.people;

if (people) {
for (let person of people) {
//discover if localstorage has image for person already
if (person.image !== '@' && person.image !== undefined && person.image !== null) {
window.localStorage.setItem(person.id, person.image);

This comment has been minimized.

Copy link
@nmetulev

nmetulev Aug 27, 2019

Contributor

I feel like this should be done on the mgt-person side and not just in the people-picker, thoughts?

}
if (person.image === undefined) {
person.image = window.localStorage.getItem(person.id);
} else {
// set image to @ to flag the mgt-person component to
// query the image from the graph
person.image = '@';
}
}
if (people.length == 0 && this._userInput.length > 0 && this.isLoading == false) {
return html`
<ul class="people-list">
Expand All @@ -377,9 +386,11 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
}

private renderPersons(people: Array<any>) {
return people.slice(0, this.showMax).map(
person =>
html`
return html`
${repeat(
people,
person => person.id,
person => html`
<li
class="${person.isSelected == 'fill' ? 'people-person-list-fill' : 'people-person-list'}"
@click="${(event: any) => this.addPerson(person, event)}"
Expand All @@ -391,7 +402,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
</div>
</li>
`
);
)}
`;
}

render() {
Expand Down

0 comments on commit 844a4a7

Please sign in to comment.