Skip to content

Commit

Permalink
Add option to show track numbers in lists
Browse files Browse the repository at this point in the history
Requested in #222
  • Loading branch information
elamperti committed Nov 1, 2023
1 parent cc9e523 commit 97f034c
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 183 deletions.
5 changes: 5 additions & 0 deletions assets/db/migrations/0003_showTrackNumbers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;
INSERT INTO migrations (revision) VALUES (3);
ALTER TABLE settings
ADD showTrackNumbers BOOLEAN DEFAULT 0;
COMMIT;
1 change: 1 addition & 0 deletions cypress/fixtures/api/v2/user/authenticated.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"username": "cypress",
"catchPaste": 1,
"use12Hours": 0,
"showTrackNumbers": 0,
"lang": "auto",
"isDonor": 0,
"keepOriginalTimestamp": 1,
Expand Down
1 change: 1 addition & 0 deletions cypress/fixtures/api/v2/user/donor.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"username": "cypress",
"catchPaste": 1,
"use12Hours": 0,
"showTrackNumbers": 0,
"lang": "auto",
"isDonor": 1,
"keepOriginalTimestamp": 1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openscrobbler",
"version": "2.7.12",
"version": "2.7.13",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.2.1",
Expand Down
9 changes: 7 additions & 2 deletions src/components/ScrobbleItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class ScrobbleItem extends Component {
// COMPACT view
songInfo = (
<Label className="d-flex align-items-center mb-0" htmlFor={scrobbleItemInputId}>
{!!this.props.settings.showTrackNumber && scrobble.trackNumber && (
<span className="me-1">{scrobble.trackNumber}.</span>
)}
<span className="song flex-grow-1 pe-2 truncate">{songFullTitle}</span>
{timeOrDuration}
</Label>
Expand Down Expand Up @@ -292,8 +295,9 @@ class ScrobbleItem extends Component {
);
}

const scrobbleItemClasses =
`scrobbled-item status-${scrobble.status} ${(this.props.compact ? 'compact' : 'card mb-2')}`;
const scrobbleItemClasses = `scrobbled-item status-${scrobble.status} ${
this.props.compact ? 'compact' : 'card mb-2'
}`;

// ToDo: evaluate using flex-nowrap instead of flex-wrap
return (
Expand Down Expand Up @@ -348,6 +352,7 @@ ScrobbleItem.propTypes = {
selected: PropTypes.bool,
settings: PropTypes.shape({
use12Hours: PropTypes.bool,
showTrackNumber: PropTypes.bool,
}),
t: PropTypes.func,
uuid: PropTypes.string,
Expand Down
9 changes: 9 additions & 0 deletions src/components/SettingsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class SettingsModal extends React.Component {

render() {
const t = this.props.t;
// ToDo: refactor this component ffs
// const trackNumbersEnabled = useFeatureIsOn('show-track-numbers');
const trackNumbersEnabled = false;

return (
<Modal
Expand Down Expand Up @@ -123,6 +126,12 @@ class SettingsModal extends React.Component {
<Input type="checkbox" {...this.createPropsForCheckbox('catchPaste')} />
{t('splitPastedText')}
</Label>
{trackNumbersEnabled && (
<Label className="d-block" check>
<Input type="checkbox" {...this.createPropsForCheckbox('showTrackNumbers')} />
{t('showTrackNumbers')}
</Label>
)}
</FormGroup>
</Form>
</ModalBody>
Expand Down
2 changes: 2 additions & 0 deletions src/store/reducers/settingsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const initialState = {
lang: 'auto',
use12Hours: false,
catchPaste: true,
showTrackNumbers: false,
isDonor: false,
keepOriginalTimestamp: true,
modalIsOpen: false,
Expand All @@ -27,6 +28,7 @@ const settingsReducer = (state = initialState, action) => {
...action.payload,
use12Hours: !!action.payload.use12Hours,
catchPaste: !!action.payload.catchPaste,
showTrackNumbers: !!action.payload.showTrackNumbers,
isDonor: !!action.payload.isDonor,
settingsLoaded: true,
};
Expand Down
118 changes: 0 additions & 118 deletions src/store/transformers/albumTransformer.js

This file was deleted.

62 changes: 0 additions & 62 deletions src/store/transformers/trackTransformer.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('Discogs transformer: tracks response', () => {
duration: 259,
uuid: 'fakeShortId',
cover: null,
trackNumber: null,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function tracksTransformer(
duration: track.duration && _HMSStrToSeconds(track.duration),
uuid: shortid.generate(),
cover: null,
trackNumber: track.position || null,
};

if (hasIn(options, 'cover')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe('the `tracksTransformer` function', () => {
},
name: 'track',
duration: '123',
'@attr': {
rank: '2',
},
},
],
},
Expand All @@ -28,6 +31,7 @@ describe('the `tracksTransformer` function', () => {
duration: 123,
uuid: expect.anything(),
cover: undefined,
trackNumber: 2,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function tracksTransformer(response: any, options?: { album?: string; cov
duration: track.duration ? parseInt(track.duration) : 0,
uuid: shortid.generate(),
cover: undefined,
trackNumber: track['@attr'] ? parseInt(track['@attr'].rank) : null,
};

if (hasIn(options, 'cover')) {
Expand Down

0 comments on commit 97f034c

Please sign in to comment.