Skip to content

Commit

Permalink
fix: catalog return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Pashkagreen committed Jan 23, 2024
1 parent 69d669e commit eea96af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/modules/music-kit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NativeModules } from 'react-native';
import type { CatalogSearchType } from '../types/catalog-search-type';
import type { CatalogSearchType, ICatalogSearch } from '../types/catalog-search';
import type { MusicItem } from '../types/music-item';
import type { ISong } from '../types/song';
import type { ITracksFromLibrary } from '../types/tracks-from-library';

const { MusicModule } = NativeModules;
Expand All @@ -23,14 +22,17 @@ class MusicKit {
search: string,
types: CatalogSearchType[],
options?: IEndlessListOptions,
): Promise<ISong[]> {
const response: { results: ISong[] } = await MusicModule.catalogSearch(search, types, options);
): Promise<ICatalogSearch | undefined> {
try {
return (await MusicModule.catalogSearch(search, types, options)) as ICatalogSearch;
} catch (error) {
console.error('Apple Music Kit: Catalog Search failed.', error);

if (response.results) {
return response.results;
return {
songs: [],
albums: [],
};
}

return [];
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/types/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface IAlbum {
id: string;
title: string;
artistName: string;
artworkUrl: string;
trackCount: number;
}
4 changes: 0 additions & 4 deletions src/types/catalog-search-type.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/types/catalog-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { IAlbum } from './album';
import type { ISong } from './song';

export enum CatalogSearchType {
SONGS = 'songs',
ALBUMS = 'albums',
}

export interface ICatalogSearch {
songs: ISong[];
albums: IAlbum[];
}

0 comments on commit eea96af

Please sign in to comment.