-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
21 changed files
with
1,491 additions
and
90 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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@import "bootstrap"; | ||
|
||
|
||
header { | ||
img { | ||
max-width: 100px; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, {useState} from 'react'; | ||
import './App.scss'; | ||
|
||
import Header from './components/Header'; | ||
import { Home } from './pages/Home'; | ||
import { | ||
BrowserRouter as Router, | ||
Switch, | ||
Route, | ||
Link | ||
} from "react-router-dom"; | ||
|
||
|
||
import { Series } from './pages/Series'; | ||
|
||
export const LikedComicsContext = React.createContext({}); | ||
|
||
|
||
function App() { | ||
|
||
|
||
const [likedComics, setLikedComics] = useState([]) | ||
|
||
|
||
return ( | ||
<> | ||
|
||
|
||
<Router> | ||
|
||
<Header /> | ||
<div> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link to="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link to="/about">About</Link> | ||
</li> | ||
<li> | ||
<Link to="/users">Users</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
|
||
{/* A <Switch> looks through its children <Route>s and | ||
renders the first one that matches the current URL. */} | ||
<Switch> | ||
<Route path="/about"> | ||
test about | ||
</Route> | ||
<Route path="/users"> | ||
test | ||
</Route> | ||
<Route path="/series/:seriesId"> | ||
<LikedComicsContext.Provider value={[likedComics, setLikedComics]}> | ||
<Series /> | ||
</LikedComicsContext.Provider> | ||
|
||
</Route> | ||
<Route path="/"> | ||
<LikedComicsContext.Provider value={[likedComics, setLikedComics]}> | ||
<Home /> | ||
</LikedComicsContext.Provider> | ||
</Route> | ||
</Switch> | ||
</div> | ||
</Router> | ||
</> | ||
); | ||
|
||
} | ||
|
||
export default App; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, {FC}from 'react' | ||
import { LikedComicsContext } from '../App' | ||
|
||
interface Props { | ||
comic: string[] | ||
} | ||
|
||
export const ComicListing: FC<Props> = ({comic}) => { | ||
|
||
|
||
const [likedComics, setLikedComics] = React.useContext<object[]>(LikedComicsContext) | ||
|
||
function handleAdd() { | ||
|
||
// const items = [comic, ...likedComics]; | ||
|
||
// const uniqueLikedComics = [...new Set(items.map(a => a.id))] | ||
// .map(id => { | ||
// return items.find(a => a.id === id) | ||
// }) | ||
|
||
// setLikedComics(uniqueLikedComics) | ||
|
||
} | ||
|
||
function handleRemove(id:number) { | ||
|
||
const newList = likedComics.filter((item:any) => item.id !== id); | ||
|
||
setLikedComics(newList); | ||
} | ||
|
||
function toggleShow() { | ||
return likedComics.indexOf(comic) > -1 ? true : false; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="col-sm-12 col-md-4 col-lg-3 "> | ||
|
||
<div className="card p-2 text-center"> | ||
|
||
<img src={comic.thumbnail.path + "/portrait_xlarge.jpg"} alt="" /> | ||
<span className="my-2">{comic.title} </span> | ||
<button className={toggleShow() ? 'd-block btn btn-danger' : 'd-none' } onClick={() => handleRemove(comic.id)}>×</button> | ||
<button className={toggleShow() ? 'd-none' : 'd-block btn btn-primary'} onClick={handleAdd}>Like!</button> | ||
</div> | ||
</div> | ||
|
||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
import { ComicListing } from './ComicListing' | ||
|
||
interface Props { | ||
comics: any[] | ||
} | ||
|
||
export const ComicsListings: React.FC <Props> = ({comics}) => { | ||
return ( | ||
<div className="row"> | ||
{comics.map((comic) => { | ||
return <ComicListing key={comic.id} comic={comic}/> | ||
})} | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import logo from '../Marvel_Logo.svg' | ||
import { Link } from 'react-router-dom' | ||
|
||
export default function Header() { | ||
return ( | ||
<header className="p-3 bg-dark text-white"> | ||
|
||
<div className="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start"> | ||
|
||
<img src={logo} alt="" /> | ||
<ul className="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0"> | ||
<li><a href="/" className="nav-link px-2 text-secondary">Home</a></li> | ||
<Link to='/'>Home</Link> | ||
</ul> | ||
|
||
|
||
|
||
<div className="text-end"> | ||
<button type="button" className="btn btn-outline-light me-2">Login</button> | ||
<button type="button" className="btn btn-warning">Sign-up</button> | ||
</div> | ||
|
||
</div> | ||
</header> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
export default function LikedComics({likedComics}) { | ||
return ( | ||
<div> | ||
|
||
Liked Comics <br /> | ||
|
||
{likedComics.map((comic) => { | ||
return <div key={comic.id}> | ||
{comic.title} <br /> | ||
</div> | ||
})} | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router-dom'; | ||
|
||
export default function SeriesListing({ series }) { | ||
|
||
|
||
|
||
return ( | ||
<Link to={'/series/' + series.id} className="col-sm-12 col-md-4 col-lg-3 "> | ||
|
||
<div className="card p-2 text-center"> | ||
|
||
<img src={series.thumbnail.path + "/portrait_xlarge.jpg"} alt="" /> | ||
<span className="my-2">{series.title} </span> | ||
|
||
|
||
</div> | ||
</Link> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import SeriesListing from './SeriesListing' | ||
|
||
export default function SeriesListings({series}) { | ||
|
||
return ( | ||
<div className="row"> | ||
|
||
{series.map(item => ( | ||
<SeriesListing key={item.id} series={item} /> | ||
))} | ||
|
||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {useState, useEffect} from 'react' | ||
|
||
export const useComics = (seriesId) => { | ||
|
||
|
||
const [error, setError] = useState(null); | ||
const [isLoaded, setIsLoaded] = useState(false); | ||
const [items, setItems] = useState({}); | ||
|
||
|
||
useEffect(() => { | ||
|
||
setIsLoaded(false) | ||
|
||
fetch(`https://gateway.marvel.com:443/v1/public/series/${seriesId}/comics?apikey=f15ab39bdb06abd02556dd9ba822aecd`) | ||
.then(res => res.json()) | ||
.then( | ||
(result) => { | ||
setIsLoaded(true); | ||
setItems(result); | ||
|
||
}, | ||
// Note: it's important to handle errors here | ||
// instead of a catch() block so that we don't swallow | ||
// exceptions from actual bugs in components. | ||
(error) => { | ||
setIsLoaded(true); | ||
setError(error); | ||
} | ||
) | ||
}, [seriesId]) | ||
|
||
|
||
return { | ||
isLoaded, | ||
error, | ||
items | ||
}; | ||
|
||
} |
Oops, something went wrong.