Skip to content

Commit

Permalink
feat: fetch loo names
Browse files Browse the repository at this point in the history
  • Loading branch information
ob6160 committed Feb 12, 2022
1 parent c883c2e commit ec58d1c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/api/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stringifyAndCompressLoos } from '../lib/loo';
import ngeohash from 'ngeohash';
import { async } from 'hasha';

const { Loo, Report, Area, MapGeo } = require('./db');
const { GraphQLDateTime } = require('graphql-iso-date');
Expand Down Expand Up @@ -102,6 +103,8 @@ const resolvers = {
page: res.page,
};
},
looNamesByIds: async (parent, args) =>
await Loo.find({ _id: { $in: args.idList } }),
loosByProximity: async (parent, args) =>
await Loo.findNear(args.from.lng, args.from.lat, args.from.maxDistance),
loosByGeohash: async (parent, args, context) => {
Expand Down
1 change: 1 addition & 0 deletions src/api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ type Query {
"A Point from which to begin the search"
from: ProximityInput!
): [Loo!]!
looNamesByIds(idList: [ID]): [Loo!]!
ukLooMarkers: [String!]! @cacheControl(maxAge: 360, scope: PUBLIC)
"Retrieve a list of areas in existance, name and type only"
areas: [AdminGeo!]!
Expand Down
19 changes: 15 additions & 4 deletions src/components/LooMap/AccessibilityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useTheme, css } from '@emotion/react';
import Box from '../Box';
import Text from '../Text';
import Spacer from '../Spacer';
import { CompressedLooObject } from '../../lib/loo';
import { useLooNamesByIdsQuery } from '../../api-client/graphql';

const Key = ({ children, ...props }) => (
<Box
Expand Down Expand Up @@ -82,26 +84,35 @@ const Content = ({ toilets }) => {
);
};

const AccessibilityList = (
props: JSX.IntrinsicAttributes & { toilets: any }
) => {
const AccessibilityList = ({ toilets, ...props }) => {
const [showContent, setShowContent] = React.useState(false);

// Fetch proper loo names
const unorderedNames = useLooNamesByIdsQuery({
variables: { idList: toilets.map((t) => t?.id) },
});

// to ensure it gets announced, there must be a delay between the existence of the aria live element and the content
useEffect(() => {
setTimeout(() => {
setShowContent(true);
}, 300);
}, []);

const mapIdToName = Object.fromEntries(
unorderedNames.data?.looNamesByIds.map((e) => [e.id, e.name]) || []
);

const names = toilets.map((t) => mapIdToName[t?.id] || 'Toilet Loading');

return (
<div
role="status"
aria-atomic="true"
aria-live="polite"
aria-relevant="additions text"
>
{showContent && <Content {...props} />}
{showContent && <Content toilets={names || []} {...props} />}
</div>
);
};
Expand Down
6 changes: 1 addition & 5 deletions src/components/LooMap/LooMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,7 @@ const LooMap: React.FC<LooMapProps> = ({
center={center}
/>

<AccessibilityList
toilets={intersectingToilets.map(
(toilet: { name: any }) => toilet.name
)}
/>
<AccessibilityList toilets={intersectingToilets} />

<VisuallyHidden>
<div
Expand Down

0 comments on commit ec58d1c

Please sign in to comment.