import React, { useEffect, useState } from "react";
import "./styles.css";
import { JokeOne } from "./JokeOne";
import { JokeTwo } from "./JokeTwo";
export default function App() {
const [jokesList, setJokesList] = useState([]);
const [randomJoke, setRandomJoke] = useState("");
const addJoke = () => {
fetch(`https://jsonplaceholder.typicode.com/todos/${jokesList.length + 1}`)
.then((res) => res.json())
.then((data) => setJokesList([...jokesList, data.title]));
}
const getRandomJoke = () => {
fetch("https://api.chucknorris.io/jokes/random?category=sport")
.then((res) => res.json())
.then((data) => setRandomJoke(data.value));
};
const handleReset = () => {
getRandomJoke();
setJokesList([]);
}
useEffect(() => {
getRandomJoke();
}, []);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<hr />
<JokeOne onAdd={addJoke} data={jokesList}/>
<hr />
<JokeTwo data={randomJoke}/>
<hr />
<button onClick={handleReset}>Обновить шутки</button>
</div>
);
}
const form = document.getElementById('form');
const cardNumberInput = document.getElementById('card-input');
form.addEventListener('submit', (event) => {
const cardNumber = cardNumberInput.value;
const isCardNumberValid = luhnAlgorithm(cardNumber);
if (!isCardNumberValid) {
event.preventDefault();
cardNumberInput.classList.add('invalid-card')
}
})
function trimNumber(num, count) {
const [a = '0', b = ''] = String(num).split('.');
return [a, b.slice(0, count).padEnd(count, '0')].join('.')
}
<span class="bg-primary ${item.dailyBalance < 0 ? 'balance-negative' : 'balance-positive'}">${item.date} - ${item.dailyBalance}</span>
item.dailyBalance.toFixed(2)
deDB.run('SELECT id, dt FROM meta', function(err) {
if (err) {
res = true;
}
console.trace('Step1');
resolve();
});
setTimeout(() => {
if (err) {
res = true;
}
console.trace('Step1');
}, 1000)
const btn = document.getElementById ('share');
const modal = document.getElementById ('news_share');
btn.onclick = () => {
modal.classList.add("active");
modal.addEventListener("click", closeModal);
};
document.onclick = function(event){
var target = event.target
if (target !== modal && !modal.contains(target)) { // <--------------------- Вот тут
closeModal();
}
};
function closeModal() {
modal.removeEventListener("click", closeModal);
};
const BATCH_SIZE = 1000;
const cacheImages = async () => {
const batches = await lodash.chunk(srcArray, BATCH_SIZE);
for (const batch of batches) {
const promises = batch.map(src => {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = resolve;
img.onerror = reject;
img.src = src;
window[src] = img;
});
});
await Promise.all(promises);
}
};