diff --git a/public/locales/en.json b/public/locales/en.json index 26f7bd1..30e88e5 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -20,7 +20,7 @@ "customTimestamp": "Custom timestamp", "albumTimestampLogicDescription": "Scrobbling tracks \"now\" will scrobble the last track at the current time, backdating the previous ones accordingly (as if you had just finished listening). The \"custom timestamp\" will define the timestamp of the first track and add time to the following tracks from there (i.e. you specify the time you started listening to this album).", "albumArtist": "Album artist", - "albumCleanupPattern": "Removable text pattern from every track name", + "filter": "Filter", "albumCleanupPatternDescription": "Some albums tracks are displayed with some repeated text (i.e. Demo, Live, Remastered, ...). These are patterns that could be considered annoying to scrobble, for some users. Set the full pattern (including paranthesis, dashes, ...) that you would like to be removed, from the track names.", "history": "History", "yourProfile": "Your profile", diff --git a/public/locales/it.json b/public/locales/it.json index 98077ab..33f62df 100644 --- a/public/locales/it.json +++ b/public/locales/it.json @@ -20,7 +20,6 @@ "customTimestamp": "Timestamp personalizzato", "albumTimestampLogicDescription": "Scrobblando le canzoni \"adesso\" scrobblerà l'ultima canzone in questo momento, anticipando relativamente le precedenti (come se avessi appena finito di ascoltarle). Il \"timestamp personalizzato\" definirà il timestamp di ascolto della prima traccia ed agginguerà il relativo tempo alle canzoni successive (come se avessi iniziato ad ascoltare l'album nel timestamp selezionato)", "albumArtist": "Artista di un Album", - "albumCleanupPattern": "Pattern removibile da ogni nome di canzone", "albumCleanupPatternDescription": "Alcune canzoni di album sono visualizzate con un certo testo ripetuto (ad esempio Demo, Live, Remastered, ...). Questi sono pattern che potrebbero risultare fastidiosi da scrobblare, per alcuni utenti. Imposta il pattern completo (incluse parentesi, trattini, ...) che desideri venga rimosso dai nomi delle canzoni.", "history": "Storico", "yourProfile": "Tuo profilo", diff --git a/src/components/ScrobbleItem.css b/src/components/ScrobbleItem.css index 0dec2c1..3ece4ee 100644 --- a/src/components/ScrobbleItem.css +++ b/src/components/ScrobbleItem.css @@ -98,7 +98,7 @@ padding-right: 1.15rem; } -.scrobbled-item-cleanup { +.scrobbled-item del { color: var(--bs-secondary-color) !important; - text-decoration: line-through; + background-color: rgba(255, 32, 0, 0.2); } diff --git a/src/components/ScrobbleItem.tsx b/src/components/ScrobbleItem.tsx index a35aa6b..06d52ac 100644 --- a/src/components/ScrobbleItem.tsx +++ b/src/components/ScrobbleItem.tsx @@ -10,8 +10,7 @@ import isToday from 'date-fns/isToday'; import getYear from 'date-fns/getYear'; import { Button, Input, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, FormGroup, Label } from 'reactstrap'; -import { useState } from 'react'; -import { renderToStaticMarkup } from 'react-dom/server'; +import { Fragment, useState } from 'react'; import { LazyLoadImage } from 'react-lazy-load-image-component'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { @@ -27,16 +26,16 @@ import { } from '@fortawesome/free-solid-svg-icons'; import { faClock, faCopy } from '@fortawesome/free-regular-svg-icons'; import { getAmznLink } from 'Constants'; +import { breakStringUsingPattern, cleanTitleWithPattern } from 'domains/scrobbleAlbum/CleanupContext'; import type { Scrobble } from 'utils/types/scrobble'; -import { replaceLastOccurrence } from 'utils/common'; import './ScrobbleItem.css'; import { useSettings } from 'hooks/useSettings'; interface ScrobbleItemProps { scrobble: Scrobble; - cleanupPattern?: string; + cleanupPattern?: RegExp; compact?: boolean; hideArtist?: boolean; muteArtist?: boolean; @@ -51,7 +50,7 @@ interface ScrobbleItemProps { export default function ScrobbleItem({ scrobble, - cleanupPattern = '', + cleanupPattern, compact = false, hideArtist = false, muteArtist = false, @@ -90,8 +89,9 @@ export default function ScrobbleItem({ enqueueScrobble(dispatch)([ { ...scrobble, - title: cleanupPattern ? scrobble.title.replaceAll(cleanupPattern, '').trim() : scrobble.title, + title: cleanTitleWithPattern(scrobble.title, cleanupPattern), timestamp: useOriginalTimestamp ? scrobble.timestamp : new Date(), + cleanupPattern: cleanupPattern || undefined, }, ]); setHasScrobbledAgain(true); @@ -109,20 +109,10 @@ export default function ScrobbleItem({ }); }; - const getCompleteItem = (item: string, highlight?: string) => { - const parsedItem = item; - - if (!highlight || !item.endsWith(highlight)) { - return parsedItem; - } - - const parsedComplete = highlight; - - const textComplete = renderToStaticMarkup({parsedComplete}); - - const itemComplete = replaceLastOccurrence(parsedItem, parsedComplete, textComplete); - - return itemComplete; + const strikethroughMatch = (text: string, pattern?: RegExp) => { + return breakStringUsingPattern(text, pattern).map(({ value, isMatch }, index) => ( + {!isMatch ? value : {value}} + )); }; let albumArt; @@ -220,18 +210,23 @@ export default function ScrobbleItem({ ); + const formattedTitle = strikethroughMatch(properCase(scrobble.title, true), cleanupPattern); if (!hideArtist) { if (muteArtist) { songFullTitle = ( <> - {properCase(scrobble.title, true)} {properCase(scrobble.artist)} + {formattedTitle} {properCase(scrobble.artist)} ); } else { - songFullTitle = `${properCase(scrobble.artist)} - ${properCase(scrobble.title, true)}`; + songFullTitle = ( + <> + {properCase(scrobble.artist)} - {formattedTitle} + + ); } } else { - songFullTitle = properCase(scrobble.title, true); + songFullTitle = formattedTitle; } const scrobbleItemInputId = `ScrobbleItem-checkbox-${scrobble.uuid}`; @@ -241,10 +236,7 @@ export default function ScrobbleItem({ songInfo = ( ); @@ -252,10 +244,7 @@ export default function ScrobbleItem({ // FULL view songInfo = ( <> - + {songFullTitle}