Skip to content

Commit

Permalink
Update PokemonDetail.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh1311 authored Nov 3, 2024
1 parent 28ee7a8 commit e4d7bb7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client/src/components/PokemonDetail.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { toast } from 'react-toastify';
import { adoptPokemon } from '../api/api';
import { colors, statColor } from '../constants';
import { useState } from 'react';
import { set } from 'react-hook-form';

const PokemonDetail = ({ pokemon }) => {
const [loading, setLoading] = useState(false);

const handleAdoption = async () => {
setLoading(true);
try {
const res = await adoptPokemon(pokemon.id);
toast.success(res.message);
setLoading(false);
} catch (e) {
toast.error(e.response.data.message);
setLoading(false);
}
};
return (
Expand Down Expand Up @@ -100,8 +106,13 @@ const PokemonDetail = ({ pokemon }) => {
<button
onClick={handleAdoption}
className="rounded-lg bg-blue-700 px-6 py-2 text-white hover:scale-110 hover:animate-spin hover:shadow-2xl"
disabled={loading}
>
Adopt Me
{
loading ? <div className='w-6 h-6 rounded-full mx-auto border-l-2 animate-spin border-white'>

</div> : 'Adopt'
}
</button>
</div>
</div>
Expand Down

0 comments on commit e4d7bb7

Please sign in to comment.