probleme
This commit is contained in:
@@ -65,7 +65,7 @@ window.observeAuthState = function(callback) {
|
||||
};
|
||||
|
||||
|
||||
export async function favorite(releaseId) {
|
||||
export async function favorite(releaseId, type) {
|
||||
const storedUid = localStorage.getItem("uid");
|
||||
|
||||
const usersRef = collection(db, "users");
|
||||
@@ -80,6 +80,7 @@ export async function favorite(releaseId) {
|
||||
|
||||
await addDoc(favoritesRef, {
|
||||
releaseId: releaseId,
|
||||
Type: type,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -107,10 +108,16 @@ export async function getFavorites() {
|
||||
const favoritesRef = collection(db, "users", userDocId, "favorites");
|
||||
const snapshot = await getDocs(favoritesRef);
|
||||
|
||||
return snapshot.docs.map(doc => doc.data().releaseId);
|
||||
return snapshot.docs.map(doc => {
|
||||
const data = doc.data();
|
||||
return {
|
||||
releaseId: data.releaseId,
|
||||
Type: data.Type
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function isFavorite(releaseId) {
|
||||
export async function isFavorite(releaseId, type) {
|
||||
const storedUid = localStorage.getItem("uid");
|
||||
if (!storedUid) return false;
|
||||
|
||||
@@ -124,13 +131,17 @@ export async function isFavorite(releaseId) {
|
||||
const userDocId = userDoc.id;
|
||||
|
||||
const favoritesRef = collection(db, "users", userDocId, "favorites");
|
||||
const favQuery = query(favoritesRef, where("releaseId", "==", releaseId));
|
||||
const favQuery = query(favoritesRef, where("releaseId", "==", releaseId), where("Type", "==", type));
|
||||
const favSnapshot = await getDocs(favQuery);
|
||||
|
||||
return !favSnapshot.empty;
|
||||
if (!favSnapshot.empty) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeFavorite(releaseId) {
|
||||
export async function removeFavorite(releaseId, type) {
|
||||
const storedUid = localStorage.getItem("uid");
|
||||
|
||||
const usersRef = collection(db, "users");
|
||||
@@ -141,7 +152,7 @@ export async function removeFavorite(releaseId) {
|
||||
const userDocId = userDoc.id;
|
||||
|
||||
const favoritesRef = collection(db, "users", userDocId, "favorites");
|
||||
const favQuery = query(favoritesRef, where("releaseId", "==", releaseId));
|
||||
const favQuery = query(favoritesRef, where("releaseId", "==", releaseId), where("Type", "==", type));
|
||||
const favSnapshot = await getDocs(favQuery);
|
||||
|
||||
await deleteDoc(favSnapshot.docs[0].ref);
|
||||
|
||||
Reference in New Issue
Block a user