Skip to content
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

566 amenity marker active states #571

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Binary file added assets/images/amenityIconFirstAidActive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/amenityIconToiletActive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/screens/ParadeMapScreen/AmenityMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { Marker } from "react-native-maps";
import type { Amenity } from "../../data/amenity";
import type { Coordinates } from "../../constants/parade-coordinates";
import amenityIconFirstAid from "../../../assets/images/amenityIconFirstAid.png";
import amenityIconFirstAidActive from "../../../assets/images/amenityIconFirstAidActive.png";
import amenityIconToilet from "../../../assets/images/amenityIconToilet.png";
import amenityIconToiletActive from "../../../assets/images/amenityIconToiletActive.png";

type Props = {
amenities: Amenity[],
activeMarker: ?string,
handleMarkerPress: (markerID: string) => void,
markerSelect: (event: { nativeEvent: { coordinate: Coordinates } }) => void
};

Expand All @@ -16,22 +20,36 @@ const iconMap = {
"First Aid": amenityIconFirstAid
};

const AmenityMarkers = ({ amenities, markerSelect }: Props) => {
const activeIconMap = {
Toilet: amenityIconToiletActive,
"First Aid": amenityIconFirstAidActive
};

const AmenityMarkers = ({
amenities,
activeMarker,
handleMarkerPress,
markerSelect
}: Props) => {
if (amenities.length === 0) {
return null;
}

return (
<Fragment>
{amenities.map(amenity => (
<Marker
pointerEvents="none"
coordinate={{
longitude: amenity.fields.location.lon,
latitude: amenity.fields.location.lat
}}
stopPropagation
onPress={() => handleMarkerPress(amenity.id)}
key={amenity.id}
image={iconMap[amenity.fields.type]}
image={
activeMarker === amenity.id
? activeIconMap[amenity.fields.type]
: iconMap[amenity.fields.type]
}
onSelect={markerSelect}
/>
))}
Expand Down
14 changes: 12 additions & 2 deletions src/screens/ParadeMapScreen/AmenityMarkers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ const amenity = sampleOne(generateAmenity, { seed: 5728 });
describe("AmenityMarkers component", () => {
it("renders correctly", () => {
const output = shallow(
<AmenityMarkers amenities={[amenity]} markerSelect={() => {}} />
<AmenityMarkers
amenities={[amenity]}
markerSelect={() => {}}
handleMarkerPress={() => {}}
activeMarker={undefined}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one test for active amenity too please?

);
expect(output).toMatchSnapshot();
});

it("renders nothing when no amenities provided", () => {
const output = shallow(
<AmenityMarkers amenities={[]} markerSelect={() => {}} />
<AmenityMarkers
amenities={[]}
markerSelect={() => {}}
handleMarkerPress={() => {}}
activeMarker={undefined}
/>
);
expect(output.children().length).toBe(0);
});
Expand Down
9 changes: 7 additions & 2 deletions src/screens/ParadeMapScreen/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ class Map extends PureComponent<Props, State> {
);
};

handleMarkerPress = (stage: Event) => {
this.setState({ tileDetails: stage, activeMarker: stage.id });
handleMarkerPress = (markerID: string, stage: ?Event) => {
this.setState({
tileDetails: stage,
activeMarker: markerID
});
};

handleMapPress = () => {
Expand Down Expand Up @@ -215,6 +218,8 @@ class Map extends PureComponent<Props, State> {
/>
<AmenityMarkers
amenities={amenities}
handleMarkerPress={this.handleMarkerPress}
activeMarker={this.state.activeMarker}
markerSelect={this.handleIOSMarkerSelect}
/>
<StageMarkers
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ParadeMapScreen/Map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe("handleMarkerPress", () => {

output.instance().mapViewRef.current = { animateToCoordinate };
const handleMarkerPressSpy = output.instance().handleMarkerPress;
handleMarkerPressSpy(stage);
handleMarkerPressSpy(stage.id, stage);
expect(output.state().tileDetails).toEqual(stage);
expect(output.state().activeMarker).toEqual(stage.id);
jest.clearAllMocks();
Expand Down
4 changes: 2 additions & 2 deletions src/screens/ParadeMapScreen/StageMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import stageIconInactive from "../../../assets/images/stageIconInactive.png";
type Props = {
stages: Event[],
activeMarker: ?string,
handleMarkerPress: (stage: Event) => void,
handleMarkerPress: (markerID: string, stage: Event) => void,
markerSelect: (event: { nativeEvent: { coordinate: Coordinates } }) => void
};

Expand All @@ -36,7 +36,7 @@ const StageMarkers = ({
latitude: stage.fields.location.lat
}}
key={stage.id}
onPress={() => handleMarkerPress(stage)}
onPress={() => handleMarkerPress(stage.id, stage)}
stopPropagation
image={
activeMarker === stage.id ? stageIconActive : stageIconInactive
Expand Down
10 changes: 3 additions & 7 deletions src/screens/ParadeMapScreen/StageMarkers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from "react";
import { shallow } from "enzyme";
import StageMarkers from "./StageMarkers";
import { generateEvent, sampleOne } from "../../data/__test-data";
import type { Event } from "../../data/event";

const stage = sampleOne(generateEvent, { seed: 5728 });

Expand All @@ -12,8 +11,7 @@ describe("AmenityMarkers component", () => {
const output = shallow(
<StageMarkers
stages={[stage]}
// eslint-disable-next-line no-unused-vars
handleMarkerPress={(_: Event) => {}}
handleMarkerPress={() => {}}
activeMarker={null}
markerSelect={() => {}}
/>
Expand All @@ -25,8 +23,7 @@ describe("AmenityMarkers component", () => {
const output = shallow(
<StageMarkers
stages={[]}
// eslint-disable-next-line no-unused-vars
handleMarkerPress={(_: Event) => {}}
handleMarkerPress={() => {}}
activeMarker={null}
markerSelect={() => {}}
/>
Expand All @@ -43,8 +40,7 @@ describe("AmenityMarkers component", () => {
const output = shallow(
<StageMarkers
stages={[stage, recurrenceStage]}
// eslint-disable-next-line no-unused-vars
handleMarkerPress={(_: Event) => {}}
handleMarkerPress={() => {}}
activeMarker={null}
markerSelect={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ exports[`AmenityMarkers component renders correctly 1`] = `
}
image={1}
key="20nBC086o2kwuMWHp8FqMyUV"
onPress={[Function]}
onSelect={[Function]}
pointerEvents="none"
stopPropagation={false}
stopPropagation={true}
/>
</React.Fragment>
`;
4 changes: 4 additions & 0 deletions src/screens/ParadeMapScreen/__snapshots__/Map.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ exports[`Map component renders correctly 1`] = `
}
/>
<AmenityMarkers
activeMarker={null}
amenities={
Array [
Object {
Expand All @@ -581,6 +582,7 @@ exports[`Map component renders correctly 1`] = `
},
]
}
handleMarkerPress={[Function]}
markerSelect={[Function]}
/>
<StageMarkers
Expand Down Expand Up @@ -1276,6 +1278,7 @@ exports[`Map component renders without location button when permission is restri
}
/>
<AmenityMarkers
activeMarker={null}
amenities={
Array [
Object {
Expand All @@ -1293,6 +1296,7 @@ exports[`Map component renders without location button when permission is restri
},
]
}
handleMarkerPress={[Function]}
markerSelect={[Function]}
/>
<StageMarkers
Expand Down