Code Monkey home page Code Monkey logo

alcoholoverflowfrontend's Issues

Wine details in Anayltics could probably use the Wine Component

<Grid.Column>
<h3>Most Reviewed Wine</h3>
{mostReviewed[0] ?
<Grid>
<Grid.Row>
<Grid.Column>
<center><h4><u>{mostReviewed[0].name}</u></h4></center>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column>
<Link to={`/winelist/${mostReviewed[0].id}`}><Image src={`${mostReviewed[0].image}`} size='medium'/></Link>
</Grid.Column>
<Grid.Column>
<p>
<b><i>Varietal:</i></b> {mostReviewed[0].varietal}<br/>
<b><i>Region:</i></b> {mostReviewed[0].region}<br/>
<b><i>Winery:</i></b> {mostReviewed[0].winery}<br/>
<b><i>Type:</i></b> {mostReviewed[0].wine_type}<br/>
</p>
</Grid.Column>
</Grid.Row>
</Grid>
: null }
</Grid.Column>

In here you display both the most reviewed wine and the wine of the week. Couldn't you use the wine component and just pass in different wines here instead of having a few slightly different iterations on a wine display?

Multi line ternary is really hard to read

{toggle ?
<Card.Description>
Varietal: {wineDetail.varietal}<br/>
Vintage: {wineDetail.vintage}<br/>
Region: {wineDetail.region}<br/>
Winery: {wineDetail.winery}<br/>
Type: {wineDetail.wine_type}<br/>
<Button basic color='black' onClick={handleToggle}>Hide details</Button>
</Card.Description> :
<Button basic color='black' onClick={handleToggle}>Show more</Button>

Had to do some serious hunting to find the :. Just extract this to a function and use a normal if statement. Similar to this: https://facebook.github.io/react/docs/conditional-rendering.html

Don't modify the DOM directly and one component should not modify the DOM of another

document.getElementById('username').value = ""
document.getElementById('content').value = ""

Each component should be reusable. That means that having this component modify the DOM of a child component is not good. In addition to that, you shouldn't be modifying the DOM directly if you can avoid it due to the virtual DOM stuff. Instead reset state appropriately to clear out these variables.

Doing a fetch for the details of a wine from the backend unnecessarily

handleUpVotes = (id) => {
fetch(`http://localhost:3000/api/v1/wines/${id}`)
.then(res => res.json())
.then(data => {
fetch(`http://localhost:3000/api/v1/wines/${id}`, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
user_vote: data.user_vote + 1
})
})
.then(() => {
this.fetchData()
})
})

So you do a fetch to get the details of a wine given a specific id. Then grab that to increment/decrement the upvotes. There is no need to do that intial fetch to get the wine details. You've already done by fetching all wine data. Instead of just passing in the id into this function you can pass the entire wine object in. That way all you need to do is do the PUT request.

Finding Avg rating could have been done with map

for (let i=0; i < data.length; i++) {
if (data[i].reviews.length > 0) {
let newObj = {}
newObj.name = data[i].name
let total = data[i].reviews.reduce((value, review) => {
return review.user_rating + value }, 0)
newObj.average = total/data[i].reviews.length
newAry.push(newObj)
}

This line can be made a bit simpler using map instead of that for loop. Any time you feel yourself making a blank array, then putting stuff into it there is usually an iterator you can use

Repeated Code is dying to be converted into functions

.then((wines) => {
const white = wines.filter(wine => wine.wine_type === 'White Wine').sort((a, b) => {
return b.user_vote - a.user_vote
})
this.setState({wines: white})
})
} else if (name === 'red') {
fetch('http://localhost:3000/api/v1/wines')
.then(resp => resp.json())
.then((wines) => {
const red = wines.filter(wine => wine.wine_type === 'Red Wine').sort((a, b) => {
return b.user_vote - a.user_vote
})
this.setState({wines: red})

These two occurrences plus the one above that sorts them is dying to be put into a function! Also I assume you want them to be sorted no matter the filter?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.