fix: improper handling of undefined api leading to crashes

This commit is contained in:
Prayag Prajapati committed 2024-11-25 00:11:53 +05:30
1 parent c6b5d6a4a2
commit 81695a583d
9 files changed
+73 -67

No files matched your search

+3 -5
View File
@@ -8,13 +8,11 @@ import React from "react";
const PlayNextButton = () => {
const api = useApiInContext((s) => s.api);
if (!api) {
console.error("Unable to display play next button, api is not available");
return null;
}
const user = useQuery({
queryKey: ["user"],
queryFn: async () => {
if (!api) return;
const result = await getUserApi(api).getCurrentUser();
return result.data;
},
@@ -22,7 +20,7 @@ const PlayNextButton = () => {
const handlePlayNext = useMutation({
mutationKey: ["playNextButton"],
mutationFn: () => playItemFromQueue("next", user.data?.Id, api),
onError: (error) => [console.error(error)],
onError: (error) => console.error(error),
});
const [queueItems, currentItemIndex] = useQueue((state) => [
state.tracks,