last tickets

This commit is contained in:
Thomas Demirdjian
2025-11-24 15:35:14 +01:00
parent 471a3177e8
commit 72852ad92b
40 changed files with 1749 additions and 667 deletions
+21 -4
View File
@@ -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 }
);