-
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
17,683 additions
and
73 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 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
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 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 @@ | ||
import axios from 'axios'; | ||
|
||
export const fetchEvents = () => | ||
axios.get( | ||
"https://raw.githubusercontent.com/2020PB/police-brutality/data_build/all-locations.json" | ||
); |
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,88 @@ | ||
import React, { useState, createContext, useMemo } from "react"; | ||
import { fetchEvents } from "../actions"; | ||
import { Incident, Categories } from "../types"; | ||
import { cleanData, getCategoryCounts, compareByDate } from "../utils/data"; | ||
import _ from "lodash"; | ||
|
||
interface DataContextProps { | ||
incidents: Incident[]; | ||
totalCount: number; | ||
categoryCounts: Record<Categories, number>; | ||
category?: Categories; | ||
setCategory: (cat?: Categories) => void; | ||
cityState?: string; | ||
setCityState: (cityState?: string) => void; | ||
cityStateCounts: Record<string, number>; | ||
} | ||
|
||
const DataContext = createContext<DataContextProps>({ | ||
totalCount: 0, | ||
incidents: [], | ||
categoryCounts: {} as Record<Categories, number>, | ||
setCategory: () => {}, | ||
cityState: undefined, | ||
setCityState: () => {}, | ||
cityStateCounts: {}, | ||
}); | ||
|
||
export const useData = () => React.useContext(DataContext); | ||
|
||
export const DataContextProvider = ({ children }: any) => { | ||
const [incidents, setIncidents] = useState<Incident[]>([]); | ||
const [category, setCategory] = useState<Categories | undefined>(); | ||
const [cityState, setCityState] = useState<string>(); | ||
|
||
React.useEffect(() => { | ||
fetchEvents().then((res) => { | ||
const { | ||
data: { data }, | ||
} = res; | ||
const cleaned = cleanData(data); | ||
const cleanedSorted = cleaned.sort(compareByDate); | ||
setIncidents(cleanedSorted); | ||
}); | ||
}, []); | ||
|
||
const categoryCounts = useMemo(() => getCategoryCounts(incidents), [ | ||
incidents, | ||
]); | ||
|
||
const categoryFilteredIncidents = useMemo( | ||
() => | ||
category | ||
? incidents.filter((i) => i.categories.includes(category)) | ||
: incidents, | ||
[incidents, category] | ||
); | ||
|
||
const groupedByCityState = useMemo( | ||
() => _.groupBy(categoryFilteredIncidents, (i) => `${i.city}, ${i.state}`), | ||
[categoryFilteredIncidents] | ||
); | ||
|
||
const cityStateCounts = _.mapValues(groupedByCityState, (arr) => arr.length); | ||
|
||
const categoryCityStateFilteredIncidents = useMemo( | ||
() => | ||
cityState ? groupedByCityState[cityState] : categoryFilteredIncidents, | ||
[cityState, groupedByCityState, categoryFilteredIncidents] | ||
); | ||
|
||
const loading = !incidents.length; | ||
return ( | ||
<DataContext.Provider | ||
value={{ | ||
incidents: categoryCityStateFilteredIncidents, | ||
categoryCounts, | ||
category, | ||
setCategory, | ||
cityStateCounts, | ||
cityState, | ||
setCityState, | ||
totalCount: incidents.length, | ||
}} | ||
> | ||
{loading ? loading : children} | ||
</DataContext.Provider> | ||
); | ||
}; |
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,161 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
import { mobileRules } from "../constants/style"; | ||
import { useData } from "./data-context"; | ||
import { Categories } from "../types"; | ||
// import CrowdBannerVid from "../assets/drone_720_trimmed.mp4"; | ||
|
||
export const Filter = () => { | ||
const { | ||
categoryCounts, | ||
category, | ||
setCategory, | ||
cityStateCounts, | ||
cityState, | ||
setCityState, | ||
} = useData(); | ||
|
||
const categoryOptions = [ | ||
{ | ||
onClick: () => setCategory(), | ||
text: `Show all incidents`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.gas), | ||
text: `${categoryCounts[Categories.gas]} Chemical attacks`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.shooting_gun), | ||
text: `${categoryCounts[Categories.shooting_gun]} Shootings by firearms`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.shooting_rubber), | ||
text: `${ | ||
categoryCounts[Categories.shooting_rubber] | ||
} Shootings by rubber bullets/projectiles`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.assault), | ||
text: `${categoryCounts[Categories.assault]} Assaults`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.arrest), | ||
text: `${categoryCounts[Categories.arrest]} Unjustified arrests`, | ||
}, | ||
{ | ||
onClick: () => setCategory(Categories.other), | ||
text: `${categoryCounts[Categories.arrest]} other bullsh*t`, | ||
}, | ||
]; | ||
const cityStateOptions = Object.keys(cityStateCounts) | ||
.sort( | ||
(cityStateA, cityStateB) => | ||
cityStateCounts[cityStateB] - cityStateCounts[cityStateA] | ||
) | ||
.map((cityState) => ({ | ||
text: `${cityState}, (${cityStateCounts[cityState]})`, | ||
onClick: () => { | ||
setCityState(cityState); | ||
}, | ||
})); | ||
|
||
const allCityStateOptions = [ | ||
{ | ||
text: `ENTIRE U.S.`, | ||
onClick: () => setCityState(), | ||
}, | ||
...cityStateOptions, | ||
]; | ||
|
||
const categoryLabel = category?.toUpperCase() || "ALL INCIDENTS"; | ||
const cityStateLabel = cityState?.toUpperCase() || "ENTIRE U.S."; | ||
|
||
return ( | ||
<FilterText> | ||
SEE <Dropdown label={categoryLabel} options={categoryOptions} /> IN | ||
<Dropdown label={cityStateLabel} options={allCityStateOptions} /> BELOW | ||
</FilterText> | ||
); | ||
}; | ||
|
||
const FilterText = styled.div` | ||
font-size: 36px; | ||
font-weight: 700; | ||
padding: 16px 48px; | ||
display: flex; | ||
background: yellow; | ||
color: black; | ||
margin-bottom: 48px; | ||
display: flex; | ||
flex-flow: row; | ||
align-items: center; | ||
`; | ||
|
||
const DropdownWrapper = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const DropdownOptions = styled.div` | ||
position: absolute; | ||
top: 100%; | ||
left: 16px; | ||
background: black; | ||
color: white; | ||
font-weight: 500; | ||
border: 8px solid white; | ||
width: 500px; | ||
text-transform: uppercase; | ||
max-height: 80vh; | ||
overflow: auto; | ||
z-index: 1; | ||
`; | ||
|
||
const Option = styled.div` | ||
padding: 16px; | ||
border-bottom: 4px solid white; | ||
cursor: pointer; | ||
&:hover { | ||
background: rgba(255, 0, 0, 0.3); | ||
} | ||
`; | ||
|
||
const DropdownToggle = styled.div` | ||
border: 8px solid black; | ||
padding: 24px; | ||
margin: 0 24px; | ||
cursor: pointer; | ||
`; | ||
|
||
interface DropdownProps { | ||
label: string; | ||
options: { text: string; onClick?: any }[]; | ||
} | ||
|
||
const Dropdown = ({ label, options }: DropdownProps) => { | ||
const [open, setOpen] = useState<boolean>(false); | ||
return ( | ||
<DropdownWrapper> | ||
<DropdownToggle | ||
onClick={() => { | ||
setOpen(!open); | ||
}} | ||
> | ||
{label} | ||
</DropdownToggle> | ||
{open && ( | ||
<DropdownOptions> | ||
{options.map((option: any) => ( | ||
<Option | ||
onClick={() => { | ||
setOpen(false); | ||
option.onClick && option.onClick(); | ||
}} | ||
> | ||
{option.text} | ||
</Option> | ||
))} | ||
</DropdownOptions> | ||
)} | ||
</DropdownWrapper> | ||
); | ||
}; |
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,12 @@ | ||
import { createGlobalStyle } from "styled-components"; | ||
|
||
export const GlobalStyle = createGlobalStyle` | ||
body { | ||
background: black; | ||
color: white; | ||
font-family: 'Rubik', sans-serif; | ||
} | ||
.EmbeddedTweet { | ||
border: none; | ||
} | ||
`; |
Oops, something went wrong.