music options
This commit is contained in:
@@ -12,6 +12,7 @@ import { SheetManager } from "react-native-actions-sheet";
|
||||
import SwiperFlatList from "react-native-swiper-flatlist";
|
||||
import { icons } from "../../assets";
|
||||
import { arrayUnion, playlistsRef } from "../../config/firebase";
|
||||
import useMinuit from "react-native-minuit/src/hooks/useMinuit";
|
||||
import { useUserData } from "../../providers/UserDataProvider";
|
||||
import { createPlaylist } from "../../screens/Library/Playlists/playlist";
|
||||
import { Palette } from "../../styles";
|
||||
@@ -30,6 +31,7 @@ const PlaylistModal = (props) => {
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const { currentUID, userPlaylists = [] } = useUserData();
|
||||
const startAtCreate = props?.payload?.startAtCreate || false;
|
||||
const { setTooltip } = useMinuit();
|
||||
|
||||
return (
|
||||
<AppActionSheet id="Playlist">
|
||||
@@ -104,9 +106,19 @@ const PlaylistModal = (props) => {
|
||||
musics: arrayUnion(projectId),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
const addedPlaylist = (Array.isArray(userPlaylists)
|
||||
? userPlaylists
|
||||
: []
|
||||
).find((p) => p?.id === selectedId);
|
||||
const name = addedPlaylist?.name || "la playlist";
|
||||
setTooltip({
|
||||
type: "success",
|
||||
text: `Ajouté à “${name}”`,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Add to playlist error", e?.message);
|
||||
setTooltip({ type: "error", text: e?.message || "Ajout impossible" });
|
||||
} finally {
|
||||
SheetManager.hide("Playlist");
|
||||
}
|
||||
@@ -175,20 +187,28 @@ const PlaylistModal = (props) => {
|
||||
if (!playlist?.trim()?.length || !currentUID) return;
|
||||
try {
|
||||
setIsCreating(true);
|
||||
const name = playlist.trim();
|
||||
await createPlaylist({
|
||||
createdBy: currentUID,
|
||||
name: playlist.trim(),
|
||||
name,
|
||||
musics: props?.payload?.projectId
|
||||
? [props.payload.projectId]
|
||||
: [],
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
setTooltip({
|
||||
type: "success",
|
||||
text: props?.payload?.projectId
|
||||
? `Playlist “${name}” créée et musique ajoutée`
|
||||
: `Playlist “${name}” créée`,
|
||||
});
|
||||
setPlaylist("");
|
||||
SheetManager.hide("Playlist");
|
||||
scrollRef.current.scrollToIndex({ index: 0, animated: true });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
setTooltip({ type: "error", text: e?.message || "Création impossible" });
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user