Skip to content

Commit 615e3d6

Browse files
committed
feat: add playing bars to playing queue item
1 parent 49ddb6a commit 615e3d6

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

src/components/group.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { css, html, LitElement, nothing } from 'lit';
22
import { property } from 'lit/decorators.js';
3-
import { when } from 'lit/directives/when.js';
43
import Store from '../model/store';
54
import { dispatchActivePlayerId, getSpeakerList } from '../utils/utils';
65
import { SESSION_STORAGE_PLAYER_ID } from '../constants';
76
import { MediaPlayer } from '../model/media-player';
7+
import './playing-bars';
88

99
class Group extends LitElement {
1010
@property({ attribute: false }) store!: Store;
@@ -41,16 +41,7 @@ class Group extends LitElement {
4141
</div>
4242
</div>
4343
44-
${when(
45-
this.player.isPlaying(),
46-
() => html`
47-
<div class="bars" slot="meta">
48-
<div></div>
49-
<div></div>
50-
<div></div>
51-
</div>
52-
`,
53-
)}
44+
<sonos-playing-bars slot="meta" .show=${this.player.isPlaying()}></sonos-playing-bars>
5445
</mwc-list-item>
5546
`;
5647
}
@@ -91,17 +82,6 @@ class Group extends LitElement {
9182

9283
static get styles() {
9384
return css`
94-
@keyframes sound {
95-
0% {
96-
opacity: 0.35;
97-
height: 0.15rem;
98-
}
99-
100% {
100-
opacity: 1;
101-
height: 1rem;
102-
}
103-
}
104-
10585
mwc-list-item {
10686
height: fit-content;
10787
margin: 1rem;
@@ -166,37 +146,6 @@ class Group extends LitElement {
166146
.compact div {
167147
margin: 0.1rem;
168148
}
169-
170-
.bars {
171-
width: 0.55rem;
172-
position: relative;
173-
margin-left: 1rem;
174-
}
175-
176-
.bars > div {
177-
background: var(--secondary-text-color);
178-
bottom: 0.05rem;
179-
height: 0.15rem;
180-
position: absolute;
181-
width: 0.15rem;
182-
animation: sound 0ms -800ms linear infinite alternate;
183-
display: block;
184-
}
185-
186-
.bars > div:first-child {
187-
left: 0.05rem;
188-
animation-duration: 474ms;
189-
}
190-
191-
.bars > div:nth-child(2) {
192-
left: 0.25rem;
193-
animation-duration: 433ms;
194-
}
195-
196-
.bars > div:last-child {
197-
left: 0.45rem;
198-
animation-duration: 407ms;
199-
}
200149
`;
201150
}
202151
}

src/components/media-row.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import Store from '../model/store';
44
import { MediaPlayerItem } from '../types';
55
import { mediaItemTitleStyle } from '../constants';
66
import { renderFavoritesItem } from '../utils/favorites-utils';
7+
import './playing-bars';
78

89
class MediaRow extends LitElement {
910
@property({ attribute: false }) store!: Store;
1011
@property({ attribute: false }) item!: MediaPlayerItem;
1112
@property({ type: Boolean }) selected = false;
13+
@property({ type: Boolean }) playing = false;
1214

1315
render() {
1416
const { itemBackgroundColor, itemTextColor, selectedItemBackgroundColor, selectedItemTextColor } =
@@ -21,7 +23,10 @@ class MediaRow extends LitElement {
2123
return html`
2224
<mwc-list-item hasMeta ?selected=${this.selected} ?activated=${this.selected} class="button" style="${cssVars}">
2325
<div class="row">${renderFavoritesItem(this.item)}</div>
24-
<slot slot="meta"></slot>
26+
<div class="meta-content" slot="meta">
27+
<sonos-playing-bars .show=${this.playing}></sonos-playing-bars>
28+
<slot></slot>
29+
</div>
2530
</mwc-list-item>
2631
`;
2732
}
@@ -74,6 +79,12 @@ class MediaRow extends LitElement {
7479
align-self: center;
7580
flex: 1;
7681
}
82+
83+
.meta-content {
84+
display: flex;
85+
align-items: center;
86+
gap: 0.5rem;
87+
}
7788
`,
7889
mediaItemTitleStyle,
7990
];

src/components/playing-bars.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { css, html, LitElement, nothing } from 'lit';
2+
import { property } from 'lit/decorators.js';
3+
4+
class PlayingBars extends LitElement {
5+
@property({ type: Boolean }) show = false;
6+
7+
render() {
8+
if (!this.show) {
9+
return nothing;
10+
}
11+
return html`
12+
<div class="bars">
13+
<div></div>
14+
<div></div>
15+
<div></div>
16+
</div>
17+
`;
18+
}
19+
20+
static get styles() {
21+
return css`
22+
@keyframes sound {
23+
0% {
24+
opacity: 0.35;
25+
height: 0.15rem;
26+
}
27+
100% {
28+
opacity: 1;
29+
height: 1rem;
30+
}
31+
}
32+
33+
:host {
34+
display: flex;
35+
align-items: center;
36+
}
37+
38+
.bars {
39+
width: 0.55rem;
40+
height: 1rem;
41+
position: relative;
42+
margin-left: 1rem;
43+
}
44+
45+
.bars > div {
46+
background: var(--secondary-text-color);
47+
bottom: 0;
48+
height: 0.15rem;
49+
position: absolute;
50+
width: 0.15rem;
51+
animation: sound 0ms -800ms linear infinite alternate;
52+
display: block;
53+
}
54+
55+
.bars > div:first-child {
56+
left: 0.05rem;
57+
animation-duration: 474ms;
58+
}
59+
60+
.bars > div:nth-child(2) {
61+
left: 0.25rem;
62+
animation-duration: 433ms;
63+
}
64+
65+
.bars > div:last-child {
66+
left: 0.45rem;
67+
animation-duration: 407ms;
68+
}
69+
`;
70+
}
71+
}
72+
73+
customElements.define('sonos-playing-bars', PlayingBars);

src/sections/queue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ export class Queue extends LitElement {
4545
${until(
4646
this.store.hassService.getQueue(this.store.activePlayer).then((queue) =>
4747
queue.map((item, index) => {
48+
const isSelected = selected !== undefined && selected === index;
49+
const isPlaying = isSelected && this.activePlayer.isPlaying();
4850
return html`
4951
<sonos-media-row
5052
@click=${() => this.onMediaItemSelected(index)}
5153
.item=${item}
52-
.selected=${selected !== undefined && selected === index}
54+
.selected=${isSelected}
55+
.playing=${isPlaying}
5356
.store=${this.store}
5457
><ha-icon-button
5558
hide=${this.editMode && nothing}

0 commit comments

Comments
 (0)