diff --git a/src/Components/CatProfile.tsx b/src/Components/CatProfile.tsx index 64a6665..2282980 100644 --- a/src/Components/CatProfile.tsx +++ b/src/Components/CatProfile.tsx @@ -13,28 +13,24 @@ import Messages from './Styling/Messages'; const { REACT_APP_LOGGED_IN_USER } = process.env; -function CatProfile() { +interface Props { + selectedCat: CatFromAxios; +} + +function CatProfile({ selectedCat }: Props) { const [catName, setCatName] = useState(''); const [catPicture, setCatPicture] = useState(''); const [catDescription, setCatDescription] = useState(''); const [catProfiles, setCatProfiles] = useState([]); - const [isLoading, setIsLoading] = useState(true); + const [isLoading, setIsLoading] = useState(false); const [message, setMessage] = useState(''); useEffect(() => { - getCatsProfiles(REACT_APP_LOGGED_IN_USER as string).then( - (fetchedProfiles) => { - if (Array.isArray(fetchedProfiles) && fetchedProfiles.length > 0) { - const profile = fetchedProfiles[0]; - setCatProfiles(fetchedProfiles); - setCatName(profile.name); - setCatPicture(profile.picture_url); - setCatDescription(profile.description); - } - setIsLoading(false); - } - ); - }, []); + setCatName(selectedCat.name); + setCatPicture(selectedCat.picture_url); + setCatDescription(selectedCat.description); + setCatProfiles([selectedCat]); + }, [selectedCat]); if (isLoading) { return

Loading...

; @@ -93,8 +89,8 @@ function CatProfile() { }; return ( -
-

Cat's Profile

+ <> +

{selectedCat.name}'s Profile

{message && ( <> {message === 'Updates have been saved' && ( @@ -111,7 +107,7 @@ function CatProfile() { )} )} -
+
- - -
-
+
+ + +
+ + ); } export default CatProfile; diff --git a/src/Components/MyClowder.tsx b/src/Components/MyClowder.tsx index 6cfc8e7..05f2805 100644 --- a/src/Components/MyClowder.tsx +++ b/src/Components/MyClowder.tsx @@ -22,20 +22,22 @@ export default function MyClowder() { } }, [userId]); - return selectedCat ? ( - - - - ) : ( + return ( <>

My Clowder

-
    - {myCats.map((cat) => ( -
  • - -
  • - ))} -
+ {selectedCat ? ( + + + + ) : ( +
    + {myCats.map((cat) => ( +
  • + +
  • + ))} +
+ )} ); } diff --git a/src/Components/Styling/Button.tsx b/src/Components/Styling/Button.tsx index c082f04..0f38913 100644 --- a/src/Components/Styling/Button.tsx +++ b/src/Components/Styling/Button.tsx @@ -8,14 +8,28 @@ interface Props { } export default function Button({ children, type, onClick, disabled }: Props) { + let colour = 'bg-blue-500'; + switch (children) { + case 'Submit': + colour = 'bg-green-500'; + break; + case 'Delete': + colour = 'bg-red-500'; + break; + default: + break; + } + return ( diff --git a/src/Components/Styling/FormInput.tsx b/src/Components/Styling/FormInput.tsx index fc3e897..9553664 100644 --- a/src/Components/Styling/FormInput.tsx +++ b/src/Components/Styling/FormInput.tsx @@ -20,7 +20,7 @@ export default function FormInput({ return ( +
{children}
);