Skip to content

Commit

Permalink
Added iziToast
Browse files Browse the repository at this point in the history
  • Loading branch information
LesiaUKR committed Nov 23, 2023
1 parent 82ee278 commit 0233ca6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.6.2",
"izitoast": "^1.4.0",
"slim-select": "^2.6.0",
"vite-plugin-full-reload": "^1.0.5",
"vite-plugin-html-inject": "^1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/cat-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const fetchCatByBreed = async breedId => {
`${BASE_URL}${IMAGE_END_POINT}?breed_ids=${breedId}`
);
if (!responce || responce.status !== 200) {
throw new Error('Моя помилка');
throw new Error('Error fetching cat by breed');
}
return responce.data;
};
23 changes: 12 additions & 11 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ img {
}

.error {
display: none;
font-size: 20px;
}

.container {
Expand All @@ -51,16 +51,6 @@ img {
justify-content: center;
}

.cat-info {
display: flex;
justify-content: center;
flex-wrap: nowrap;
gap: 60px;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
}

.text-wrapper {
position: absolute;
top: 50%;
Expand All @@ -75,6 +65,17 @@ img {
.title {
color: #f0d62e;
}

.cat-info {
display: flex;
justify-content: center;
flex-wrap: nowrap;
gap: 60px;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
}

.imgWrapper {
width: 600px;
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ <h1>CatBreedsExplorer</h1>
autoplay
></dotlottie-player>
</div>
<p class="error">Oops! Something went wrong! Try reloading the page!</p>
<p class="error visually-hidden">
Oops! Something went wrong! Try reloading the page!
</p>
<div class="cat-info hidden"></div>
</div>
<script src="index.js" type="module"></script>
Expand Down
26 changes: 23 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import SlimSelect from 'slim-select';
import iziToast from 'izitoast';
import 'izitoast/dist/css/iziToast.min.css';
import { fetchBreeds, fetchCatByBreed } from './cat-api';

const catInfoBox = document.querySelector('.cat-info');
const select = document.querySelector('#selectElement');
const loader = document.querySelector('.loader');

const error = document.querySelector('.error');
const breedSelect = new SlimSelect({
select: '#selectElement',
settings: {
Expand Down Expand Up @@ -34,7 +36,16 @@ fetchBreeds()
})
.catch(err => {
loader.classList.add('visually-hidden');
console.log(err);
error.classList.remove('visually-hidden');
iziToast.show({
message: 'Failed to fetch cat breeds',
messageColor: 'red',
messageSize: '18px',
backgroundColor: '#ffffff',
position: 'topRight',
timeout: 2500,
});
console.log(err.message);
});

function onChangeSelect(evt) {
Expand All @@ -51,7 +62,16 @@ function onChangeSelect(evt) {
.catch(err => {
catInfoBox.innerHTML = '';
loader.classList.add('visually-hidden');
console.error('FetchCatByBreed Error:', err);
error.classList.remove('visually-hidden');
iziToast.show({
message: 'Error fetching cat by breed',
messageColor: 'red',
messageSize: '18px',
backgroundColor: '#ffffff',
position: 'topRight',
timeout: 2500,
});
console.log(err.message);
})
.finally(() => {
loader.classList.add('visually-hidden');
Expand Down

0 comments on commit 0233ca6

Please sign in to comment.