Skip to content

Commit

Permalink
Merge pull request #86 from HE-Arc/simon-plumey-84-fixer-nombre-dessais
Browse files Browse the repository at this point in the history
Adding nb of tries
  • Loading branch information
Krucksy authored Dec 14, 2023
2 parents 57f4fad + a889ab2 commit 0579c6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
26 changes: 14 additions & 12 deletions resources/js/components/comparaison.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const { data } = toRefs(props);
const emit = defineEmits(['clear-history'])
const nbTries = ref(0);
const title = ref('');
const artist = ref({
Expand Down Expand Up @@ -44,7 +42,6 @@ const time = ref({
});
function resetFields() {
nbTries.value = 0
title.value = ''
artist.value.label = 'Artist ?'
Expand All @@ -71,7 +68,6 @@ function resetFields() {
function updateFields(comparisonData) {
// this is related to the backend object strucutre
// to understand, check Documentation API available at https://github.com/HE-Arc/MusicGuessr/wiki/Documentation-API
nbTries.value+=1
let cp = comparisonData
// artist
Expand Down Expand Up @@ -151,12 +147,7 @@ function updateFields(comparisonData) {
title.value = cp.name
endGame()
// redirect to /success route TODO is it the right way to do it ?
window.location.href = '/success?title=' + encodeURIComponent(cp.name)
+ '&artist=' + encodeURIComponent(cp.artist_name)
+ '&spotify_id=' + encodeURIComponent(cp.spotify_id)
+ '&nb_tries=' + nbTries.value;
redirectToSuccess(cp.name, cp.artist_name, cp.spotify_id)
}
else
{
Expand All @@ -165,6 +156,19 @@ function updateFields(comparisonData) {
saveFieldsInLocalStorage()
}
async function redirectToSuccess(title, artist, spotify_id) {
let urlToRedirect = '/success?title=' + encodeURIComponent(title)
+ '&artist=' + encodeURIComponent(artist)
+ '&spotify_id=' + encodeURIComponent(spotify_id);
const answer = await axios.post('/nb_tries')
if (answer.status == 200) {
urlToRedirect += '&nb_tries=' + encodeURIComponent(answer.data.nb_tries);
}
window.location.href = urlToRedirect;
}
function convertMsToMinSec(timeInMs) {
let minutes = Math.floor(timeInMs / 60000)
let seconds = ((timeInMs % 60000) / 1000).toFixed(0)
Expand Down Expand Up @@ -195,7 +199,6 @@ async function startGame() {
function saveFieldsInLocalStorage()
{
localStorage.setItem('nbTries', nbTries.value)
localStorage.setItem('title', title.value)
localStorage.setItem('artist', JSON.stringify(artist.value))
localStorage.setItem('album', JSON.stringify(album.value))
Expand All @@ -205,7 +208,6 @@ function saveFieldsInLocalStorage()
}
function fetchFromLocalStorage() {
nbTries.value = localStorage.getItem('nbTries')
title.value = localStorage.getItem('title')
genres.value.list = []
Expand Down
3 changes: 1 addition & 2 deletions resources/js/components/search-bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ async function getSongs(userInput) {
async function sendProposition(songId) {
const answer = await axios.post('/comparison_with_answer_song/', {
song_id: songId,
nb_tries: 5 //TODO Simon: Add nb_try stored in local storage
song_id: songId
})
emit('send-comparaison', answer.data);
Expand Down
2 changes: 2 additions & 0 deletions resources/views/game/success.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<h3 class="music-title neon-text-effect-cyan">{{ $title }}</h3>
<p class="music-artist">{{ $artist }}</p>
</div>
@isset($nb_tries)
<p class="nb-tries">Vous l'avez trouvé en {{ $nb_tries }} essais!</p>
@endisset
<h2>Ecouter:</h2>
<div class="spotify-container neon-effect-magenta">
<iframe style="border-radius:12px"
Expand Down

0 comments on commit 0579c6f

Please sign in to comment.