Ajout de l'icone partage sur la page collection + appel axios

This commit is contained in:
Damien Broqua 2022-03-05 21:02:38 +01:00
parent 796f985991
commit 657b44c122
6 changed files with 74 additions and 3 deletions

View file

@ -2,13 +2,16 @@
* Fonction permettant d'afficher un message dans un toastr * Fonction permettant d'afficher un message dans un toastr
* @param {String} message * @param {String} message
*/ */
function showToastr(message) { function showToastr(message, success = false) {
let x = document.getElementById("toastr"); let x = document.getElementById("toastr");
if ( message ) { if ( message ) {
x.getElementsByTagName("SPAN")[0].innerHTML = message; x.getElementsByTagName("SPAN")[0].innerHTML = message;
} }
x.className = `${x.className} show`; x.className = `${x.className} show`.replace("sucess", "");
if ( success ) {
x.className = `${x.className} success`;
}
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000); setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}; };

View file

@ -83,3 +83,7 @@ html {
display: initial; display: initial;
} }
} }
.is-danger {
color: $nord12;
}

View file

@ -1,4 +1,9 @@
.ma-collection { .ma-collection {
h1 {
i {
cursor: pointer;
}
}
.filters { .filters {
display: flex; display: flex;
justify-content: end; justify-content: end;

View file

@ -13,6 +13,11 @@
color: $button-alternate-color; color: $button-alternate-color;
border-radius: 6px; border-radius: 6px;
&.success {
background-color: $success-color;
color: $button-font-color;
}
&.show { &.show {
visibility: visible; visibility: visible;
animation: toastrFadein 0.5s, toastrFadeout 0.5s 2.5s; animation: toastrFadein 0.5s, toastrFadeout 0.5s 2.5s;

View file

@ -23,6 +23,10 @@ const UserSchema = new mongoose.Schema(
}, },
hash: String, hash: String,
salt: String, salt: String,
isPublicCollection: {
type: Boolean,
default: false,
},
}, },
{ timestamps: true } { timestamps: true }
); );

View file

@ -1,5 +1,8 @@
<main class="layout-maxed ma-collection" id="app"> <main class="layout-maxed ma-collection" id="app">
<h1>Ma collection</h1> <h1>
Ma collection
<i class="icon-share" @click="toggleModalShare" aria-label="Partager ma collection" title="Votre collection sera visible en lecture aux personnes ayant le lien de partage"></i>
</h1>
<div class="filters"> <div class="filters">
<div class="field"> <div class="field">
<label for="artist">Artiste</label> <label for="artist">Artiste</label>
@ -105,9 +108,35 @@
</footer> </footer>
</div> </div>
</div> </div>
<div class="modal" :class="{'is-visible': showModalShare}">
<div class="modal-background"></div>
<div class="modal-card">
<header>
Partager ma collection
</header>
<section>
Votre collection sera visible de toute personne disposant du lien suivant :
<br />
<a :href="shareLink" target="_blank">{{shareLink}}</a>
<br />
Ce lien permet uniquement de visualiser l'ensemble de votre collection mais ne perment <strong class="is-danger">en aucun cas</strong> de la modifier.
<br />
Vous pourrez à tout moment supprimer le lien de partage en cliquant à nouveau sur l'icône <i class="icon-share"></i> sur votre collection.
</section>
<footer>
<button class="button is-primary" @click="shareCollection">Partager</button>
<button class="button" @click="toggleModalShare">Annuler</button>
</footer>
</div>
</div>
</main> </main>
<script> <script>
const {
protocol,
host
} = window.location;
Vue.createApp({ Vue.createApp({
data() { data() {
return { return {
@ -124,6 +153,8 @@
order: 'asc', order: 'asc',
itemId: null, itemId: null,
showModalDelete: false, showModalDelete: false,
showModalShare: false,
shareLink: `${protocol}//${host}/collection/<%= user._id %>`,
} }
}, },
created() { created() {
@ -190,6 +221,9 @@
toggleModal() { toggleModal() {
this.showModalDelete = !this.showModalDelete; this.showModalDelete = !this.showModalDelete;
}, },
toggleModalShare() {
this.showModalShare = !this.showModalShare;
},
showConfirmDelete(itemId) { showConfirmDelete(itemId) {
this.itemId = itemId; this.itemId = itemId;
this.toggleModal(); this.toggleModal();
@ -205,6 +239,22 @@
.finally(() => { .finally(() => {
this.toggleModal(); this.toggleModal();
}); });
},
shareCollection() {
axios.post(`/api/v1/me`, {
isPublicCollection: true,
})
.then( () => {
showToastr("Collection partagée", true);
window.open(this.shareLink, '_blank');
})
.catch((err) => {
showToastr(err.response?.data?.message || "Impossible de supprimer cet album");
})
.finally(() => {
this.toggleModalShare();
});
} }
} }
}).mount('#app'); }).mount('#app');