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

water - Li & Marj #8

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
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
400e532
initial commit
Schmarj3 Jan 19, 2021
7a8b23a
added components folder, created component files - no code yet
Schmarj3 Jan 19, 2021
ed4368f
added basic code for video component
Schmarj3 Jan 19, 2021
2a3e761
added basic code for serch component
Schmarj3 Jan 19, 2021
e8e0686
added basic code for library component
Schmarj3 Jan 19, 2021
d80a07c
added basic code for customer list component
Schmarj3 Jan 19, 2021
2bd66f1
added basic code for customer component
Schmarj3 Jan 19, 2021
3ada060
added css files for components and navigation routing
Schmarj3 Jan 19, 2021
fa73671
added code to Homepage component and solved error
Schmarj3 Jan 19, 2021
7c1c506
Merge pull request #1 from Schmarj3/components
Schmarj3 Jan 19, 2021
0215536
added base url
nerdyistrendy Jan 20, 2021
db8c759
added base url
nerdyistrendy Jan 20, 2021
db21a61
Merge branch 'components' of https://github.com/Schmarj3/video-store-…
nerdyistrendy Jan 20, 2021
03cfd15
Delete .env
nerdyistrendy Jan 20, 2021
b2f18b8
added customers state
nerdyistrendy Jan 20, 2021
7478253
Merge branch 'master' of https://github.com/Schmarj3/video-store-cons…
nerdyistrendy Jan 20, 2021
4c7c49c
added state and api call for video library list
Schmarj3 Jan 20, 2021
7cb1e07
customers showing
nerdyistrendy Jan 20, 2021
9d71bbb
completed video and library components, selected video logic, styling
Schmarj3 Jan 20, 2021
829f975
removed component from react import statement
Schmarj3 Jan 20, 2021
14d6038
select customer working
nerdyistrendy Jan 20, 2021
8aaf3c1
added propTypes
nerdyistrendy Jan 20, 2021
cdef28c
added styling to error message, not sure if it will work
Schmarj3 Jan 20, 2021
d0bded2
Merge pull request #2 from Schmarj3/library-video-components
Schmarj3 Jan 20, 2021
bec70a0
Merge branch 'master' into customer
nerdyistrendy Jan 20, 2021
d46af47
Merge pull request #3 from Schmarj3/customer
nerdyistrendy Jan 20, 2021
850e9e9
search box
nerdyistrendy Jan 20, 2021
3208d20
edited seleted customer ternary
nerdyistrendy Jan 20, 2021
a58149d
removed requred customerid
nerdyistrendy Jan 20, 2021
67bfba7
removed requred customerid
nerdyistrendy Jan 20, 2021
8f7ff37
changed selectedVideo logic to set state to object, added new selecte…
Schmarj3 Jan 20, 2021
9385913
fixed styling, added logic for select component display
Schmarj3 Jan 20, 2021
1e0ab95
search result showing
nerdyistrendy Jan 20, 2021
7f69ccb
search result formatting
nerdyistrendy Jan 20, 2021
4599a08
add to library button
nerdyistrendy Jan 20, 2021
6d965f8
added button disable logic and some styling
Schmarj3 Jan 20, 2021
6cd821f
added styling to customers page
Schmarj3 Jan 21, 2021
8461a19
add video working
nerdyistrendy Jan 21, 2021
60c229f
only add unique video
nerdyistrendy Jan 21, 2021
7731228
added select logic to unselect already selected item and fixed alerts
Schmarj3 Jan 21, 2021
750913e
Merge pull request #4 from Schmarj3/customer-list-styling
Schmarj3 Jan 21, 2021
9a25e13
Merge branch 'master' into search
nerdyistrendy Jan 21, 2021
b16cbc5
Merge pull request #5 from Schmarj3/search
nerdyistrendy Jan 21, 2021
60f2b4f
cleaning up the code
nerdyistrendy Jan 21, 2021
57c07ef
searchbar css
nerdyistrendy Jan 21, 2021
51901cc
added homepage logic and styling
Schmarj3 Jan 21, 2021
37667bc
Merge branch 'master' of https://github.com/Schmarj3/video-store-cons…
nerdyistrendy Jan 21, 2021
9e6af32
Merge pull request #6 from Schmarj3/homepage
Schmarj3 Jan 21, 2021
cf16f09
fixed p tag styling
Schmarj3 Jan 21, 2021
5a70f69
added propTypes
nerdyistrendy Jan 21, 2021
ac811de
added emojis to homepage and changed wording
Schmarj3 Jan 22, 2021
446f9e6
added emojis and changed text
Schmarj3 Jan 22, 2021
132cbc6
made heading all caps for consistency
Schmarj3 Jan 22, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/build

# misc
.env
.DS_Store
.env.local
.env.development.local
Expand Down
13,597 changes: 118 additions & 13,479 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
"version": "0.1.1",
"private": true,
"dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"react": "^17.0.1",
"react-bootstrap": "^1.4.3",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1"
},
"devDependencies": {
"gh-pages": "^3.1.0",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.3",
"@testing-library/user-event": "^12.6.0"
"@testing-library/user-event": "^12.6.0",
"gh-pages": "^3.1.0"
},
"scripts": {
"start": "PORT=3001 react-scripts start",
Expand Down
76 changes: 76 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* Original code */
.App {
text-align: center;
}
Expand Down Expand Up @@ -26,3 +27,78 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}


/* New code */
main {
display: flex;
flex-wrap: wrap;
margin-left: 160px; /* Same as the width of the sidebar */
justify-content: center;
padding: 0px 10px;
}

nav li {
list-style: none;
}

nav ul {
margin: 0;
padding: 0;
}

.sidenav {
height: 100%; /* Full-height: remove this if you want "auto" height */
width: 160px; /* Set the width of the sidebar */
position: fixed; /* Fixed Sidebar (stay in place on scroll) */
z-index: 1; /* Stay on top */
top: 0; /* Stay at the top */
left: 0;
background-color: #111; /* Black */
overflow-x: hidden; /* Disable horizontal scroll */
padding-top: 20px;
z-index: 2;
}

/* The navigation menu links */
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}

/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
color: #f1f1f1;
}

/* On smaller screens, where height is less than 450px, change the style of the sidebar (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}

.selected-container {
position: fixed;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
background-color: white;
width: 100%;
height: 100px;
margin-bottom: 10px;
z-index: 1;
}

.lower {
margin-top: 120px;
}

.hide {
display: none;
}

.error-msg {
background-color: rgba(139, 0, 0, 0.6);
font-weight: bold;
}
209 changes: 195 additions & 14 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,202 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from 'react-router-dom';
import Homepage from './components/Homepage'
import Search from './components/Search'
import Library from './components/Library'
import CustomerList from './components/CustomerList'
import './App.css';
import CheckoutReturn from './components/CheckoutReturn';

class App extends Component {
render() {
const API_URL_BASE = 'http://localhost:3000/'

const App = () => {

const [errorMessage, setErrorMessage] = useState(null);
const [customerList, setCustomerList] = useState([]);
const [currentCustomer, setCurrentCustomer] = useState(null);
const [videoList, setVideoList] = useState([]);
const [selectedVideo, setSelectedVideo] = useState(null)
const [searchResult, setSearchResult] = useState([]);
const [overdue, setOverdue] = useState([])


useEffect(() => {
axios.get(`${API_URL_BASE}customers`)
.then((response) => {
const apiCustomerList = response.data;
setCustomerList(apiCustomerList);
})
.catch((error) => {
setErrorMessage(error.message);
});
}, []);

useEffect(() => {
axios.get(`${API_URL_BASE}videos`)
.then((response) => {
const apiVideoList = response.data;
setVideoList(apiVideoList);
})
.catch((error) => {
setErrorMessage(error.message);
});
}, []);

useEffect(() => {
axios.get(`${API_URL_BASE}rentals/overdue`)
.then((response) => {
const overdueList = response.data
setOverdue(overdueList)
})
.catch((error) => {
setErrorMessage(error.message);
});
}, []);

const selectedCustomer = (id) => {
if (currentCustomer && id === currentCustomer.id) {
setCurrentCustomer(null)
} else {
const customer = customerList.find((customer) => {
return customer.id === id;
});
setCurrentCustomer(customer);
}
};

const selectVideo = (id) => {
if (selectedVideo && id === selectedVideo.id) {
setSelectedVideo(null)
} else {
const video = videoList.find((video) => {
return video.id === id;
});
setSelectedVideo(video)
}
};


const searchVideo = (video) => {
axios.get(`${API_URL_BASE}videos?query=${video}`)
.then((response) => {
const results = response.data;
setSearchResult(results);
})
.catch((error) => {
setErrorMessage(error.message);
});
};

const addVideo = (video) => {
axios.post(API_URL_BASE+'videos', video)
.then( response => {
const newVideoList = [...videoList, response.data]
console.log(newVideoList)

setVideoList(newVideoList)
})
.catch( error => {
const errors = error.response.data.errors
setErrorMessage(errors)
})
};


const checkoutVideo = (params) => {
axios.post(`${API_URL_BASE}/rentals/${selectedVideo.title}/check-out`, params)
.then((response) => {
alert(`Successfully checked out ${selectedVideo.title}`)
})
.catch((error) => {
alert(`Sorry, we were unable to check out ${selectedVideo.title}`)
setErrorMessage(error.message);
});
setSelectedVideo(null)
setCurrentCustomer(null)
}

const returnVideo = (params) => {
axios.post(`${API_URL_BASE}/rentals/${selectedVideo.title}/return`, params)
.then((response) => {
alert(`Successfully returned ${selectedVideo.title}`)
})
.catch((error) => {
alert(`Sorry, we were unable to return ${selectedVideo.title}`)
setErrorMessage(error.message);
});
setSelectedVideo(null)
setCurrentCustomer(null)
}

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<Router>
<div>
<nav className='sidenav'>
<ul>
<li>
<Link to='/'>Home</Link>
</li>
<li>
<Link to='/search'>Search</Link>
</li>
<li>
<Link to='/library'>Library</Link>
</li>
<li>
<Link to='/customers'>Customers</Link>
</li>
</ul>
</nav>
<main>
{errorMessage ? <div><h2 className="error-msg">{errorMessage}</h2></div> : ''}

<section className={`selected-container ${currentCustomer || selectedVideo ? '' : 'hide'}`}>
<CheckoutReturn
currentCustomer={currentCustomer}
selectedVideo={selectedVideo}
onCheckoutVideo={checkoutVideo}
onReturnVideo={returnVideo}
/>
</section>
<section className={`${currentCustomer || selectedVideo ? 'lower' : ''}`}>
<Switch>
<Route path='/search'>
<Search
searchVideoCallback={searchVideo}
searchResult={searchResult}
addVideoCallback={addVideo}
videos={videoList}/>
</Route>
<Route path='/library'>
<Library
videos={videoList}
selectedVideo={selectedVideo}
onSelectVideoCallback= {selectVideo}
/>
</Route>
<Route path='/customers'>
<CustomerList
customers={customerList}
selectCustomerCallback={selectedCustomer}
currentCustomer={currentCustomer}/>
</Route>
<Route path='/'>
<Homepage overdue={overdue}/>
</Route>
</Switch>
</section>

</main>
</div>
</Router>
);
}

}

export default App;
export default App;
24 changes: 24 additions & 0 deletions src/components/CheckoutReturn.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.main-container {
display: flex;
align-items: center;
justify-content: space-evenly;
}

.movie {
display: flex;
align-items: center;
}
.thumbnail {
height: 80px;
margin: 0 5px;
}

.hide {
visibility: hidden;
}

.checkout-video, .return-video {
font-size: 20px;
border-radius: 12px;
padding: 10px 24px;
}
Loading