Реализовать кнопку добавить в избранное
Я разрабатываю приложение и работаю с api https://api.chucknorris.io, использую чистый js.
В левой колонке я радиокнопкой выбираю категорию шутки и нажимаю кнопку "Получить шутку".
Нажав сердечко необходимо добавить шутку в избранное и отобразить ее в правой колонке. У меня абсолютно нет идей, как это реализовать.
Пожалуйста, только чистый js. Спасибо.
const getJoke = () => {
let radioInput = document.querySelector(".radio__input");
let jokes = document.querySelector(".jokes");
let request = new Promise(() => {
fetch("https://api.chucknorris.io/jokes/random")
.then((data) => data.json())
.then((data) => {
jokes.insertAdjacentHTML(
"afterbegin",
showJoke(data.id, data.categories, data.value, data.updated_at)
);
});
});
};
document.querySelector(".get-joke__btn").onclick = getJoke;
const showJoke = (id, category, joke, updated) => {
return ` <div class="joke">
<div class="joke__id">
id: <a href="https://api.chucknorris.io/jokes/${id}">ID: ${id}</a><img src="../link.png" alt="">
</div>
<div class="joke__text">
${joke}
</div>
<div class="joke__info">
<div class="info__updated">
Last update: ${updated} hours ago
</div>
<div class="info__category">
${category}
</div>
</div>
</div>`;
};
.left .container {
max-width: 680px;
margin: 0 auto;
}
.right .container {
max-width: 400px;
margin: 0 auto;
}
.app {
display: flex;
justify-content: center;
min-height: 100vh;
}
.left {
width: 960px;
padding-top: 40px;
}
.get-joke__btn {
font-weight: bold;
font-size: 16px;
line-height: 22px;
color: #FFFFFF;
background: linear-gradient(92.01deg, #8EA7FF 0%, #7291FF 100%);
border-radius: 10px;
padding: 9px 37px;
cursor: pointer;
}
.jokes {
padding-top: 40px;
}
.joke {
padding: 67px 40px 45px 100px;
background: #F8F8F8;
border-radius: 20px;
position: relative;
margin-bottom: 20px;
}
.joke::after {
content: "";
display: block;
background: url(" https://img.icons8.com/ios/50/000000/like.png");
height: 50px;
width: 50px;
position: absolute;
top: 40px;
right: 41px;
}
.joke__id {
font-weight: 500;
font-size: 10px;
line-height: 14px;
}
.joke__text {
font-size: 18px;
line-height: 26px;
color: #333333;
margin-top: 5px;
}
.joke__info {
display: flex;
justify-content: space-between;
margin-top: 28px;
}
.info__updated {
font-size: 10px;
line-height: 14px;
color: #ABABAB;
}
.info__category {
margin-top: -5px;
font-weight: 500;
font-size: 10px;
line-height: 14px;
letter-spacing: 2px;
text-transform: uppercase;
color: #333333;
background: #FFFFFF;
border-radius: 6px;
padding: 6px 20px;
}
.right {
width: 480px;
background: #F8F8F8;
}
<div class="app">
<section class="left">
<div class="container">
<div class="get-joke">
<div class="get-joke__item">
<div class="radio">
<input type="radio" class="radio__input" id="random" name="option" value="random">
<label class="radio__label" for="random">Random</label>
</div>
</div>
<button class="get-joke__btn">Get a joke</button>
</div>
<div class="jokes"></div>
</div>
</section>
<section class="right">
<div class="container">
Favourite
</div>
</section>
</div>