-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ade505
commit c78a393
Showing
226 changed files
with
35,178 additions
and
1,480 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,37 @@ | ||
// not empty | ||
@font-face { | ||
font-family: Mont; | ||
src: url(../src/fonts/Mont-Regular.otf); | ||
} | ||
|
||
@font-face { | ||
font-family: Mont; | ||
src: url(../src/fonts/Mont-SemiBold.otf); | ||
font-weight: 700; | ||
} | ||
|
||
@font-face { | ||
font-family: Mont; | ||
src: url(../src/fonts/Mont-Bold.otf); | ||
font-weight: 800; | ||
} | ||
|
||
@import "../src/styles/utils/vars"; | ||
@import "../src/styles/utils/mixins"; | ||
|
||
@import "../src/styles/page.scss"; | ||
@import "../src/styles/nav.scss"; | ||
@import "../src/styles/container.scss"; | ||
@import "../src/styles/button.scss"; | ||
@import "../src/styles/shop.scss"; | ||
@import "../src/styles/category.scss"; | ||
@import "../src/styles/icon.scss"; | ||
@import "../src/styles/footer.scss"; | ||
@import "../src/styles/filter.scss"; | ||
@import "../src/styles/error.scss"; | ||
@import "../src/styles/basket.scss"; | ||
@import "../src/styles/header.scss"; | ||
@import "../src/styles/item.scss"; | ||
@import "../src/styles/pagination.scss"; | ||
@import "../src/styles/slider.scss"; | ||
@import "../src/styles/notFound.scss"; | ||
@import "../src/styles/loader.scss"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,194 @@ | ||
import './App.scss'; | ||
import { | ||
Route, Routes, Navigate, | ||
} from 'react-router-dom'; | ||
import { useEffect, useState } from 'react'; | ||
import { Header } from './Header'; | ||
import { Footer } from './Footer'; | ||
import { Iphone } from './types/Iphone'; | ||
import { PhonesPage } from './PhonesPage'; | ||
import { HomePage } from './HomePage'; | ||
import { NotImplemented } from './PageNotImplemented'; | ||
import { Favorites } from './Favorites'; | ||
import { Basket } from './Basket'; | ||
import { PhoneDescription } from './PhoneDescription'; | ||
import { getAll } from './api/iphones'; | ||
|
||
const App = () => ( | ||
<div className="App"> | ||
<h1>React Phone Catalog</h1> | ||
</div> | ||
); | ||
const App = () => { | ||
const [iphones, setIphones] = useState<Iphone[]>([]); // - | ||
const [selectedIphoneId] = useState<null | string>(null); // - set | ||
const [favorites, setFavorites] = useState<Iphone[]>([]); | ||
const [selectedIphoneIdToBuy] = useState<null | string>(null); | ||
const [iphonesToBuy, setIphonesToBuy] = useState<Iphone[]>([]); | ||
const [iphoneTitle, setIphoneTitle] = useState(''); | ||
|
||
useEffect(() => { | ||
getAll().then((items) => setIphones(items)); | ||
}, []); | ||
|
||
const handleRemoveIphone = (iphoneId: string) => { | ||
setIphonesToBuy(iphonesToBuy.filter(iphone => iphoneId !== iphone.id)); | ||
}; | ||
|
||
const handleSetInputText = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setIphoneTitle(event.target.value); | ||
}; | ||
|
||
const handleSelectPhone = (iphoneId: string | undefined) => { | ||
const selectedIphone = iphones.find((iphone) => iphone.id === iphoneId); // was visibleItems before instead of iphones | ||
|
||
if (selectedIphone) { | ||
const isFavorite = favorites | ||
.some((iphone) => iphone.id === selectedIphone.id); | ||
|
||
if (isFavorite) { | ||
const updatedFavorites = favorites | ||
.filter((iphone) => iphone.id !== selectedIphone.id); | ||
|
||
setFavorites(updatedFavorites); | ||
} else { | ||
const updatedFavorites = [...favorites, selectedIphone]; | ||
|
||
setFavorites(updatedFavorites); | ||
} | ||
} | ||
}; | ||
|
||
const handleSelectPhoneToBuy = (iphoneId: string | undefined) => { | ||
const selectedIphoneToBuy = iphones | ||
.find((iphone) => iphone.id === iphoneId); | ||
|
||
if (selectedIphoneToBuy) { | ||
const isInBasket = iphonesToBuy | ||
.some((iphone) => iphone.id === selectedIphoneToBuy.id); | ||
|
||
if (isInBasket) { | ||
const updatedInBasket = iphonesToBuy | ||
.filter((iphone) => iphone.id !== selectedIphoneToBuy.id); | ||
|
||
setIphonesToBuy(updatedInBasket); | ||
} else { | ||
const updatedInBasket = [...iphonesToBuy, selectedIphoneToBuy]; | ||
|
||
setIphonesToBuy(updatedInBasket); | ||
} | ||
} | ||
}; | ||
|
||
const svgLike = document.querySelector('.icon--path'); | ||
|
||
if (favorites.length > 0) { | ||
svgLike?.setAttribute('fill', '#EB5757'); | ||
svgLike?.removeAttribute('stroke'); | ||
svgLike?.removeAttribute('stroke-width'); | ||
} else { | ||
svgLike?.setAttribute('fill', 'white'); | ||
svgLike?.setAttribute('stroke', 'black'); | ||
svgLike?.setAttribute('stroke-width', '1'); | ||
} | ||
|
||
return ( | ||
<> | ||
<Header | ||
inputText={iphoneTitle} | ||
setInputText={handleSetInputText} | ||
favoritesCount={favorites.length} | ||
basketCount={iphonesToBuy.length} | ||
/> | ||
<main className="page"> | ||
<div className="container"> | ||
<Routes> | ||
<Route | ||
path="/" | ||
element={( | ||
<HomePage | ||
selectPhone={handleSelectPhone} | ||
selectedIphoneId={selectedIphoneId} | ||
selectPhoneToBuy={handleSelectPhoneToBuy} | ||
selectedIphoneIdToBuy={selectedIphoneIdToBuy} | ||
/> | ||
)} | ||
/> | ||
|
||
<Route path="/home" element={<Navigate to="/" replace />} /> | ||
<Route | ||
path="phones" | ||
element={( | ||
<PhonesPage | ||
selectedIphoneId={selectedIphoneId} | ||
selectPhone={handleSelectPhone} | ||
selectPhoneToBuy={handleSelectPhoneToBuy} | ||
selectedIphoneIdToBuy={selectedIphoneIdToBuy} | ||
iphoneTitle={iphoneTitle} | ||
/> | ||
)} | ||
/> | ||
<Route | ||
path="tablets" | ||
element={( | ||
<NotImplemented />)} | ||
/> | ||
<Route | ||
path="accessories" | ||
element={( | ||
<NotImplemented />)} | ||
/> | ||
|
||
<Route | ||
path="liked" | ||
element={( | ||
<Favorites | ||
favorites={favorites} | ||
selectedIphoneIdToBuy={selectedIphoneIdToBuy} | ||
selectPhoneToBuy={handleSelectPhoneToBuy} | ||
selectedIphoneId={selectedIphoneId} | ||
selectPhone={handleSelectPhone} | ||
/> | ||
)} | ||
/> | ||
|
||
<Route | ||
path="basket" | ||
element={( | ||
<Basket | ||
phonesToBuy={iphonesToBuy} | ||
removeIphone={handleRemoveIphone} | ||
/> | ||
)} | ||
/> | ||
|
||
<Route path="phones"> | ||
<Route | ||
index | ||
element={( | ||
<PhonesPage | ||
selectedIphoneId={selectedIphoneId} | ||
selectPhone={handleSelectPhone} | ||
selectPhoneToBuy={handleSelectPhoneToBuy} | ||
selectedIphoneIdToBuy={selectedIphoneIdToBuy} | ||
iphoneTitle={iphoneTitle} // + | ||
/> | ||
)} | ||
/> | ||
<Route | ||
path=":iphoneId" | ||
element={( | ||
<PhoneDescription | ||
selectedIphoneId={selectedIphoneId} | ||
selectPhone={handleSelectPhone} | ||
selectPhoneToBuy={handleSelectPhoneToBuy} | ||
selectedIphoneIdToBuy={selectedIphoneIdToBuy} | ||
/> | ||
)} | ||
/> | ||
</Route> | ||
|
||
</Routes> | ||
</div> | ||
</main> | ||
<Footer /> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
Oops, something went wrong.