Skip to content

Commit b0d85ff

Browse files
committed
Misc TrackList improvements
- simpler CSS, splitted by component - larger spacing for the artist view - fixed dash displayed when no genres
1 parent 63d50a4 commit b0d85ff

7 files changed

Lines changed: 79 additions & 66 deletions

File tree

src/components/TrackList.module.css

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,3 @@
66
height: 100%;
77
user-select: none;
88
}
9-
10-
.trackListScroller {
11-
overflow-y: scroll;
12-
flex: 1 1 auto;
13-
position: relative;
14-
}
15-
16-
.trackListRows {
17-
width: 100%;
18-
position: relative;
19-
}
20-
21-
.tracksGroup {
22-
display: flex;
23-
gap: 16px;
24-
padding: 16px 16px;
25-
align-items: flex-start;
26-
position: relative;
27-
}
28-
29-
.tracksGroupLabel {
30-
font-size: 1.4rem;
31-
font-weight: bold;
32-
margin: 0;
33-
}
34-
35-
.tracksGroupMetadata {
36-
color: var(--text-muted);
37-
display: flex;
38-
flex-direction: column;
39-
gap: 4px;
40-
}
41-
42-
.tracksGroupSide {
43-
width: 160px;
44-
position: sticky;
45-
top: 16px;
46-
display: flex;
47-
flex-direction: column;
48-
gap: 8px;
49-
50-
@media (min-width: 1024px) {
51-
width: 240px;
52-
}
53-
}
54-
55-
.tracksGroupContent {
56-
flex-grow: 1;
57-
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.rows {
2+
width: 100%;
3+
position: relative;
4+
}

src/components/TrackListDefault.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { useVirtualizer } from '@tanstack/react-virtual';
88
import type React from 'react';
99
import { useCallback, useId, useImperativeHandle, useRef } from 'react';
1010

11+
import Scrollable from '../elements/Scrollable';
1112
import type { Track } from '../generated/typings';
1213
import useDndSensors from '../hooks/useDnDSensors';
1314
import usePlayingTrackID from '../hooks/usePlayingTrackID';
1415
import type { TrackListVirtualizer } from '../types/museeks';
15-
import styles from './TrackList.module.css';
16+
import styles from './TrackListDefault.module.css';
1617
import TrackListHeader from './TrackListHeader';
1718
import TrackRow, { type TrackRowEvents } from './TrackRow';
1819

@@ -111,16 +112,14 @@ export default function TrackListDefault(props: Props) {
111112
modifiers={DND_MODIFIERS}
112113
sensors={sensors}
113114
>
114-
<div ref={innerScrollableRef} className={styles.trackListScroller}>
115+
<Scrollable ref={innerScrollableRef}>
115116
<TrackListHeader enableSort={isSortEnabled} />
116117

117118
{/* The large inner element to hold all of the items */}
118119
<div
119-
className={styles.trackListRows}
120+
className={styles.rows}
120121
style={{
121122
height: `${virtualizer.getTotalSize()}px`,
122-
width: '100%',
123-
position: 'relative',
124123
}}
125124
>
126125
<SortableContext
@@ -158,7 +157,7 @@ export default function TrackListDefault(props: Props) {
158157
})}
159158
</SortableContext>
160159
</div>
161-
</div>
160+
</Scrollable>
162161
</DndContext>
163162
);
164163
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
:root {
2+
--spacing: 24px;
3+
}
4+
5+
.group {
6+
display: flex;
7+
gap: var(--spacing);
8+
padding: var(--spacing);
9+
align-items: flex-start;
10+
position: relative;
11+
}
12+
13+
.aside {
14+
width: 160px;
15+
position: sticky;
16+
top: var(--spacing);
17+
display: flex;
18+
flex-direction: column;
19+
gap: 8px;
20+
21+
@media (min-width: 1024px) {
22+
width: 240px;
23+
}
24+
}
25+
26+
.label {
27+
font-size: 1.4rem;
28+
font-weight: bold;
29+
margin: 0;
30+
}
31+
32+
.metadata {
33+
color: var(--text-muted);
34+
display: flex;
35+
flex-direction: column;
36+
gap: 4px;
37+
}
38+
39+
.rows {
40+
flex-grow: 1;
41+
}

src/components/TrackListGrouped.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Plural } from '@lingui/react/macro';
22
import { useImperativeHandle, useRef } from 'react';
33

4+
import Scrollable from '../elements/Scrollable';
45
import type { TrackGroup } from '../generated/typings';
56
import useAllTracks from '../hooks/useAllTracks';
67
import { parseDuration } from '../hooks/useFormattedDuration';
78
import usePlayingTrackID from '../hooks/usePlayingTrackID';
89
import type { TrackListVirtualizer } from '../types/museeks';
910
import Cover from './Cover';
10-
import styles from './TrackList.module.css';
11+
import styles from './TrackListGrouped.module.css';
1112
import TrackRow, { type TrackRowEvents } from './TrackRow';
1213

1314
/** ----------------------------------------------------------------------------
@@ -48,7 +49,7 @@ export default function TrackListGroupedLayout(props: Props) {
4849
}, [tracks]);
4950

5051
return (
51-
<div ref={innerScrollableRef} className={styles.trackListScroller}>
52+
<Scrollable ref={innerScrollableRef}>
5253
{trackGroups.map((tracksGroup) => {
5354
return (
5455
<TrackListGroup
@@ -60,7 +61,7 @@ export default function TrackListGroupedLayout(props: Props) {
6061
/>
6162
);
6263
})}
63-
</div>
64+
</Scrollable>
6465
);
6566
}
6667

@@ -87,23 +88,23 @@ function TrackListGroup(props: TrackListGroupProps) {
8788
}
8889

8990
return (
90-
<div className={styles.tracksGroup}>
91-
<div className={styles.tracksGroupSide}>
91+
<div className={styles.group}>
92+
<aside className={styles.aside}>
9293
{/** Instead of the first one, maybe get the first track within the album to hold a cover? */}
9394
<Cover track={tracks[0]} iconSize={36} noBorder />
94-
<h3 className={styles.tracksGroupLabel}>{label}</h3>
95-
<div className={styles.tracksGroupMetadata}>
95+
<h3 className={styles.label}>{label}</h3>
96+
<div className={styles.metadata}>
9697
<div>
97-
{year ? <span>{year} - </span> : null}
98-
{genres.join(', ')}
98+
{year}
99+
{genres.length > 0 && <span> - {genres.join(', ')}</span>}
99100
</div>
100101
<div>
101102
<Plural value={tracks.length} one="# track" other="# tracks" />,{' '}
102103
{parseDuration(duration)}
103104
</div>
104105
</div>
105-
</div>
106-
<div className={styles.tracksGroupContent}>
106+
</aside>
107+
<div className={styles.rows}>
107108
{tracks.map((track, index) => {
108109
return (
109110
<TrackRow

src/elements/Scrollable.module.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scrollable {
2+
overflow-y: auto;
3+
}

src/elements/Scrollable.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import styles from './Scrollable.module.css';
2+
3+
type Props = {
4+
children: React.ReactNode;
5+
ref: React.Ref<HTMLDivElement>;
6+
};
7+
8+
export default function Scrollable(props: Props) {
9+
return (
10+
<div className={styles.scrollable} ref={props.ref}>
11+
{props.children}
12+
</div>
13+
);
14+
}

0 commit comments

Comments
 (0)