From 17518dbe7f545100770a892d03d1f8508adc3650 Mon Sep 17 00:00:00 2001 From: sct Date: Thu, 24 Dec 2020 10:33:54 +0900 Subject: [PATCH] fix(frontend): sort person detail credits by tmdb votes --- src/components/PersonDetails/index.tsx | 203 ++++++++++++------------- 1 file changed, 95 insertions(+), 108 deletions(-) diff --git a/src/components/PersonDetails/index.tsx b/src/components/PersonDetails/index.tsx index 7eb32fa0b..e0a44d4f5 100644 --- a/src/components/PersonDetails/index.tsx +++ b/src/components/PersonDetails/index.tsx @@ -44,30 +44,18 @@ const PersonDetails: React.FC = () => { } const sortedCast = combinedCredits?.cast.sort((a, b) => { - const aDate = - a.mediaType === 'movie' - ? a.releaseDate?.slice(0, 4) ?? 0 - : a.firstAirDate?.slice(0, 4) ?? 0; - const bDate = - b.mediaType === 'movie' - ? b.releaseDate?.slice(0, 4) ?? 0 - : b.firstAirDate?.slice(0, 4) ?? 0; - if (aDate > bDate) { + const aVotes = a.voteCount ?? 0; + const bVotes = b.voteCount ?? 0; + if (aVotes > bVotes) { return -1; } return 1; }); const sortedCrew = combinedCredits?.crew.sort((a, b) => { - const aDate = - a.mediaType === 'movie' - ? a.releaseDate?.slice(0, 4) ?? 0 - : a.firstAirDate?.slice(0, 4) ?? 0; - const bDate = - b.mediaType === 'movie' - ? b.releaseDate?.slice(0, 4) ?? 0 - : b.firstAirDate?.slice(0, 4) ?? 0; - if (aDate > bDate) { + const aVotes = a.voteCount ?? 0; + const bVotes = b.voteCount ?? 0; + if (aVotes > bVotes) { return -1; } return 1; @@ -75,6 +63,94 @@ const PersonDetails: React.FC = () => { const isLoading = !combinedCredits && !errorCombinedCredits; + const cast = (sortedCast ?? []).length > 0 && ( + <> +
+
+
+ {intl.formatMessage(messages.appearsin)} +
+
+
+ + + ); + + const crew = (sortedCrew ?? []).length > 0 && ( + <> +
+
+
+ {intl.formatMessage(messages.crewmember)} +
+
+
+ + + ); + return ( <> {(sortedCrew || sortedCast) && ( @@ -126,96 +202,7 @@ const PersonDetails: React.FC = () => { - {(sortedCast ?? []).length > 0 && ( - <> -
-
-
- {intl.formatMessage(messages.appearsin)} -
-
-
- - - )} - {(sortedCrew ?? []).length > 0 && ( - <> -
-
-
- {intl.formatMessage(messages.crewmember)} -
-
-
- - - )} + {data.knownForDepartment === 'Acting' ? [cast, crew] : [crew, cast]} {isLoading && } );