Skip to content

Commit eaa53b7

Browse files
committed
update sound library UI & some RTL fixes
1 parent ea4bad3 commit eaa53b7

File tree

8 files changed

+652
-19
lines changed

8 files changed

+652
-19
lines changed

src/components/library-item/library-item.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
background: $ui-primary;
2727
}
2828

29+
.library-item-sound {
30+
width: 200px;
31+
max-width: 200px;
32+
flex-basis: 200px;
33+
height: 100px;
34+
padding: 0.25rem;
35+
padding-bottom: 0;
36+
}
37+
2938
.library-item-extension {
3039
align-self: stretch;
3140
}
@@ -228,9 +237,20 @@
228237
left: 0;
229238
top: 0;
230239
width: 100%;
240+
}
241+
242+
.library-item-waveform {
243+
position: absolute;
244+
left: 0;
245+
width: calc(100% - 3rem);
246+
height: 3rem;
231247
max-width: 100%;
232248
max-height: 100%;
233249
}
250+
[dir="rtl"] .library-item-waveform {
251+
left: initial;
252+
right: 0;
253+
}
234254

235255
.library-item-inset-image {
236256
width: 2.5rem;
@@ -250,6 +270,29 @@
250270
white-space: pre-wrap;
251271
min-width: 0;
252272
}
273+
.library-item-sound-name {
274+
text-align: left;
275+
width: 100%;
276+
margin-bottom: 0;
277+
}
278+
.library-item-sound-type {
279+
text-align: left;
280+
width: 100%;
281+
margin-top: 0;
282+
opacity: 0.65;
283+
}
284+
285+
[dir="rtl"] .library-item-sound-name,
286+
[dir="rtl"] .library-item-sound-type {
287+
text-align: right;
288+
}
289+
290+
.library-item-sound-info-container {
291+
width: 100%;
292+
position: relative;
293+
display: flex;
294+
flex-direction: column;
295+
}
253296

254297
.featured-item {
255298
flex-basis: 300px;

src/components/library-item/library-item.jsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const getURLOrigin = (url) => {
2525
}
2626
return urlObj.origin;
2727
};
28+
const getMSFormatted = (ms) => {
29+
return (ms / 1000).toFixed(2);
30+
};
2831

2932
/* eslint-disable react/prefer-stateless-function */
3033
class LibraryItemComponent extends React.PureComponent {
@@ -308,7 +311,8 @@ class LibraryItemComponent extends React.PureComponent {
308311
<Box
309312
className={classNames(
310313
styles.libraryItem, {
311-
[styles.hidden]: this.props.hidden
314+
[styles.hidden]: this.props.hidden,
315+
[styles.libraryItemSound]: this.props.styleForSound,
312316
}
313317
)}
314318
role="button"
@@ -328,24 +332,44 @@ class LibraryItemComponent extends React.PureComponent {
328332
onMouseLeave={this.props.showPlayButton ? this.props.onMouseLeave : null}
329333
>
330334
<img
331-
className={styles.libraryItemImage}
335+
className={classNames(
336+
styles.libraryItemImage, {
337+
[styles.libraryItemWaveform]: this.props.styleForSound
338+
}
339+
)}
332340
loading="lazy"
333341
src={this.props.iconURL}
334342
draggable={false}
335343
/>
336344
{this.props.overlayURL && (
337345
<img
338-
className={styles.libraryItemImageOverlay}
346+
className={classNames(
347+
styles.libraryItemImage, styles.libraryItemImageOverlay, {
348+
[styles.libraryItemWaveform]: this.props.styleForSound
349+
}
350+
)}
339351
loading="lazy"
340352
src={this.props.overlayURL}
341353
draggable={false}
342354
/>
343355
)}
344356
</Box>
345357
</Box>
346-
<span className={styles.libraryItemName}>{this.props.name}</span>
358+
{this.props.styleForSound ? (
359+
<div className={styles.libraryItemSoundInfoContainer}>
360+
<span className={classNames(styles.libraryItemName, styles.libraryItemSoundName)}>{this.props.name}</span>
361+
<span className={classNames(styles.libraryItemName, styles.libraryItemSoundType)}>
362+
{this.props.soundType}, {getMSFormatted(this.props.soundLength)}
363+
</span>
364+
</div>
365+
) : (
366+
<span className={styles.libraryItemName}>{this.props.name}</span>
367+
)}
347368
{this.props.showPlayButton ? (
348369
<PlayButton
370+
className={classNames({
371+
[styles.libraryItemSoundPlayButton]: this.props.styleForSound
372+
})}
349373
isPlaying={this.props.isPlaying}
350374
onPlay={this.props.onPlay}
351375
onStop={this.props.onStop}
@@ -377,6 +401,9 @@ LibraryItemComponent.propTypes = {
377401
iconURL: PropTypes.string,
378402
overlayURL: PropTypes.string,
379403
insetIconURL: PropTypes.string,
404+
styleForSound: PropTypes.bool,
405+
soundType: PropTypes.string,
406+
soundLength: PropTypes.number,
380407
customInsetColor: PropTypes.string,
381408
internetConnectionRequired: PropTypes.bool,
382409
isPlaying: PropTypes.bool,

src/components/library/library.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,34 @@
2626
display: flex;
2727
flex-direction: row;
2828
align-items: center;
29+
margin-left: 6px;
2930
}
30-
.libraryItemCount {
31+
.library-item-count {
3132
opacity: 0.5;
3233
margin-block: 0;
3334
margin-left: 4px;
3435
}
3536
[theme="dark"] .library-header {
3637
color: white;
3738
}
39+
[dir="rtl"] .library-header {
40+
margin-left: initial;
41+
margin-right: 6px;
42+
}
43+
[dir="rtl"] .library-item-count {
44+
margin-left: initial;
45+
margin-right: 4px;
46+
}
47+
48+
.library-tag-count {
49+
margin-right: 2.5%;
50+
text-align: right;
51+
}
52+
[dir="rtl"] .library-tag-count {
53+
margin-right: initial;
54+
margin-left: 2.5%;
55+
text-align: left;
56+
}
3857

3958
.library-scroll-grid {
4059
width: calc(100% - 346px);

src/components/library/library.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ class LibraryComponent extends React.Component {
312312
*/}
313313
{this.props.header ? (
314314
<h1
315-
style={{ marginLeft: "6px" }}
316315
className={classNames(
317316
styles.libraryHeader,
318317
styles.whiteTextInDarkMode
@@ -415,7 +414,7 @@ class LibraryComponent extends React.Component {
415414
{...tagProps}
416415
/>
417416
</div>
418-
<div style={{ width: "7.5%", marginRight: "2.5%", textAlign: "right" }}>
417+
<div className={styles.libraryTagCount}>
419418
{this.state.loaded &&
420419
(
421420
this.state.data.filter(dataItem => (arrayIncludesItemsFrom(
@@ -457,6 +456,9 @@ class LibraryComponent extends React.Component {
457456
icons={dataItem.costumes}
458457
id={index}
459458
_id={dataItem._id}
459+
styleForSound={this.props.actor === "SoundLibrary"}
460+
soundType={dataItem.soundType}
461+
soundLength={dataItem.soundLength}
460462
incompatibleWithScratch={dataItem.incompatibleWithScratch}
461463
insetIconURL={dataItem.insetIconURL}
462464
internetConnectionRequired={dataItem.internetConnectionRequired}

src/components/tag-checkbox/tag-button.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
.checkbox:hover {
4848
border: 2px solid $motion-primary;
4949
}
50+
[dir="rtl"] .checkbox {
51+
margin-right: initial;
52+
margin-left: 4px;
53+
}
5054

5155
.checkbox:checked {
5256
border: 2px solid $motion-primary;

src/containers/library-item.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ class LibraryItem extends React.PureComponent {
192192
hidden={this.props.hidden}
193193
iconURL={iconURL}
194194
overlayURL={this.props.overlayURL}
195+
styleForSound={this.props.styleForSound}
196+
soundType={this.props.soundType}
197+
soundLength={this.props.soundLength}
195198
icons={this.props.icons}
196199
id={this.props.id}
197200
_id={this.props._id}
@@ -244,6 +247,9 @@ LibraryItem.propTypes = {
244247
iconMd5: PropTypes.string,
245248
iconRawURL: PropTypes.string,
246249
overlayURL: PropTypes.string,
250+
styleForSound: PropTypes.bool,
251+
soundType: PropTypes.string,
252+
soundLength: PropTypes.number,
247253
icons: PropTypes.arrayOf(
248254
PropTypes.shape({
249255
baseLayerMD5: PropTypes.string, // 2.0 library format, TODO GH-5084

src/containers/sound-library.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import AudioEngine from 'scratch-audio';
77

88
import LibraryComponent from '../components/library/library.jsx';
99

10-
import soundIcon from '../components/library-item/lib-icon--sound.svg';
11-
import soundIconRtl from '../components/library-item/lib-icon--sound-rtl.svg';
12-
import loopIcon from '../components/library-item/lib-icon--loop.svg';
13-
import loopIconRtl from '../components/library-item/lib-icon--loop-rtl.svg';
14-
import themeIcon from '../components/library-item/lib-icon--theme.svg';
15-
import themeIconRtl from '../components/library-item/lib-icon--theme-rtl.svg';
10+
// import soundIcon from '../components/library-item/lib-icon--sound.svg';
11+
// import soundIconRtl from '../components/library-item/lib-icon--sound-rtl.svg';
12+
// import loopIcon from '../components/library-item/lib-icon--loop.svg';
13+
// import loopIconRtl from '../components/library-item/lib-icon--loop-rtl.svg';
14+
// import themeIcon from '../components/library-item/lib-icon--theme.svg';
15+
// import themeIconRtl from '../components/library-item/lib-icon--theme-rtl.svg';
1616

1717
import {getSoundLibrary} from '../lib/libraries/tw-async-libraries';
18+
import soundLengths from '../lib/libraries/sounds-lengths.json';
1819
import soundTags from '../lib/libraries/sound-tags';
1920

2021
import {connect} from 'react-redux';
@@ -33,11 +34,11 @@ const PM_LIBRARY_API = "https://library.penguinmod.com/";
3334
const getSoundLibraryThumbnailData = (soundLibraryContent, isRtl) => soundLibraryContent
3435
.sort((a, b) => a.name.localeCompare(b.name))
3536
.map(sound => {
36-
const icons = {
37-
sound: isRtl ? soundIconRtl : soundIcon,
38-
loop: isRtl ? loopIconRtl : loopIcon,
39-
theme: isRtl ? themeIconRtl : themeIcon,
40-
};
37+
// const icons = {
38+
// sound: isRtl ? soundIconRtl : soundIcon,
39+
// loop: isRtl ? loopIconRtl : loopIcon,
40+
// theme: isRtl ? themeIconRtl : themeIcon,
41+
// };
4142
const isLoop = sound.tags ? sound.tags.includes('loops') : false;
4243
const isTheme = sound.tags ? sound.tags.includes('themes') : false;
4344

@@ -51,7 +52,10 @@ const getSoundLibraryThumbnailData = (soundLibraryContent, isRtl) => soundLibrar
5152
rawURL: sound.fromPenguinModLibrary ?
5253
`${PM_LIBRARY_API}files/sound_previews/${sound.libraryFilePage.replace(/\//g, "_").replace(".mp3", ".png")}` :
5354
`${PM_LIBRARY_API}files/scratch_sound_previews/${assetId}.png`,
54-
overlayURL: isTheme ? icons.theme : (isLoop ? icons.loop : icons.sound),
55+
soundLength: sound.fromPenguinModLibrary ?
56+
soundLengths.penguinmod[sound.libraryFilePage] :
57+
soundLengths.scratch[assetId],
58+
soundType: isTheme ? "Theme" : (isLoop ? "Loop" : "Sound"),
5559
...otherData
5660
};
5761
});
@@ -260,6 +264,7 @@ class SoundLibrary extends React.PureComponent {
260264
showPlayButton
261265
data={this.state.data}
262266
id="soundLibrary"
267+
actor="SoundLibrary"
263268
header={"Sounds"}
264269
setStopHandler={this.setStopHandler}
265270
tags={soundTags}

0 commit comments

Comments
 (0)