Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pedsm committed Dec 10, 2019
1 parent c127bbe commit cc568c2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 101 deletions.
Binary file modified .github/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 19 additions & 19 deletions components/crime.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React from 'react'

export default class Crime extends React.Component {
cleanDashCase(dashCase) {
const s = dashCase.split('-').join(' ')
return s[0].toUpperCase() + s.slice(1)
}
cleanDashCase(dashCase) {
const s = dashCase.split('-').join(' ')
return s[0].toUpperCase() + s.slice(1)
}

render() {
const { crime } = this.props
return (
<article className="media">
<div className="media-content">
<div className="content">
<p><strong>{this.cleanDashCase(crime.category)}</strong></p>
<p>{crime.location.street.name} <br />
{crime.outcome_status == null ? "🔎 No outcome avaliable" : "🧐" + crime.outcome_status.category}
</p>
</div>
</div>
</article>
)
}
render() {
const { crime } = this.props
return (
<article className="media">
<div className="media-content">
<div className="content">
<p><strong>{this.cleanDashCase(crime.category)}</strong></p>
<p>{crime.location.street.name} <br />
{crime.outcome_status == null ? "🔎 No outcome avaliable" : "🧐" + crime.outcome_status.category}
</p>
</div>
</div>
</article>
)
}
}
38 changes: 19 additions & 19 deletions components/stats.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, {Fragment} from 'react'
import React, { Fragment } from 'react'

export default class Level extends React.Component {
render() {
const { crimes
, postcode } = this.props
return (
<nav className="level">
<p className="level-item has-text-centered">
{(() => {
if (crimes.length == 0 && postcode == '') {
return 'Please enter your postcode'
} else if (crimes.length == 0) {
return (<>No records found for <strong>{postcode.toUpperCase()}</strong></>)
}
return (<><strong>{crimes.length}</strong>&nbsp;records found for <strong>{postcode.toUpperCase()}</strong></>)
})()}
</p>
</nav>
)
}
render() {
const { crimes
, postcode } = this.props
return (
<nav className="level">
<p className="level-item has-text-centered">
{(() => {
if (crimes.length == 0 && postcode == '') {
return 'Please enter your postcode'
} else if (crimes.length == 0) {
return (<span>No records found for <strong>{postcode.toUpperCase()}</strong></span>)
}
return (<span><strong>{crimes.length}</strong>&nbsp;records found for <strong>{postcode.toUpperCase()}</strong></span>)
})()}
</p>
</nav>
)
}
}
4 changes: 2 additions & 2 deletions pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class MyDocument extends Document {
return (
<Html>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
</Head>
<body className="custom_class">
<Main />
Expand Down
122 changes: 61 additions & 61 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,73 @@ import { fetchPostcodeInfo, fetchPoliceRecords } from '../utils/api'
const { log, error } = console

class Home extends React.Component {
constructor(props) {
super(props)
const { postcode, crimes } = props
this.state = {
postcode,
crimes
}
constructor(props) {
super(props)
const { postcode, crimes } = props
this.state = {
postcode,
crimes
}
}

static async getInitialProps({ query }) {
const postcode = query.postcode || ""
const postcodeDetails = await fetchPostcodeInfo(postcode)
if (postcodeDetails == null) {
return { postcode, crimes: [] }
}
const { latitude, longitude } = postcodeDetails
const crimes = await fetchPoliceRecords(latitude, longitude)
return {
postcode,
crimes
}
static async getInitialProps({ query }) {
const postcode = query.postcode || ""
const postcodeDetails = await fetchPostcodeInfo(postcode)
if (postcodeDetails == null) {
return { postcode, crimes: [] }
}

async handleInput(e) {
const postcode = e.target.value
this.setState((state) => ({ ...state, postcode }))
const postcodeDetails = await fetchPostcodeInfo(postcode)
if (postcodeDetails == null) {
this.setState((state) => ({ ...state, crimes: [] }))
return
} else {
const { latitude, longitude } = postcodeDetails
const crimes = await fetchPoliceRecords(latitude, longitude)
this.setState((state) => ({ ...state, crimes }))
}
const { latitude, longitude } = postcodeDetails
const crimes = await fetchPoliceRecords(latitude, longitude)
return {
postcode,
crimes
}
}

render() {
return (
<>
<section className="section">
<div className="container">
<h1 className="title">👮🏻‍♀Safe postcode</h1>
<form action="/" method="GET">
<input
name="postcode"
style={{ marginBottom: 10 }}
className="input"
onChange={this.handleInput.bind(this)}
placeholder="postcode"
value={this.state.postcode}
/>
</form>
<Stats crimes={this.state.crimes} postcode={this.state.postcode} />
{this.state.crimes.map((crime, i) => (
<Crime crime={crime} key={i} />
))}
</div>
</section>
<footer style={{ boxShadow: "0 100vh 0 100vh #fafafa"}} class="footer">
<div class="content has-text-centered">
<a href="https://github.com/pedsm/safePostcode"><strong>Safe Postcode</strong></a> built by <a href="https://github.com/pedsm">Pedro Mendonca</a> with <a href="https://nextjs.org/">Next.js</a>
</div>
</footer>
</>
)
async handleInput(e) {
const postcode = e.target.value
this.setState((state) => ({ ...state, postcode }))
const postcodeDetails = await fetchPostcodeInfo(postcode)
if (postcodeDetails == null) {
this.setState((state) => ({ ...state, crimes: [] }))
return
} else {
const { latitude, longitude } = postcodeDetails
const crimes = await fetchPoliceRecords(latitude, longitude)
this.setState((state) => ({ ...state, crimes }))
}
}

render() {
return (
<>
<section className="section">
<div className="container">
<h1 className="title">👮🏻‍♀Safe postcode</h1>
<form action="/" method="GET">
<input
name="postcode"
style={{ marginBottom: 10 }}
className="input"
onChange={this.handleInput.bind(this)}
placeholder="postcode"
value={this.state.postcode}
/>
</form>
<Stats crimes={this.state.crimes} postcode={this.state.postcode} />
{this.state.crimes.map((crime, i) => (
<Crime crime={crime} key={i} />
))}
</div>
</section>
<footer style={{ boxShadow: "0 100vh 0 100vh #fafafa" }} className="footer">
<div className="content has-text-centered">
<a href="https://github.com/pedsm/safePostcode"><strong>Safe Postcode</strong></a> built by <a href="https://github.com/pedsm">Pedro Mendonca</a> with <a href="https://nextjs.org/">Next.js</a>
</div>
</footer>
</>
)
}
}

export default Home

0 comments on commit cc568c2

Please sign in to comment.