diff --git a/src/providers/UserDataProvider.js b/src/providers/UserDataProvider.js index 1d22808..a18f19b 100644 --- a/src/providers/UserDataProvider.js +++ b/src/providers/UserDataProvider.js @@ -3,7 +3,7 @@ import { useDataFromRef } from "react-native-minuit/src/hooks"; import useMinuit from "react-native-minuit/src/hooks/useMinuit"; import { createContext, useContext, useGlobal } from "reactn"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { checkIfEmailIsValid } from "../actions/signupActions"; import firebase, { arrayRemove, @@ -48,6 +48,9 @@ export default ({ children }) => { refreshArray: [currentUID], }); + const userPlaybacks = Array.isArray(userProjects) + ? userProjects.filter((project) => project.playbackUrl) + : []; // Subscribe to user's liked projects const { data: userLikedProjects = [] } = useDataFromRef({ ref: currentUID @@ -95,7 +98,7 @@ export default ({ children }) => { followedBy: arrayUnion(currentUID), lastFollowersUpdateAt: new Date(), }, - { merge: true }, + { merge: true } ); setTooltip({ type: "success", text: "Abonnement mis à jour" }); } @@ -113,7 +116,7 @@ export default ({ children }) => { followedBy: arrayRemove(currentUID), lastFollowersUpdateAt: new Date(), }, - { merge: true }, + { merge: true } ); setTooltip({ type: "success", @@ -242,6 +245,7 @@ export default ({ children }) => { currentUID, currentUserData: currentUserDoc, userProjects, + userPlaybacks, userLikedProjects, userPlaylists, followingCount: userFollowing?.length || 0, diff --git a/src/screens/Profile/Profile.js b/src/screens/Profile/Profile.js index ffcf619..c826374 100644 --- a/src/screens/Profile/Profile.js +++ b/src/screens/Profile/Profile.js @@ -29,7 +29,8 @@ import MusicCard from "../Library/components/MusicCard"; const Profile = () => { const [selected, setSelected] = useState("Chansons"); - const { userProjects, followingCount, currentUserData } = useUser(); + const { userProjects, userPlaybacks, followingCount, currentUserData } = + useUser(); const [, setTooltip] = useGlobal("_tooltip"); const [menuTop, setMenuTop] = useState(0); const [showMenu, setShowMenu] = useState(false); @@ -176,9 +177,71 @@ const Profile = () => { ))} {selected === "Playbacks" && ( - - - + + {Array.isArray(userPlaybacks) && userPlaybacks.length > 0 ? ( + item.id} + renderItem={({ item }) => ( + + navigate(Routes.MusicDetails, { projectId: item.id }) + } + onPressMore={(posTop) => { + setSelectedProjectId(item.id); + setMenuTop(posTop); + setShowMenu((prev) => !prev || posTop !== menuTop); + }} + /> + )} + /> + ) : ( + + )} + setShowMenu(false)} + inPlaylist={false} + projectId={selectedProjectId} + extraItems={[ + { + label: "Supprimer", + onPress: () => + SheetManager.show("Delete", { + payload: { + title: "Supprimer le projet", + message: + "Cette action supprimera définitivement ce projet.", + onConfirm: async () => { + try { + if (!selectedProjectId) return; + await projectsRef.doc(selectedProjectId).delete(); + setTooltip({ + type: "success", + text: "Projet supprimé", + }); + } catch (e) { + setTooltip({ + type: "error", + text: e?.message || "Suppression impossible", + }); + } + }, + }, + }), + }, + ]} + /> + )} {selected === "Chansons" && (