Skip to content

Commit

Permalink
chore(www): upgrade server-list to Lit
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Feb 21, 2024
1 parent 6356371 commit 385ae8f
Showing 1 changed file with 38 additions and 49 deletions.
87 changes: 38 additions & 49 deletions src/www/views/servers_view/server_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,53 @@
limitations under the License.
*/

import {computed, customElement, property} from '@polymer/decorators';
import {html, PolymerElement} from '@polymer/polymer';
import {css, html, LitElement} from 'lit';
import {customElement, property} from 'lit/decorators.js';

import '../server_list_item/server_card';
import {ServerListItem} from '../server_list_item';
import {Localizer} from 'src/infrastructure/i18n';

@customElement('server-list')
export class ServerList extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
margin: 0 auto;
width: 100%;
height: 100%;
padding: 8px;
box-sizing: border-box;
}
server-row-card {
margin: 0 auto 8px auto;
height: 130px;
}
server-hero-card {
height: 400px;
}
</style>
<!-- TODO(daniellacosse): use slots instead after we move this to lit -->
<template is="dom-repeat" items="[[servers]]">
<template is="dom-if" if="[[hasSingleServer]]">
<server-hero-card localize="[[localize]]" server="[[item]]"></server-hero-card>
</template>
<template is="dom-if" if="[[!hasSingleServer]]">
<server-row-card localize="[[localize]]" server="[[item]]"></server-row-card>
</template>
</template>
`;
}

// Need to declare localize function passed in from parent, or else
// localize() calls within the template won't be updated.

// @polymer/decorators doesn't support Function constructors...
@property({type: Object}) localize: Localizer;
export class ServerList extends LitElement {
static styles = [
css`
:host {
box-sizing: border-box;
display: block;
height: 100%;
margin: 0 auto;

Check warning on line 29 in src/www/views/servers_view/server_list/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list/index.ts#L26-L29

Added lines #L26 - L29 were not covered by tests
padding: 8px;
width: 100%;
}

Check warning on line 33 in src/www/views/servers_view/server_list/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list/index.ts#L31-L33

Added lines #L31 - L33 were not covered by tests
server-row-card {
margin: 0 auto 8px auto;
height: 130px;
}

Check warning on line 37 in src/www/views/servers_view/server_list/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list/index.ts#L36-L37

Added lines #L36 - L37 were not covered by tests
server-hero-card {
height: 400px;
}
`,

Check warning on line 42 in src/www/views/servers_view/server_list/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list/index.ts#L41-L42

Added lines #L41 - L42 were not covered by tests
];

@property({type: Function}) localize: Localizer = msg => msg;
@property({type: Array}) servers: ServerListItem[] = [];

@computed('servers')
get hasSingleServer() {
return this.servers.length === 1;
render() {
if (this.hasSingleServer) {
return html` <server-hero-card .localize=${this.localize} .server="${this.servers[0]}"></server-hero-card> `;
} else {
return html`
${this.servers.map(
server => html`<server-row-card .localize=${this.localize} .server="${server}"></server-row-card>`
)}
`;
}
}

getErrorMessage(errorMessageId: string) {
if (typeof errorMessageId === 'string') {
return this.localize(errorMessageId);
}
private get hasSingleServer() {
return this.servers.length === 1;
}
}

0 comments on commit 385ae8f

Please sign in to comment.