Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: artist page link sending to artist page #825

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} />}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have Prettier enabled for this project? This should automatically turn this into:

Suggested change
{<ArtistName artist={trackGroup.artist} />}
<ArtistName artist={trackGroup.artist} />

decluttering it a little bit. It's an outstanding project to add it to the repo by detault

</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