fix: playbacks && profile picture

This commit is contained in:
2025-11-03 10:06:32 +01:00
parent ab5aa1fd1a
commit 3d37bdba97
2 changed files with 61 additions and 4 deletions
@@ -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 MoreMenu from "../../../components/MoreMenu";
import ProfilePicture from "../../../components/ProfilePicture";
@@ -44,6 +44,56 @@ const SearchResultsList = ({
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 didNavigate = navigateToMusicDetails({
projectId: project?.id,
@@ -109,7 +159,7 @@ const SearchResultsList = ({
key={project.id}
title={project?.title || "Sans titre"}
subtitle={project?.userName}
imageUri={project?.coverUrl || null}
imageUri={resolveCoverUri(project)}
projectId={project?.id}
likedBy={project?.likedBy || []}
onPress={() => handleMusicPress(project)}
@@ -153,7 +203,9 @@ const SearchResultsList = ({
key={project.id}
title={project?.title || "Sans titre"}
subtitle={project?.userName}
imageUri={project?.coverUrl || null}
imageUri={resolveCoverUri(project, {
preferThumbnail: true,
})}
projectId={project?.id}
likedBy={project?.likedBy || []}
onPress={() => handlePlaybackPress(project)}
+6 -1
View File
@@ -321,7 +321,12 @@ const Profile = () => {
});
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 (
<Page