Skip to content

Cleanup meta tags component #294

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions frontend/src/Components/AgencyData/AgencyData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import AgencyHeader from './AgencyHeader';
import Sidebar from '../Sidebar/Sidebar';
import ChartRoutes from '../Charts/ChartRoutes';
import { CompareAlertBox } from '../Elements/Alert/Alert';
import useOfficerId from '../../Hooks/useOfficerId';
import MetaTags from '../Charts/ChartSections/MetaTags';

function AgencyData(props) {
let { agencyId } = useParams();
const officerId = useOfficerId();

if (props.agencyId) {
agencyId = props.agencyId;
}
Expand All @@ -27,6 +31,9 @@ function AgencyData(props) {
const [chartsOpen, setChartsOpen] = useState(false);
const [chartState] = useDataset(agencyId, AGENCY_DETAILS);

const _getEntityReference = () =>
officerId ? `Officer ${officerId}` : chartState?.data[AGENCY_DETAILS]?.name;

useEffect(() => {
if (chartState.data[AGENCY_DETAILS]) setSidebarOpen(true);
}, [chartState.data[AGENCY_DETAILS]]);
Expand All @@ -41,6 +48,7 @@ function AgencyData(props) {

return (
<S.AgencyData data-testid="AgencyData" {...props}>
<MetaTags entityReference={_getEntityReference()} />
{props.showCompare && !props.agencyId && <CompareAlertBox />}
<AgencyHeader
agencyHeaderOpen={agencyHeaderOpen}
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/Arrest/Arrests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ArrestsStyled from './Arrests.styles';
import { YEARS_DEFAULT } from '../chartUtils';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// Children
Expand All @@ -28,7 +27,6 @@ function Arrests(props) {
const [togglePercentageOfStops, setTogglePercentageOfStops] = useState(true);
const [togglePercentageOfSearches, setTogglePercentageOfSearches] = useState(true);

const renderMetaTags = useMetaTags();
const [renderTableModal] = useTableModal();

useEffect(() => {
Expand All @@ -44,7 +42,6 @@ function Arrests(props) {

return (
<ArrestsStyled>
{renderMetaTags()}
{renderTableModal()}
<div style={{ display: 'flex', justifyContent: 'center' }}>
<DataSubsetPicker
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/Components/Charts/ChartSections/MetaTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import CopWatchLogoSolid from '../../../img/NC_copwatch_logo_solid.png';

// Deps
import { Helmet } from 'react-helmet';

export default function MetaTags({ entityReference }) {
const _getPageTitle = () => `Stop Data for ${entityReference}`;
const _getUrlForShare = () => window.location.href;

return (
<Helmet>
<title>{_getPageTitle()}</title>
<meta property="og:title" content={`Traffic Stop Data for ${_getPageTitle()}`} />
<meta
property="og:description"
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.`}
/>
<meta property="og:type" content="website" />
<meta property="og:url" content={_getUrlForShare()} />
<meta property="og:image" content={CopWatchLogoSolid} />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:alt" content="The NC CopWatch Logo" />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="300" />
</Helmet>
);
}
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/Contraband/Contraband.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as S from '../ChartSections/ChartsCommon.styled';
import { CONTRABAND_TYPES, STATIC_CONTRABAND_KEYS, YEARS_DEFAULT } from '../chartUtils';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// State
Expand Down Expand Up @@ -45,7 +44,6 @@ function Contraband(props) {

const [year, setYear] = useState(YEARS_DEFAULT);

const renderMetaTags = useMetaTags();
const [renderTableModal] = useTableModal();

const initContrabandData = {
Expand Down Expand Up @@ -523,7 +521,6 @@ function Contraband(props) {

return (
<ContrabandStyled>
{renderMetaTags()}
{renderTableModal()}
<details>
<summary style={{ display: 'flex', alignItems: 'center', gap: '10px', cursor: 'pointer' }}>
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/Components/Charts/Overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import {
} from '../chartUtils';
import * as slugs from '../../../Routes/slugs';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';

// Data
import useDataset, {
AGENCY_DETAILS,
Expand Down Expand Up @@ -63,8 +60,6 @@ function Overview(props) {
const [searchesData, setSearchesData] = useState(initChartData);
const [useOfForceData, setUseOfForceData] = useState(initChartData);

const renderMetaTags = useMetaTags();

const subjectObserving = () => {
if (officerId) {
return 'by this officer';
Expand Down Expand Up @@ -193,7 +188,6 @@ function Overview(props) {

return (
<OverviewStyled>
{renderMetaTags()}
<ChartHeader
chartTitle="Overview"
shareProps={{
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/SearchRate/SearchRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import useDataset, { AGENCY_DETAILS, LIKELIHOOD_OF_SEARCH } from '../../../Hooks

// Hooks
import useOfficerId from '../../../Hooks/useOfficerId';
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// Constants
Expand All @@ -31,7 +30,6 @@ function SearchRate(props) {
const initData = { labels: [], datasets: [], loading: true };
const [searchRateData, setSearchRateData] = useState(initData);

const renderMetaTags = useMetaTags();
const [renderTableModal, { openModal }] = useTableModal();

useEffect(() => {
Expand Down Expand Up @@ -96,7 +94,6 @@ function SearchRate(props) {

return (
<SearchRateStyled>
{renderMetaTags()}
{renderTableModal()}
<S.ChartSection>
<ChartHeader chartTitle="Likelihood of Search" handleViewData={handleViewData} />
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/Searches/Searches.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import useDataset, {
} from '../../../Hooks/useDataset';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// Elements
Expand Down Expand Up @@ -59,7 +58,6 @@ function Searches(props) {
};
const [searchCountData, setSearchCountData] = useState(initCountData);
const [searchCountType, setSearchCountType] = useState(0);
const renderMetaTags = useMetaTags();
const [renderTableModal, { openModal }] = useTableModal();

// Build Searches By Percentage
Expand Down Expand Up @@ -167,7 +165,6 @@ function Searches(props) {
return (
<SearchesStyled>
{/* Search Rate */}
{renderMetaTags()}
{renderTableModal()}
<S.ChartSection id="searches_by_percentage">
<ChartHeader
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/TrafficStops/TrafficStops.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import useDataset, { STOPS_BY_REASON, STOPS, AGENCY_DETAILS } from '../../../Hoo
import { P, WEIGHTS } from '../../../styles/StyledComponents/Typography';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// Children
Expand Down Expand Up @@ -105,7 +104,6 @@ function TrafficStops(props) {
],
});

const renderMetaTags = useMetaTags();
const [renderTableModal, { openModal }] = useTableModal();

const [stopPurposeGroupsData, setStopPurposeGroups] = useState({
Expand Down Expand Up @@ -700,7 +698,6 @@ function TrafficStops(props) {
return (
<TrafficStopsStyled>
{/* Traffic Stops by Percentage */}
{renderMetaTags()}
{renderTableModal()}
<S.ChartSection>
<ChartHeader
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/Components/Charts/UseOfForce/UseOfForce.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import useDataset, { AGENCY_DETAILS, USE_OF_FORCE } from '../../../Hooks/useDataset';

// Hooks
import useMetaTags from '../../../Hooks/useMetaTags';
import useTableModal from '../../../Hooks/useTableModal';

// Children
Expand Down Expand Up @@ -51,7 +50,6 @@ function UseOfForce(props) {
],
});

const renderMetaTags = useMetaTags();
const [renderTableModal, { openModal }] = useTableModal();

const subjectObserving = () => {
Expand Down Expand Up @@ -143,7 +141,6 @@ function UseOfForce(props) {

return (
<UseOfForceStyled>
{renderMetaTags()}
{renderTableModal()}
<S.ChartSection>
<ChartHeader chartTitle="Use of Force" handleViewData={handleViewData} />
Expand Down
48 changes: 0 additions & 48 deletions frontend/src/Hooks/useMetaTags.js

This file was deleted.

Loading