mirror of
https://github.com/ershisan99/podcaster.git
synced 2025-12-18 05:09:30 +00:00
chore: refactor podcast dto to hold different image sizes
This commit is contained in:
@@ -32,7 +32,7 @@ export function Home() {
|
|||||||
key={podcast.id}
|
key={podcast.id}
|
||||||
title={podcast.title}
|
title={podcast.title}
|
||||||
author={podcast.author}
|
author={podcast.author}
|
||||||
imageUrl={podcast.imageUrl}
|
imageUrl={podcast.images.large}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
import { Entry } from "./podcasts.types";
|
import { Entry, ImImage } from "./podcasts.types";
|
||||||
|
|
||||||
export class PodcastDTO {
|
export class PodcastDTO {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
author: string;
|
author: string;
|
||||||
imageUrl: string;
|
images: { small: string; medium: string; large: string };
|
||||||
|
description: string;
|
||||||
|
|
||||||
constructor(podcast: Entry) {
|
constructor(podcast: Entry) {
|
||||||
this.id = podcast.id.attributes["im:id"];
|
this.id = podcast.id.attributes["im:id"];
|
||||||
this.title = podcast["im:name"].label;
|
this.title = podcast["im:name"].label;
|
||||||
this.author = podcast["im:artist"].label;
|
this.author = podcast["im:artist"].label;
|
||||||
this.imageUrl = podcast["im:image"][0].label;
|
this.description = podcast["summary"].label;
|
||||||
|
this.images = this.convertImages(podcast["im:image"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private convertImages(images: ImImage[]) {
|
||||||
|
const sortedImages = [...images].sort((a, b) => {
|
||||||
|
return parseInt(a.attributes.height) - parseInt(b.attributes.height);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
small: sortedImages[0].label,
|
||||||
|
medium: sortedImages[1].label,
|
||||||
|
large: sortedImages[2].label,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user