Skip to content

Commit

Permalink
fix: artist page link sending to artist page
Browse files Browse the repository at this point in the history
Fixes #797.
  • Loading branch information
asartalo committed Aug 27, 2024
1 parent 911f722 commit 3dab939
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
36 changes: 23 additions & 13 deletions client/src/components/Artist/ArtistTrackGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { css } from "@emotion/css";
import React from "react";
import ClickToPlay from "../common/ClickToPlay";
import { Link } from "react-router-dom";
import { Link, matchPath } from "react-router-dom";
import { bp } from "../../constants";
import { getArtistUrl, getReleaseUrl } from "utils/artist";
import { getArtistUrl, getReleasesUrl, getReleaseUrl } from "utils/artist";
import styled from "@emotion/styled";
import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -50,18 +50,20 @@ export const TrackGroupInfo = styled.div`
a {
text-decoration: none;
}
a:first-of-type {
a:hover {
text-decoration: underline;
}
.track-group-name {
font-weight: normal;
margin-bottom: 0.2rem;
}
a:last-of-type {
.track-group-artist {
font-size: var(--mi-font-size-xsmall);
color: var(--mi-light-foreground-color);
}
a:hover {
text-decoration: underline;
}
`;

const ArtistTrackGroup: React.FC<{
Expand Down Expand Up @@ -98,16 +100,13 @@ const ArtistTrackGroup: React.FC<{
color: var(--mi-light-foreground-color);
font-style: italic;
`
+ " track-group-name"
}
>
{trackGroup.title.length ? trackGroup.title : t("untitled")}
</Link>
)}
{trackGroup.artist && (
<Link to={getArtistUrl(trackGroup.artist)}>
{trackGroup.artist?.name}
</Link>
)}
{<ArtistName artist={trackGroup.artist} />}
</TrackGroupInfo>
<div
className={css`
Expand All @@ -133,4 +132,15 @@ const ArtistTrackGroup: React.FC<{
);
};

const ArtistName: React.FC<{ artist: TrackGroup['artist'] }> = ({ artist }) => {
if (!artist) { return null; }

const artistUrl = getReleasesUrl(artist);
return (
!!matchPath({ path: artistUrl }, window.location.pathname)
? <span className="track-group-artist">{artist.name}</span>
: <Link className="track-group-artist" to={artistUrl}>{artist.name}</Link>
)
}

export default ArtistTrackGroup;
4 changes: 4 additions & 0 deletions client/src/utils/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const getArtistUrl = (artist: { urlSlug?: string; id?: number }) => {
return `/${getArtistUrlReference(artist)}`;
};

export const getReleasesUrl = (artist: { urlSlug?: string; id?: number }) => {
return `${getArtistUrl(artist)}/releases`;
}

export const getArtistManageUrl = (artistId: number) => {
return `/manage/artists/${artistId}`;
};
Expand Down

0 comments on commit 3dab939

Please sign in to comment.