All files / Rindu/utils getTopTracksCards.ts

20% Statements 2/10
0% Branches 0/3
0% Functions 0/2
20% Lines 2/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                44x               2x                                                                                                
import { ITranslations } from "types/translations";
import {
  DEFAULT_SONG_IMAGE_URL,
  GeneratedImageAPI,
  getGeneratedImageUrl,
  TOP_TRACKS_LONG_TERM_COLOR,
  TOP_TRACKS_MEDIUM_TERM_COLOR,
  TOP_TRACKS_SHORT_TERM_COLOR,
} from "utils";
 
export interface TopTracksCard {
  name: string;
  images: { url: string }[];
  url: string;
}
 
export async function getTopTracksCards(
  user: SpotifyApi.UserObjectPrivate | null | undefined,
  translations: ITranslations
): Promise<TopTracksCard[]> {
  Iif (!user) {
    return [];
  }
 
  const CARDS: { name: string; color: string; url: string }[] = [
    {
      name: translations.pages.dashboard.topTracksPlaylistLongTermTitle,
      color: TOP_TRACKS_LONG_TERM_COLOR,
      url: "/top/tracks-long-term",
    },
    {
      name: translations.pages.dashboard.topTracksPlaylistMediumTermTitle,
      color: TOP_TRACKS_MEDIUM_TERM_COLOR,
      url: "/top/tracks-medium-term",
    },
    {
      name: translations.pages.dashboard.topTracksPlaylistShortTermTitle,
      color: TOP_TRACKS_SHORT_TERM_COLOR,
      url: "/top/tracks-short-term",
    },
  ];
 
  const topTracksCards = await Promise.all(
    CARDS.map(async (card) => {
      const params = {
        title: card.name,
        color: card.color,
        imageUrl: user?.images?.[0]?.url ?? DEFAULT_SONG_IMAGE_URL,
      };
      const generatedImageUrl = await getGeneratedImageUrl(
        GeneratedImageAPI.TopTracksCover,
        params
      );
 
      return {
        name: card.name,
        images: [{ url: generatedImageUrl }],
        url: card.url,
      };
    })
  );
 
  return topTracksCards;
}