Skip to content

Commit 000b159

Browse files
Afani97simonkagwi
andauthored
consolidate meta tags to the agency data component (#294)
Co-authored-by: Simon Kagwi <[email protected]>
1 parent a99c7c7 commit 000b159

File tree

10 files changed

+37
-72
lines changed

10 files changed

+37
-72
lines changed

frontend/src/Components/AgencyData/AgencyData.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ import ChartRoutes from '../Charts/ChartRoutes';
1717
import { CompareAlertBox } from '../Elements/Alert/Alert';
1818
import { YEARS_DEFAULT } from '../Charts/chartUtils';
1919
import axios from '../../Services/Axios';
20+
import useOfficerId from '../../Hooks/useOfficerId';
21+
import MetaTags from '../Charts/ChartSections/MetaTags';
2022

2123
function AgencyData(props) {
2224
let { agencyId } = useParams();
25+
const officerId = useOfficerId();
26+
2327
if (props.agencyId) {
2428
agencyId = props.agencyId;
2529
}
@@ -33,6 +37,9 @@ function AgencyData(props) {
3337
const [year, setYear] = useState(YEARS_DEFAULT);
3438
const [yearIdx, setYearIdx] = useState(null);
3539

40+
const _getEntityReference = () =>
41+
officerId ? `Officer ${officerId}` : chartState?.data[AGENCY_DETAILS]?.name;
42+
3643
useEffect(() => {
3744
if (chartState.data[AGENCY_DETAILS]) setSidebarOpen(true);
3845
}, [chartState.data[AGENCY_DETAILS]]);
@@ -59,6 +66,7 @@ function AgencyData(props) {
5966

6067
return (
6168
<S.AgencyData data-testid="AgencyData" {...props}>
69+
<MetaTags entityReference={_getEntityReference()} />
6270
{props.showCompare && !props.agencyId && <CompareAlertBox />}
6371
<AgencyHeader
6472
agencyHeaderOpen={agencyHeaderOpen}

frontend/src/Components/Charts/Arrest/Arrests.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
22
import ArrestsStyled from './Arrests.styles';
33

44
// Hooks
5-
import useMetaTags from '../../../Hooks/useMetaTags';
65
import useTableModal from '../../../Hooks/useTableModal';
76

87
// Children
@@ -22,7 +21,6 @@ function Arrests(props) {
2221
const [togglePercentageOfStops, setTogglePercentageOfStops] = useState(true);
2322
const [togglePercentageOfSearches, setTogglePercentageOfSearches] = useState(true);
2423

25-
const renderMetaTags = useMetaTags();
2624
const [renderTableModal] = useTableModal();
2725

2826
useEffect(() => {
@@ -59,7 +57,6 @@ function Arrests(props) {
5957

6058
return (
6159
<ArrestsStyled>
62-
{renderMetaTags()}
6360
{renderTableModal()}
6461
<PercentageOfStops {...props} year={year} />
6562
<PercentageOfSearches {...props} year={year} />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
import CopWatchLogoSolid from '../../../img/NC_copwatch_logo_solid.png';
4+
5+
// Deps
6+
import { Helmet } from 'react-helmet';
7+
8+
export default function MetaTags({ entityReference }) {
9+
const _getPageTitle = () => `Stop Data for ${entityReference}`;
10+
const _getUrlForShare = () => window.location.href;
11+
12+
return (
13+
<Helmet>
14+
<title>{_getPageTitle()}</title>
15+
<meta property="og:title" content={`Traffic Stop Data for ${_getPageTitle()}`} />
16+
<meta
17+
property="og:description"
18+
content={`NC Copwatch collects traffic stop data reported by policing agencies across the state. ${entityReference} has traffic stop data available for analysis at nccopwatch.org.`}
19+
/>
20+
<meta property="og:type" content="website" />
21+
<meta property="og:url" content={_getUrlForShare()} />
22+
<meta property="og:image" content={CopWatchLogoSolid} />
23+
<meta property="og:image:type" content="image/png" />
24+
<meta property="og:image:alt" content="The NC CopWatch Logo" />
25+
<meta property="og:image:width" content="600" />
26+
<meta property="og:image:height" content="300" />
27+
</Helmet>
28+
);
29+
}

frontend/src/Components/Charts/Contraband/Contraband.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '../chartUtils';
1515

1616
// Hooks
17-
import useMetaTags from '../../../Hooks/useMetaTags';
1817
import useTableModal from '../../../Hooks/useTableModal';
1918

2019
// State
@@ -48,7 +47,6 @@ function Contraband(props) {
4847
}
4948
}, []);
5049

51-
const renderMetaTags = useMetaTags();
5250
const [renderTableModal] = useTableModal();
5351

5452
const initContrabandData = {
@@ -537,7 +535,6 @@ function Contraband(props) {
537535

538536
return (
539537
<ContrabandStyled>
540-
{renderMetaTags()}
541538
{renderTableModal()}
542539
<details>
543540
<summary style={{ display: 'flex', alignItems: 'center', gap: '10px', cursor: 'pointer' }}>

frontend/src/Components/Charts/Overview/Overview.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import {
1515
} from '../chartUtils';
1616
import * as slugs from '../../../Routes/slugs';
1717

18-
// Hooks
19-
import useMetaTags from '../../../Hooks/useMetaTags';
20-
2118
// Data
2219
import useDataset, {
2320
AGENCY_DETAILS,
@@ -59,8 +56,6 @@ function Overview(props) {
5956
const [searchesData, setSearchesData] = useState(initChartData);
6057
const [useOfForceData, setUseOfForceData] = useState(initChartData);
6158

62-
const renderMetaTags = useMetaTags();
63-
6459
const subjectObserving = () => {
6560
if (officerId) {
6661
return 'by this officer';
@@ -182,7 +177,6 @@ function Overview(props) {
182177

183178
return (
184179
<OverviewStyled>
185-
{renderMetaTags()}
186180
<ChartHeader
187181
chartTitle="Overview"
188182
shareProps={{

frontend/src/Components/Charts/SearchRate/SearchRate.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import useDataset, {
1111

1212
// Hooks
1313
import useOfficerId from '../../../Hooks/useOfficerId';
14-
import useMetaTags from '../../../Hooks/useMetaTags';
1514
import useTableModal from '../../../Hooks/useTableModal';
1615

1716
// Constants
@@ -43,7 +42,6 @@ function SearchRate(props) {
4342
const [stopRateData, setStopRateData] = useState(initStopRateData);
4443
const [noACSData, setNoACSData] = useState(false);
4544

46-
const renderMetaTags = useMetaTags();
4745
const [renderTableModal, { openModal }] = useTableModal();
4846

4947
// eslint-disable-next-line no-unused-vars
@@ -198,7 +196,6 @@ function SearchRate(props) {
198196

199197
return (
200198
<SearchRateStyled>
201-
{renderMetaTags()}
202199
{renderTableModal()}
203200
<S.ChartSection>
204201
<ChartHeader

frontend/src/Components/Charts/Searches/Searches.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import useDataset, {
1414
} from '../../../Hooks/useDataset';
1515

1616
// Hooks
17-
import useMetaTags from '../../../Hooks/useMetaTags';
1817
import useTableModal from '../../../Hooks/useTableModal';
1918

2019
// Elements
@@ -59,7 +58,6 @@ function Searches(props) {
5958
};
6059
const [searchCountData, setSearchCountData] = useState(initCountData);
6160
const [searchCountType, setSearchCountType] = useState(0);
62-
const renderMetaTags = useMetaTags();
6361
const [renderTableModal, { openModal }] = useTableModal();
6462

6563
// Build Searches By Percentage
@@ -167,7 +165,6 @@ function Searches(props) {
167165
return (
168166
<SearchesStyled>
169167
{/* Search Rate */}
170-
{renderMetaTags()}
171168
{renderTableModal()}
172169
<S.ChartSection id="searches_by_percentage">
173170
<ChartHeader

frontend/src/Components/Charts/TrafficStops/TrafficStops.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import useDataset, { STOPS_BY_REASON, STOPS, AGENCY_DETAILS } from '../../../Hoo
3838
import { P, WEIGHTS } from '../../../styles/StyledComponents/Typography';
3939

4040
// Hooks
41-
import useMetaTags from '../../../Hooks/useMetaTags';
4241
import useTableModal from '../../../Hooks/useTableModal';
4342

4443
// Children
@@ -112,7 +111,6 @@ function TrafficStops(props) {
112111
],
113112
});
114113

115-
const renderMetaTags = useMetaTags();
116114
const [renderTableModal, { openModal }] = useTableModal();
117115

118116
const [stopPurposeGroupsData, setStopPurposeGroups] = useState({
@@ -709,7 +707,6 @@ function TrafficStops(props) {
709707
return (
710708
<TrafficStopsStyled>
711709
{/* Traffic Stops by Percentage */}
712-
{renderMetaTags()}
713710
{renderTableModal()}
714711
<div style={{ display: 'flex', justifyContent: 'center' }}>
715712
<MonthRangePicker

frontend/src/Components/Charts/UseOfForce/UseOfForce.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
import useDataset, { AGENCY_DETAILS, USE_OF_FORCE } from '../../../Hooks/useDataset';
1717

1818
// Hooks
19-
import useMetaTags from '../../../Hooks/useMetaTags';
2019
import useTableModal from '../../../Hooks/useTableModal';
2120

2221
// Children
@@ -50,7 +49,6 @@ function UseOfForce(props) {
5049
],
5150
});
5251

53-
const renderMetaTags = useMetaTags();
5452
const [renderTableModal, { openModal }] = useTableModal();
5553

5654
const subjectObserving = () => {
@@ -136,7 +134,6 @@ function UseOfForce(props) {
136134

137135
return (
138136
<UseOfForceStyled>
139-
{renderMetaTags()}
140137
{renderTableModal()}
141138
<S.ChartSection>
142139
<ChartHeader chartTitle="Use of Force" handleViewData={handleViewData} />

frontend/src/Hooks/useMetaTags.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)