Info lors d'un ajout d'album déjà en collection

This commit is contained in:
Damien Broqua 2023-09-24 14:53:04 +02:00
parent 205474a701
commit 81c61a0529
5 changed files with 43 additions and 2 deletions

View file

@ -113,6 +113,7 @@ Vue.createApp({
format,
genre,
style,
inCollection,
} = results[i];
items.push({
id,
@ -123,6 +124,7 @@ Vue.createApp({
format,
genre,
style,
inCollection,
});
}

View file

@ -7,10 +7,18 @@
.list {
margin-top: 2rem;
.item{
.item {
img {
cursor: pointer;
}
&.in-collection {
opacity: 0.6;
small {
font-style: italic;
}
}
}
}
}

View file

@ -167,6 +167,7 @@ Publié automatiquement via #musictopus`;
genre,
style,
userId: collectionUserId,
discogsIds,
} = this.req.query;
let userId = this.req.user?._id;
@ -216,6 +217,10 @@ Publié automatiquement via #musictopus`;
userId = userIsSharingCollection._id;
}
if (discogsIds) {
where.discogsId = { $in: discogsIds };
}
const count = await AlbumsModel.count({
User: userId,
...where,

View file

@ -3,6 +3,7 @@ import { ensureLoggedIn } from "connect-ensure-login";
import { sendResponse } from "../../../libs/format";
import { searchSong, getAlbumDetails } from "../../../helpers";
import Albums from "../../../middleware/Albums";
// eslint-disable-next-line new-cap
const router = express.Router();
@ -16,6 +17,30 @@ router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
req.query.country || null
);
const discogsIds = [];
const foundIds = [];
for (let i = 0; i < data.results.length; i += 1) {
discogsIds.push(data.results[i].id);
}
req.query.discogsIds = discogsIds;
const albums = new Albums(req);
const myAlbums = await albums.getAll();
if (myAlbums.rows) {
for (let i = 0; i < myAlbums.rows.length; i += 1) {
foundIds.push(myAlbums.rows[i].discogsId);
}
}
for (let i = 0; i < data.results.length; i += 1) {
data.results[i].inCollection = foundIds.includes(
data.results[i].id
);
}
sendResponse(req, res, data);
} catch (err) {
next(err);

View file

@ -34,8 +34,9 @@
<div class="grid grid-cols-1 md:grid-cols-2 list hover">
<div class="item" v-if="!loading" v-for="item in items">
<div v-if="!loading" v-for="item in items" class="item" :class="{'in-collection': item.inCollection}">
<a @click="loadDetails(item.id)" class="title">{{ item.artists_sort }} {{ item.title }}</a>
<small v-if="item.inCollection"> (Dans ma collection)</small>
<div class="grid grid-cols-2 md:grid-cols-4">
<div>
<img :src="item.thumb" :alt="item.title" @click="loadDetails(item.id)"/>