display playbacks
This commit is contained in:
@@ -3,7 +3,7 @@ import { useDataFromRef } from "react-native-minuit/src/hooks";
|
|||||||
import useMinuit from "react-native-minuit/src/hooks/useMinuit";
|
import useMinuit from "react-native-minuit/src/hooks/useMinuit";
|
||||||
import { createContext, useContext, useGlobal } from "reactn";
|
import { createContext, useContext, useGlobal } from "reactn";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { checkIfEmailIsValid } from "../actions/signupActions";
|
import { checkIfEmailIsValid } from "../actions/signupActions";
|
||||||
import firebase, {
|
import firebase, {
|
||||||
arrayRemove,
|
arrayRemove,
|
||||||
@@ -48,6 +48,9 @@ export default ({ children }) => {
|
|||||||
refreshArray: [currentUID],
|
refreshArray: [currentUID],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const userPlaybacks = Array.isArray(userProjects)
|
||||||
|
? userProjects.filter((project) => project.playbackUrl)
|
||||||
|
: [];
|
||||||
// Subscribe to user's liked projects
|
// Subscribe to user's liked projects
|
||||||
const { data: userLikedProjects = [] } = useDataFromRef({
|
const { data: userLikedProjects = [] } = useDataFromRef({
|
||||||
ref: currentUID
|
ref: currentUID
|
||||||
@@ -95,7 +98,7 @@ export default ({ children }) => {
|
|||||||
followedBy: arrayUnion(currentUID),
|
followedBy: arrayUnion(currentUID),
|
||||||
lastFollowersUpdateAt: new Date(),
|
lastFollowersUpdateAt: new Date(),
|
||||||
},
|
},
|
||||||
{ merge: true },
|
{ merge: true }
|
||||||
);
|
);
|
||||||
setTooltip({ type: "success", text: "Abonnement mis à jour" });
|
setTooltip({ type: "success", text: "Abonnement mis à jour" });
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,7 @@ export default ({ children }) => {
|
|||||||
followedBy: arrayRemove(currentUID),
|
followedBy: arrayRemove(currentUID),
|
||||||
lastFollowersUpdateAt: new Date(),
|
lastFollowersUpdateAt: new Date(),
|
||||||
},
|
},
|
||||||
{ merge: true },
|
{ merge: true }
|
||||||
);
|
);
|
||||||
setTooltip({
|
setTooltip({
|
||||||
type: "success",
|
type: "success",
|
||||||
@@ -242,6 +245,7 @@ export default ({ children }) => {
|
|||||||
currentUID,
|
currentUID,
|
||||||
currentUserData: currentUserDoc,
|
currentUserData: currentUserDoc,
|
||||||
userProjects,
|
userProjects,
|
||||||
|
userPlaybacks,
|
||||||
userLikedProjects,
|
userLikedProjects,
|
||||||
userPlaylists,
|
userPlaylists,
|
||||||
followingCount: userFollowing?.length || 0,
|
followingCount: userFollowing?.length || 0,
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ import MusicCard from "../Library/components/MusicCard";
|
|||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
const [selected, setSelected] = useState("Chansons");
|
const [selected, setSelected] = useState("Chansons");
|
||||||
const { userProjects, followingCount, currentUserData } = useUser();
|
const { userProjects, userPlaybacks, followingCount, currentUserData } =
|
||||||
|
useUser();
|
||||||
const [, setTooltip] = useGlobal("_tooltip");
|
const [, setTooltip] = useGlobal("_tooltip");
|
||||||
const [menuTop, setMenuTop] = useState(0);
|
const [menuTop, setMenuTop] = useState(0);
|
||||||
const [showMenu, setShowMenu] = useState(false);
|
const [showMenu, setShowMenu] = useState(false);
|
||||||
@@ -176,9 +177,71 @@ const Profile = () => {
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
{selected === "Playbacks" && (
|
{selected === "Playbacks" && (
|
||||||
<View style={{ flex: 1 }}>
|
<ScrollView style={{ flex: 1 }}>
|
||||||
<EmptyText text={"Aucun playback pour le moment"} />
|
{Array.isArray(userPlaybacks) && userPlaybacks.length > 0 ? (
|
||||||
</View>
|
<FlatList
|
||||||
|
data={userPlaybacks}
|
||||||
|
contentContainerStyle={{
|
||||||
|
gap: 10,
|
||||||
|
}}
|
||||||
|
keyExtractor={(item) => item.id}
|
||||||
|
renderItem={({ item }) => (
|
||||||
|
<MusicCard
|
||||||
|
title={item?.title || "Sans titre"}
|
||||||
|
subtitle={currentUserData?.userName || "MusicLand"}
|
||||||
|
imageUri={item?.coverUrl || null}
|
||||||
|
projectId={item?.id}
|
||||||
|
likedBy={item?.likedBy || []}
|
||||||
|
onPress={() =>
|
||||||
|
navigate(Routes.MusicDetails, { projectId: item.id })
|
||||||
|
}
|
||||||
|
onPressMore={(posTop) => {
|
||||||
|
setSelectedProjectId(item.id);
|
||||||
|
setMenuTop(posTop);
|
||||||
|
setShowMenu((prev) => !prev || posTop !== menuTop);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<EmptyText text={"Aucune chanson pour le moment"} />
|
||||||
|
)}
|
||||||
|
<MoreMenu
|
||||||
|
visible={showMenu}
|
||||||
|
top={menuTop}
|
||||||
|
onClose={() => 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</ScrollView>
|
||||||
)}
|
)}
|
||||||
{selected === "Chansons" && (
|
{selected === "Chansons" && (
|
||||||
<ScrollView style={{ flex: 1 }}>
|
<ScrollView style={{ flex: 1 }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user