Skip to content

Commit

Permalink
Sorting info tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonym-tsk committed Jan 4, 2024
1 parent d660a6a commit bb756cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 13 additions & 5 deletions dist/starline-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions src/ts/StarlineCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,20 @@ export class StarlineCard extends HTMLElement {
this.$toast.textContent = 'Нажмите дважды для выполнения';
}

this._setDarkMode();
this._setHasTitle();
this._setControls();
this._setInfo();
this._initHandlers();
setTimeout(() => {
this.$wrapper!.style.opacity = '1';
}, 10);
}

_update() {
this._setDarkMode();
this._setHasTitle();
this._setAlarmState();
this._setCarState();
this._setInfo();
this._setInfoState();
}

_getState(entity_id: ConfigEntity): StateValue | null {
Expand Down Expand Up @@ -263,7 +264,7 @@ export class StarlineCard extends HTMLElement {
}
}

_setInfo() {
_setInfoState() {
for (const [key, data] of Object.entries(this._info) as [ConfigInfo, UIElement][]) {
let visible = false;

Expand Down Expand Up @@ -296,6 +297,16 @@ export class StarlineCard extends HTMLElement {
this.$controlRight!.classList.add(`control-icon-${this._config.controls[2]}`);
}

_setInfo() {
// Сортируем info
// TODO: Переделать, чтобы в _setInfoState не нужно было проверять видимость (а лучше вообще лишние элементы удалить)
const $cnt = this._info.balance.element!.parentNode!;
for (const name of this._config.info) {
const $item = $cnt.querySelector(`info-${name}`)!;
$cnt.appendChild($item);
}
}

_initHandlers() {
for (const [key, data] of Object.entries(this._info) as [ConfigInfo, UIElement][]) {
data.element!.addEventListener('click', () => this._moreInfo(key));
Expand Down

0 comments on commit bb756cd

Please sign in to comment.