start adding payment
This commit is contained in:
@@ -9,7 +9,7 @@ import React, {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Platform } from "react-native";
|
||||
import { AppState, Platform } from "react-native";
|
||||
import { useGlobal } from "reactn";
|
||||
import firebase, {
|
||||
arrayUnion,
|
||||
@@ -66,6 +66,18 @@ export default function NotificationProvider({ children }) {
|
||||
}
|
||||
}, [notifications]);
|
||||
|
||||
const clearBadgeCount = useCallback(async () => {
|
||||
if (Platform.OS === "web") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await Notifications.setBadgeCountAsync(0);
|
||||
} catch (error) {
|
||||
console.log("clearBadgeCount error:", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const markNotificationAsRead = useCallback(async (notificationId) => {
|
||||
try {
|
||||
if (!notificationId) return;
|
||||
@@ -117,6 +129,33 @@ export default function NotificationProvider({ children }) {
|
||||
registerForPushNotificationsAsync();
|
||||
}, [user, uid, notifInit]);
|
||||
|
||||
useEffect(() => {
|
||||
if (Platform.OS === "web") {
|
||||
return;
|
||||
}
|
||||
|
||||
clearBadgeCount();
|
||||
|
||||
const handleAppStateChange = (state) => {
|
||||
if (state === "active") {
|
||||
clearBadgeCount();
|
||||
}
|
||||
};
|
||||
|
||||
const subscription = AppState.addEventListener(
|
||||
"change",
|
||||
handleAppStateChange
|
||||
);
|
||||
|
||||
return () => {
|
||||
if (subscription?.remove) {
|
||||
subscription.remove();
|
||||
} else {
|
||||
AppState.removeEventListener("change", handleAppStateChange);
|
||||
}
|
||||
};
|
||||
}, [clearBadgeCount]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!allowNotifications) {
|
||||
return;
|
||||
|
||||
@@ -84,6 +84,7 @@ const DEFAULT_CONTEXT = {
|
||||
isLooping: false,
|
||||
setLooping: noop,
|
||||
toggleLooping: noop,
|
||||
getTrackInfo: () => null,
|
||||
};
|
||||
|
||||
export const PlayerContext = createContext(DEFAULT_CONTEXT);
|
||||
@@ -230,6 +231,7 @@ const PlayerProvider = ({ children }) => {
|
||||
const autoPlayRef = useRef(false);
|
||||
const pendingSeekValueRef = useRef(null);
|
||||
const didJustFinishRef = useRef(false);
|
||||
const trackInfoRef = useRef({});
|
||||
|
||||
const setQueueIndexValue = useCallback((index = -1) => {
|
||||
const list = queueRef.current;
|
||||
@@ -401,6 +403,18 @@ const PlayerProvider = ({ children }) => {
|
||||
durationMs,
|
||||
};
|
||||
});
|
||||
|
||||
if (currentTrack?.id) {
|
||||
trackInfoRef.current[currentTrack.id] = {
|
||||
durationMs:
|
||||
durationMs > 0
|
||||
? durationMs
|
||||
: trackInfoRef.current[currentTrack.id]?.durationMs || 0,
|
||||
positionMs,
|
||||
isLoaded,
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
}, [status, currentTrack]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -614,6 +628,10 @@ const PlayerProvider = ({ children }) => {
|
||||
const toggleLooping = useCallback(() => {
|
||||
setIsLooping((prev) => !prev);
|
||||
}, []);
|
||||
const getTrackInfo = useCallback((trackId) => {
|
||||
if (!trackId) return null;
|
||||
return trackInfoRef.current[trackId] || null;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentTrack?.id) {
|
||||
@@ -692,6 +710,7 @@ const PlayerProvider = ({ children }) => {
|
||||
isLooping,
|
||||
setLooping,
|
||||
toggleLooping,
|
||||
getTrackInfo,
|
||||
}),
|
||||
[
|
||||
currentTrack,
|
||||
@@ -715,6 +734,7 @@ const PlayerProvider = ({ children }) => {
|
||||
setLooping,
|
||||
toggleLooping,
|
||||
setQueue,
|
||||
getTrackInfo,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user