Skip to content

Commit

Permalink
adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
JyyHuang committed Aug 10, 2023
1 parent f41bb00 commit 6b82ed2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions vite-project/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function App() {
const [page, setPage] = useState("Search");
const [theme, setTheme] = useState(false);

// Changes pages on button click
function changeContact() {
setPage("Contact");
setTheme(prevTheme => !prevTheme);
Expand Down
8 changes: 2 additions & 6 deletions vite-project/src/FavItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import React, { useEffect, useState } from "react";
export default function Item(props) {
const {title, price, image, itemWebUrl, itemID} = props;


// Removes from localStorage when clicked
function toggleClass() {
if (Object.keys(localStorage).includes(itemID)) {
removeFavorite();
window.localStorage.removeItem(itemID)
}
};

function removeFavorite() {
window.localStorage.removeItem(itemID)
}

return(
<div className="column">
<div className="item">
Expand Down
2 changes: 1 addition & 1 deletion vite-project/src/Favorites.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import FavItem from './FavItem'

export function Favorites() {


// Iterate through localStorage to get data to pass props to FavItem component
const keys = Object.keys(localStorage)
const results =[]
for (let i = 0; i < keys.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion vite-project/src/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React from "react";
export default function Item(props) {
const {title, price, image, itemWebUrl, itemID} = props;


// Item component for SearchResults
// When add button clicked, data gets added or removed from localStorage
function toggleClass() {
if (Object.keys(localStorage).includes(itemID)) {
removeFavorite();
Expand Down

0 comments on commit 6b82ed2

Please sign in to comment.