Remove random recipe button

This commit is contained in:
Maël Brunet 2021-06-06 00:26:07 +02:00
parent dde00caf5a
commit 6fc749cb63
2 changed files with 0 additions and 41 deletions

View file

@ -15,8 +15,6 @@ bodyClass: c-home
<div class="l-container"> <div class="l-container">
{% set homeSearch = true %} {% set homeSearch = true %}
{% include "components/search.njk" %} {% include "components/search.njk" %}
<a x-data="getRandomRecipe()" x-init="initRandomRecipe()" x-bind:href="url" class="c-search__random-link">🔀 {{ randomRecipe }}</a>
</div> </div>
</section> </section>
@ -51,25 +49,4 @@ bodyClass: c-home
</div> </div>
</section> </section>
{% endif %} {% endif %}
<script>
function getRandomRecipe() {
return {
url: '',
initRandomRecipe() {
const random = (recipes) => recipes[Math.floor(Math.random() * recipes.length)];
if (sessionStorage.getItem('searchResults')) {
this.url = random(JSON.parse(sessionStorage.getItem('searchResults'))).url;
} else {
fetch('/search.json').then(res => res.json()).then(res => {
sessionStorage.setItem('searchResults', JSON.stringify(res));
this.url = random(res).url;
});
}
}
}
}
</script>
{% endblock %} {% endblock %}

View file

@ -122,21 +122,3 @@
.c-search__search-result-ingredients--home { .c-search__search-result-ingredients--home {
font-size: 1rem; font-size: 1rem;
} }
.c-search__random-link {
display: block;
width: max-content;
margin: 10px auto 0;
padding: 6px 10px;
border: none;
border-radius: 4px;
background-color: var(--color-grey-900);
color: var(--color-white);
font-weight: bold;
text-decoration: none;
&:hover, &:focus {
text-decoration: none;
background-color: var(--color-grey-800);
}
}