last tickets
This commit is contained in:
+21
-4
@@ -14,7 +14,19 @@ export const getProjectLikes = (project, target = LIKE_TARGET.SONG) => {
|
||||
const path = target === LIKE_TARGET.PLAYBACK ? "playback" : "song";
|
||||
const likes = project?.likes;
|
||||
const list = likes ? likes[path] : null;
|
||||
return Array.isArray(list) ? list : [];
|
||||
const normalized = Array.isArray(list) ? list : [];
|
||||
const legacy = Array.isArray(project?.likedBy) ? project.likedBy : [];
|
||||
|
||||
if (target !== LIKE_TARGET.SONG || legacy.length === 0) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const merged = new Set(normalized);
|
||||
legacy.forEach((uid) => {
|
||||
if (uid) merged.add(uid);
|
||||
});
|
||||
|
||||
return Array.from(merged);
|
||||
};
|
||||
|
||||
export const isProjectLikedByUser = (
|
||||
@@ -35,11 +47,16 @@ export const toggleProjectLike = async ({
|
||||
if (!projectId) return;
|
||||
if (!ensureAuthenticated(currentUID)) return;
|
||||
const fieldPath = getLikeFieldPath(target);
|
||||
const likeOperation = next ? arrayUnion(currentUID) : arrayRemove(currentUID);
|
||||
await projectsRef.doc(projectId).set(
|
||||
{
|
||||
[fieldPath]: next
|
||||
? arrayUnion(currentUID)
|
||||
: arrayRemove(currentUID),
|
||||
[fieldPath]: likeOperation,
|
||||
...(target === LIKE_TARGET.SONG
|
||||
? {
|
||||
// Keep legacy likedBy in sync for clients still reading this field
|
||||
likedBy: next ? arrayUnion(currentUID) : arrayRemove(currentUID),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user