fix: playbacks && profile picture
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useState } from "react";
|
import React, { useCallback, useMemo, useState } from "react";
|
||||||
import { Pressable, ScrollView, Text, View } from "react-native";
|
import { Pressable, ScrollView, Text, View } from "react-native";
|
||||||
import MoreMenu from "../../../components/MoreMenu";
|
import MoreMenu from "../../../components/MoreMenu";
|
||||||
import ProfilePicture from "../../../components/ProfilePicture";
|
import ProfilePicture from "../../../components/ProfilePicture";
|
||||||
@@ -44,6 +44,56 @@ const SearchResultsList = ({
|
|||||||
|
|
||||||
const navigateToMusicDetails = useNavigateToMusicDetails();
|
const navigateToMusicDetails = useNavigateToMusicDetails();
|
||||||
|
|
||||||
|
const resolveCoverUri = useCallback(
|
||||||
|
(project, { preferThumbnail = false } = {}) => {
|
||||||
|
const isValid = (value) =>
|
||||||
|
typeof value === "string" && value.trim().length > 0;
|
||||||
|
if (!project) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cover = project?.cover || {};
|
||||||
|
const thumbnailCandidates = [
|
||||||
|
project?.thumbnailUrl,
|
||||||
|
project?.songThumbnailUrl,
|
||||||
|
].filter(isValid);
|
||||||
|
|
||||||
|
if (preferThumbnail) {
|
||||||
|
const preferredThumbnail = thumbnailCandidates.find(isValid);
|
||||||
|
if (preferredThumbnail) {
|
||||||
|
return preferredThumbnail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValid(project?.coverUrl)) {
|
||||||
|
return project.coverUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const coverCandidates = [
|
||||||
|
cover?.result,
|
||||||
|
cover?.finalUrl,
|
||||||
|
cover?.generatedBackground,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (Array.isArray(cover?.options)) {
|
||||||
|
coverCandidates.push(
|
||||||
|
...cover.options.flatMap((option) => [
|
||||||
|
option?.finalUrl,
|
||||||
|
option?.generatedUrl,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackThumbnail = thumbnailCandidates.find(isValid);
|
||||||
|
if (fallbackThumbnail) {
|
||||||
|
coverCandidates.push(fallbackThumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return coverCandidates.find(isValid) || null;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const handleMusicPress = (project) => {
|
const handleMusicPress = (project) => {
|
||||||
const didNavigate = navigateToMusicDetails({
|
const didNavigate = navigateToMusicDetails({
|
||||||
projectId: project?.id,
|
projectId: project?.id,
|
||||||
@@ -109,7 +159,7 @@ const SearchResultsList = ({
|
|||||||
key={project.id}
|
key={project.id}
|
||||||
title={project?.title || "Sans titre"}
|
title={project?.title || "Sans titre"}
|
||||||
subtitle={project?.userName}
|
subtitle={project?.userName}
|
||||||
imageUri={project?.coverUrl || null}
|
imageUri={resolveCoverUri(project)}
|
||||||
projectId={project?.id}
|
projectId={project?.id}
|
||||||
likedBy={project?.likedBy || []}
|
likedBy={project?.likedBy || []}
|
||||||
onPress={() => handleMusicPress(project)}
|
onPress={() => handleMusicPress(project)}
|
||||||
@@ -153,7 +203,9 @@ const SearchResultsList = ({
|
|||||||
key={project.id}
|
key={project.id}
|
||||||
title={project?.title || "Sans titre"}
|
title={project?.title || "Sans titre"}
|
||||||
subtitle={project?.userName}
|
subtitle={project?.userName}
|
||||||
imageUri={project?.coverUrl || null}
|
imageUri={resolveCoverUri(project, {
|
||||||
|
preferThumbnail: true,
|
||||||
|
})}
|
||||||
projectId={project?.id}
|
projectId={project?.id}
|
||||||
likedBy={project?.likedBy || []}
|
likedBy={project?.likedBy || []}
|
||||||
onPress={() => handlePlaybackPress(project)}
|
onPress={() => handlePlaybackPress(project)}
|
||||||
|
|||||||
@@ -321,7 +321,12 @@ const Profile = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const displayedProjects = isSelf ? selfProjects : otherUserProjects;
|
const displayedProjects = isSelf ? selfProjects : otherUserProjects;
|
||||||
const displayedPlaybacks = isSelf ? selfPlaybacks : [];
|
const displayedPlaybacksSource = isSelf
|
||||||
|
? selfPlaybacks
|
||||||
|
: otherUserProjects;
|
||||||
|
const displayedPlaybacks = Array.isArray(displayedPlaybacksSource)
|
||||||
|
? displayedPlaybacksSource.filter((project) => project?.playbackUrl)
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page
|
<Page
|
||||||
|
|||||||
Reference in New Issue
Block a user