Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple photos #26

Merged
merged 53 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f1b5ba0
Style the home buttons over the hero image to look like the buttons o…
Pma913 Feb 14, 2024
aae1458
Add two new files; a test-data to avoid constant requests to new data…
Pma913 Feb 15, 2024
43a170e
Update the old style of fact display to be cleaner and update the hov…
Pma913 Feb 15, 2024
11fb11a
Adjust styling to incorporate additional data displayed about each cat
Pma913 Feb 16, 2024
0ef773a
Add a new folder -FactCard- to the components folder with two new fil…
Pma913 Feb 16, 2024
31cf90c
Map incoming data to a list of FactCard components and render the fir…
Pma913 Feb 16, 2024
e647ae3
Add forward and back buttons for the fact display and some beginning …
Pma913 Feb 16, 2024
51fc1fe
Finish the logic for the counter with forward and back buttons and ad…
Pma913 Feb 16, 2024
8297bac
Update app to pull from the new cat api. Too many rerenders are happe…
Pma913 Feb 16, 2024
46a9201
Enable the user to continuously scroll through photos of cats and the…
Pma913 Feb 17, 2024
ebb21af
Update ui experience by dynamically keeping track of placeholder data…
Pma913 Feb 17, 2024
d390147
Add favorite icons and fix logic for favorite and unfavorite. Also re…
Pma913 Feb 17, 2024
93477d4
Remove data loader functionality
Pma913 Mar 6, 2024
5b66ab2
Clean up api-calls and Fact.js
Pma913 Mar 6, 2024
f8ffc6b
Add logic for gold thumbs up
Pma913 Mar 6, 2024
0f11796
Move the initial data fetching and state to app.js
Pma913 Mar 6, 2024
09b3348
Update data cleaner to assign unique ids to each cat
Pma913 Mar 6, 2024
ed5c2df
Change app architecture to maintain state of the whole app at the mai…
Pma913 Mar 6, 2024
28a0f05
Add a trash icon to favorite cards
Pma913 Mar 6, 2024
7b891d3
Add an expand icon for the favorite card
Pma913 Mar 6, 2024
53f8d83
Add transition to hover event for exposing action icons
Pma913 Mar 6, 2024
dd54b97
Adjust styling to favorites display background
Pma913 Mar 6, 2024
cb9372b
Add in some additional catches for error handling
Pma913 Mar 6, 2024
4f94b09
Add new component for expanded card and update cleaner to use supplie…
Pma913 Mar 7, 2024
d66ba4c
Add functionality to expand and shrink selected favorite card
Pma913 Mar 8, 2024
7e3d3fb
Add some styling to the expanded card
Pma913 Mar 8, 2024
933d53d
Adjust fonts for stats section
Pma913 Mar 8, 2024
463e3ba
Update cat-facts.json to reflect actual data response from new api to…
Pma913 Mar 8, 2024
b22825e
Update the should show a random fact upon visit test
Pma913 Mar 8, 2024
0701e4f
Remove console logs
Pma913 Mar 8, 2024
5a69133
Update cypress tests for fact component
Pma913 Mar 11, 2024
896ed00
Update favorites spec
Pma913 Mar 11, 2024
460d486
Remove old tests
Pma913 Mar 11, 2024
46045fa
Center text for the error compone t
Pma913 Mar 11, 2024
ba6f665
Add some responsive design to fact cards
Pma913 Mar 11, 2024
df5e0b1
Adjust left and right arrow buttons and add to responsiveness
Pma913 Mar 12, 2024
19ac0aa
Move next and previous card arrows to the inside of the fact cards
Pma913 Mar 12, 2024
3361583
Style card name to look like the appropriate title for each card
Pma913 Mar 12, 2024
f8fe619
Move the favorite icon to the same line as name
Pma913 Mar 12, 2024
00358a5
Move arrows so bottom lines up with bottom of cat image
Pma913 Mar 12, 2024
25954d7
Replace thumb icon with heart icon
Pma913 Mar 13, 2024
3b8e928
Remove thumbs up imports
Pma913 Mar 13, 2024
0e3810c
Improve responsiveness for name and favorite icon
Pma913 Mar 13, 2024
2961d96
Save favorited property to app state and add functionality to be able…
Pma913 Mar 13, 2024
92a407e
Adjust styling of home page and header
Pma913 Mar 14, 2024
8099107
Add home buttons to a container and include background-color
Pma913 Mar 14, 2024
762df20
Round home buttons
Pma913 Mar 14, 2024
8834a97
Display trash and expand icons when in mobile view
Pma913 Mar 15, 2024
15226a9
Add drop down icon
Pma913 Mar 15, 2024
a355077
Add functionality to drop down icon
Pma913 Mar 15, 2024
50fc57d
Add to responsive layout of the expanded card
Pma913 Mar 15, 2024
a2e597a
Add transition effect to app title
Pma913 Mar 15, 2024
4c9d3ec
Remove unused useState
Pma913 Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions cypress/e2e/error_spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
describe('error page', () => {
it('should display an error page if failed to get fact', () => {
cy.intercept('https://catfact.ninja/fact', {
statusCode: 500
})
cy.visit('http://localhost:3000/')
cy.get('button[class=fact-btn]').click()
cy.get('h2').contains("Looks like something is wrong. Please try again later.")
cy.visit('http://localhost:3000/factsss')
cy.get('.error-message').contains("Looks like something is wrong. Please try again later.")
})

it('should display message if no favorited facts', () => {
cy.visit('https://cats-meow.vercel.app/')
cy.get('button[class=fav-btn]').click()
cy.get('h2').contains('No saved ideas yet')
})
it('should be able to navigate back to home page', () => {
cy.intercept('https://catfact.ninja/fact', {
statusCode: 500
})
cy.visit('http://localhost:3000/')
cy.get('button[class=fact-btn]').click()
cy.get('h2').contains("Looks like something is wrong. Please try again later.")
cy.get('h3').click()
cy.get('h1').contains('Cats Meow')
})
})
47 changes: 13 additions & 34 deletions cypress/e2e/fact_spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
describe('visiting the fact page', () => {

it('should show a random fact upon visit', () => {
cy.clearAllSessionStorage()
cy.intercept('https://catfact.ninja/fact', {
cy.intercept('https://api.thecatapi.com/v1/images/search?size=med&mime_types=jpg&format=json&has_breeds=true&order=RANDOM&page=0&limit=10', {
status: 200,
fixture: 'cat-facts'
})
cy.visit('http://localhost:3000/')
cy.get('button[class=fact-btn]').click()
cy.get('p').contains('Cats can see like wicked good')
cy.get('p[class=name]').contains('Siamese')
cy.get('p[class=dog-friendly]').contains("Yes")
cy.get('p[class=energy-level]').contains(5)
cy.get('p[class=affection-level]').contains(5)
cy.get('p[class=origin]').contains('Thailand')
cy.get('p[class=temperament]').contains("Active, Agile, Clever, Sociable, Loving, Energetic")
cy.get('p[class=fact]').contains("While Siamese cats are extremely fond of their people, they will follow you around and supervise your every move, being talkative and opinionated. They are a demanding and social cat, that do not like being left alone for long periods.")
cy.get('img[class=fact-img]').should('be.visible')
})

it('should have two buttons', () => {
cy.clearAllSessionStorage()
it('should have three buttons', () => {
cy.visit('http://localhost:3000/fact')
cy.get('button[class=fav-card-btn]').should('be.visible')
cy.get('button[class=new-fact-btn]').should('be.visible')
})

it('should display error when failed to fetch fact and provide a path back home', () => {
cy.visit('http://localhost:3000/fact')
cy.intercept('https://catfact.ninja/fact', {
statusCode: 404,
body: '404 Not Found!',
headers: {
'x-not-found': 'true',
},
})
cy.get('h2').contains('Looks like something is wrong. Please try again later.')
cy.get('a').click()
cy.get('h1').contains('Cats Meow')
})

it('should maintain fact display over page refresh', () => {
cy.clearAllSessionStorage()
cy.visit('http://localhost:3000/fact')
cy.intercept('https://catfact.ninja/fact', {
status: 200,
fixture: 'cat-facts'
})
cy.get('button[class=new-fact-btn]').click()
cy.get('p').contains('Cats can see like wicked good')
cy.reload()
cy.get('p').contains('Cats can see like wicked good')
cy.get('.fav').should('be.visible')
cy.get('.left').should('be.visible')
cy.get('.right').should('be.visible')
})
})
53 changes: 34 additions & 19 deletions cypress/e2e/favorites_spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
describe('favorites page', () => {
it('should be able to favorite a fact', () => {
cy.intercept('https://catfact.ninja/fact', {
beforeEach(() => {
cy.intercept('https://api.thecatapi.com/v1/images/search?size=med&mime_types=jpg&format=json&has_breeds=true&order=RANDOM&page=0&limit=10', {
status: 200,
fixture: 'cat-facts'
})
cy.visit('http://localhost:3000/fact')
cy.get('button[class=new-fact-btn]').click()
cy.get('p').contains('Cats can see like wicked good')
cy.get('button[class=fav-card-btn]').click()
cy.get('div[class=nav-links]').children().next().next().click()
cy.get('p[class=fav-card-fact]').contains('Cats can see like wicked good')
cy.get('.name').contains('Siamese')
cy.get('.fav').click()
cy.get('.nav-links').children().next().next().click()
})

it('should have a card and a way to delete the card', () => {
cy.intercept('https://catfact.ninja/fact', {
status: 200,
fixture: 'cat-facts'
})
cy.visit('http://localhost:3000/fact')
cy.get('button[class=new-fact-btn]').click()
cy.get('button[class=fav-card-btn]').click()
cy.get('div[class=nav-links]').children().next().next().click()
cy.get('div[class=fav-card]').should('have.length', 1)
cy.get('button[class=delete-btn]:first').click()
cy.get('section[class=fav-card-display]').contains('No saved ideas yet')
it('should contain a favorited fact', () => {
cy.get('.fav-card-name').contains('Siamese')
})

it('should have have a delete button', () => {
cy.get('.card-btn-container').invoke('show')
cy.get('.delete-btn').invoke('show').click()
cy.get('.no-ideas').contains('No saved ideas yet')
})

it('should have an expand button', () => {
cy.get('.card-btn-container').invoke('show')
cy.get('.expand-btn').invoke('show').click()
cy.get('.exp-name').contains('Siamese')
cy.get('.exp-description').contains('While Siamese cats are extremely fond of their people, they will follow you around and supervise your every move, being talkative and opinionated. They are a demanding and social cat, that do not like being left alone for long periods.')
cy.get('.exp-stats-title').contains('Stats')
cy.get('.exp-dogFriendly').contains('Yes')
cy.get('.exp-energyLevel').contains('5')
cy.get('.exp-origin').contains('Thailand')
cy.get('.exp-temperament').contains('Active, Agile, Clever, Sociable, Loving, Energetic')
cy.get('.exp-links-title').contains('External Links')
cy.get('.vca-link').contains('VCA')
cy.get('.wiki-link').contains('Wikipedia')
})

it('should have a button to return to favorites view', () => {
cy.get('.card-btn-container').invoke('show')
cy.get('.expand-btn').invoke('show').click()
cy.get('.remove-card').click()
})
})
50 changes: 48 additions & 2 deletions cypress/fixtures/cat-facts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
{
"fact": "Cats can see like wicked good"
[{
"breeds": [{
"adaptability": "5",
"affection_level": "5",
"alt_names": "Siam, Thai Cat",
"cfa_url": "http://cfa.org/Breeds/BreedsSthruT/Siamese.aspx",
"child_friendly": "4",
"country_code": "TH",
"country_codes": "TH",
"description": "While Siamese cats are extremely fond of their people, they will follow you around and supervise your every move, being talkative and opinionated. They are a demanding and social cat, that do not like being left alone for long periods.",
"dog_friendly": "5",
"energy_level": "5",
"experimental": "0",
"grooming": "1",
"hairless": "0",
"health_issues": "1",
"hypoallergenic": "1",
"id": "siam",
"indoor": "0",
"intelligence": "5",
"lap": "1",
"life_span": "12 - 15",
"name": "Siamese",
"natural": "0",
"origin": "Thailand",
"rare": "0",
"reference_image_id": "ai6Jps4sx",
"rex": "0",
"shedding_level": "2",
"short_legs": "0",
"social_needs": "5",
"stranger_friendly": "5",
"suppressed_tail": "0",
"temperament": "Active, Agile, Clever, Sociable, Loving, Energetic",
"vcahospitals_url": "https://vcahospitals.com/know-your-pet/cat-breeds/siamese",
"vetstreet_url": "http://www.vetstreet.com/cats/siamese",
"vocalisation": 5,
"weight": {
"imperial": "8 - 15",
"metric": "4 - 7"
},
"wikipedia_url": "https://en.wikipedia.org/wiki/Siamese_(cat)"
}],
"height": "809",
"id": "uTG1YFzJV",
"url": "https://cdn2.thecatapi.com/images/uTG1YFzJV.jpg",
"width": "1080"
}
]
2 changes: 1 addition & 1 deletion src/components/About/About.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.about-box {
display: flex;
background-color: pink;
background-color: #4b5d67;
}

.how-list {
Expand Down
4 changes: 3 additions & 1 deletion src/components/App/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
html {
height: 100%;
background-color: black;
}

main {
height: 100%;
}
}
73 changes: 58 additions & 15 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
import './App.css';
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import Home from '../Home/Home';
import Fact, { factLoader } from '../Fact/Fact';
import Fact from '../Fact/Fact';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import Favorites from '../Favorites/Favorites';
import Error from '../Error/Error';
import RootLayout from '../../utilities/RootLayout';
import dataCleaner from '../../utilities/dataCleaner';
import { getCatPhotos } from '../../utilities/api-call';

const App = () => {
const [favorites, setFavorites] = useState(JSON.parse(sessionStorage.getItem('allFavorites')) || []);
const [favoritedFacts, setFavoritedFacts] = useState([]);
const [cats, setCats] = useState([]);
const [count, setCount] = useState(0);
const [err, setErr] = useState()

useEffect(() => {
if (cats.length === 0) {
getCatPhotos()
.then(res => {
setCats(dataCleaner(res))
})
.catch(err => {
console.log(err)
setErr(err)

})
}
},[cats])

const favoriteFact = (currentFact) => {
const noDuplicate = favorites.every(fact => fact.fact !== currentFact.fact)

const noDuplicate = favoritedFacts.every(fact => fact.id !== currentFact.id)
if (noDuplicate) {
setFavorites([...favorites, currentFact])
sessionStorage.setItem('allFavorites', JSON.stringify([...favorites, currentFact]))
currentFact.favorited = true;
setFavoritedFacts([...favoritedFacts, currentFact])
const updatedCats = cats.map((cat) => {
if (cat.id === currentFact.id) {
return currentFact
}
return cat
});
setCats([...updatedCats])
}
}

const removeFav = (id) => {
sessionStorage.removeItem('allFavorites')
const newFavs = favorites.filter(fact => fact.id !== id)
setFavorites(newFavs)
sessionStorage.setItem('allFavorites', JSON.stringify(newFavs))
const updatedCats = cats.map((cat) => {
if (cat.id === id) {
cat.favorited = false;
return cat
}
return cat
});
setCats([...updatedCats])
const newFavs = favoritedFacts.filter(fact => fact.id !== id)
setFavoritedFacts(newFavs)
}

const addData = (data) => {
setCats([...cats, ...data])
}

const routes = createBrowserRouter([
Expand All @@ -38,17 +73,25 @@ const App = () => {
},
{
path: "/fact",
element: <Fact favFact={favoriteFact} />,
loader: factLoader
element: <Fact
favFact={favoriteFact}
removeFav={removeFav}
setCats={setCats}
cats={cats}
addData={addData}
catCount={count}
err={err}
setErr={err}
saveCatCount={setCount}/>,
},
{
path: "/favorites",
element: <Favorites removeFav={removeFav} favs={favorites} />
element: <Favorites removeFav={removeFav} favs={favoritedFacts} />
}
]
}
])

return (
<RouterProvider router={routes} />
)
Expand Down
Loading