-
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.
Merge pull request #9 from jeremykirc/add-react-router
Add react router
- Loading branch information
Showing
84 changed files
with
357 additions
and
116 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -39,3 +39,4 @@ yarn-debug.log* | |
*.swo | ||
/log | ||
/tmp | ||
.DS_store |
Binary file not shown.
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,44 @@ | ||
|
||
module Api | ||
module V1 | ||
class ImagesController < ParentController | ||
# GET /images/test_grid_data | ||
# Return test image grid data. | ||
def test_grid_data | ||
render json: test_image_grid_data | ||
end | ||
|
||
private | ||
|
||
def test_image_grid_data | ||
[ | ||
{ | ||
title: 'Egg on Waffle', | ||
description: 'Test1', | ||
url: 'EggOnWaffle.jpg' | ||
}, | ||
{ | ||
title: 'Roasted Carrots with Lentils', | ||
description: 'Test2', | ||
url: 'RoastedCarrotsAndLentils.jpg' | ||
}, | ||
{ | ||
title: 'Mole Taco', | ||
description: 'Test3', | ||
url: 'MoleTaco.jpg' | ||
}, | ||
{ | ||
title: 'Burrata and Orange', | ||
description: 'Test4', | ||
url: 'OttelenghiBurrataOrange.jpg' | ||
}, | ||
{ | ||
title: 'Apricot Lavender Cake', | ||
description: 'Test5', | ||
url: 'ApricotLavenderCake.jpg' | ||
} | ||
] | ||
end | ||
end | ||
end | ||
end |
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,6 @@ | ||
module Api | ||
module V1 | ||
class ParentController < ApplicationController | ||
end | ||
end | ||
end |
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,3 +1,3 @@ | ||
class StaticPagesController < ApplicationController | ||
def home; end | ||
def index; end | ||
end |
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,16 +1,2 @@ | ||
module ApplicationHelper | ||
def image_grid_data | ||
[ | ||
{ | ||
title: 'Pacific Ocean', | ||
description: 'A big blue ocean', | ||
url: asset_pack_path('media/images/Ocean.jpg') | ||
}, | ||
{ | ||
title: 'Santa Barbara Mission', | ||
description: 'The mission on a sunny afternoon', | ||
url: asset_pack_path('media/images/SbMission.jpg') | ||
} | ||
] | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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
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 @@ | ||
<%= react_component('AppRouter') %> |
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,23 @@ | ||
import React from 'react'; | ||
import { Container } from 'react-bootstrap'; | ||
import { BrowserRouter, Route, Switch } from 'react-router-dom'; | ||
|
||
import Header from '../components/Header'; | ||
import Home from '../components/Home'; | ||
import ImageUpload from '../components/ImageUpload'; | ||
import NotFound from '../components/NotFound'; | ||
|
||
const AppRouter = () => ( | ||
<BrowserRouter> | ||
<Header /> | ||
<Container> | ||
<Switch> | ||
<Route path='/' component={Home} exact /> | ||
<Route path='/images/new' component={ImageUpload} /> | ||
<Route component={NotFound} /> | ||
</Switch> | ||
</Container> | ||
</BrowserRouter> | ||
); | ||
|
||
export default AppRouter; |
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,37 @@ | ||
import logo from 'images/text-with-whisk-color.png'; | ||
import React from 'react'; | ||
import { Container } from 'react-bootstrap'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
const Header = () => ( | ||
<nav className='navbar navbar-expand-sm sticky-top navbar-light'> | ||
<Container> | ||
<div id='nav-logo'> | ||
<NavLink to='/' exact> | ||
<img src={logo} /> | ||
</NavLink> | ||
</div> | ||
<button className='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarNavDropdown' aria-controls='navbarNavDropdown' aria-expanded='false' aria-label='Toggle navigation'> | ||
<span className='navbar-toggler-icon'></span> | ||
</button> | ||
<div className='collapse navbar-collapse' id='navbarNavDropdown'> | ||
<ul className='navbar-nav'> | ||
<li className='nav-item dropdown'> | ||
<a className='nav-link dropdown-toggle' href='/#' id='navbarDropdownMenuLink' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'> | ||
Dropdown | ||
</a> | ||
<div className='dropdown-menu' aria-labelledby='navbarDropdownMenuLink'> | ||
<NavLink to='/' exact className='dropdown-item'>Home</NavLink> | ||
<NavLink to='/images/new' className='dropdown-item'>Upload Image</NavLink> | ||
</div> | ||
</li> | ||
<li className='nav-item'> | ||
<NavLink to='/sign_in' className='nav-link'>Sign in</NavLink> | ||
</li> | ||
</ul> | ||
</div> | ||
</Container> | ||
</nav> | ||
); | ||
|
||
export default 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,11 @@ | ||
import React from 'react'; | ||
|
||
import ImageGrid from './ImageGrid'; | ||
|
||
const Home = () => { | ||
return ( | ||
<ImageGrid /> | ||
); | ||
}; | ||
|
||
export default Home; |
File renamed without changes.
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,50 @@ | ||
import axios from 'axios'; | ||
import React, { useEffect,useState } from 'react'; | ||
import { Container, Row } from 'react-bootstrap'; | ||
|
||
import ImageBox from './ImageBox'; | ||
import ImageModal from './ImageModal'; | ||
|
||
const ImageGrid = () => { | ||
const [isModalShown, setIsModalShown] = useState(false); | ||
const [imageInfo, setImageInfo] = useState({ title: '', description: '', url: '' }); | ||
const [imageBoxes, setImageBoxes] = useState(); | ||
|
||
useEffect(() => { | ||
axios.get('/api/v1/images/test_grid_data') | ||
.then(response => { | ||
setImageBoxes(generateImageBoxes(response.data)); | ||
}) | ||
.catch(error => console.error(error)); | ||
}, []); | ||
|
||
const showModal = (imageData) => { | ||
setImageInfo(imageData); | ||
setIsModalShown(true); | ||
}; | ||
|
||
const hideModal = () => setIsModalShown(false); | ||
|
||
const generateImageBoxes = (imageGridData) => { | ||
return imageGridData.map((imageData, i) => ( | ||
<ImageBox | ||
key={i} | ||
imageInfo={imageData} | ||
handleImageBoxClick={showModal} | ||
/> | ||
)); | ||
}; | ||
|
||
return ( | ||
<Container className='image-grid'> | ||
<Row>{imageBoxes}</Row> | ||
<ImageModal | ||
show={isModalShown} | ||
imageInfo={imageInfo} | ||
handleClose={hideModal} | ||
/> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ImageGrid; |
File renamed without changes.
File renamed without changes.
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,10 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const NotFoundPage = () => ( | ||
<div> | ||
Page Not Found - <Link to='/'>Return to home</Link> | ||
</div> | ||
); | ||
|
||
export default NotFoundPage; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
|
||
.container { | ||
max-width: 98% !important; | ||
padding: 0px 15px !important; | ||
} | ||
|
||
body { | ||
|
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.