Skip to content

Commit

Permalink
Add shortkey for re-opening detailed survey
Browse files Browse the repository at this point in the history
  • Loading branch information
opyh committed Mar 6, 2024
1 parent 6474505 commit 97f57d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
14 changes: 14 additions & 0 deletions src/components/NodeToolbar/NodeToolbar.tsx
Expand Up @@ -22,6 +22,7 @@ import {
Feature,
WheelmapFeature,
YesNoLimitedUnknown,
accessibilityCloudFeatureFrom,
getFeatureId,
isWheelchairAccessible,
isWheelmapFeatureId,
Expand Down Expand Up @@ -451,6 +452,18 @@ class NodeToolbar extends React.PureComponent<Props, State> {
return <PositionedCloseLink {...{ onClick: onClose }} />;
}

handleKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {
if (event.key === 'e' && (event.metaKey || event.ctrlKey) && event.shiftKey) {
const feature = accessibilityCloudFeatureFrom(this.props.feature);
if (!feature) {
return;
}
const { properties } = feature;
const { organizationId, surveyProjectId, surveyResultId } = properties;
window.open(`https://wheelmap.pro/organizations/${organizationId}/survey-projects/${surveyProjectId}/show?surveyResultId=${surveyResultId}`)
}
}

render() {

return (
Expand All @@ -470,6 +483,7 @@ class NodeToolbar extends React.PureComponent<Props, State> {
minimalTopPosition={this.props.minimalTopPosition}
minimalHeight={135}
closeOnEscape={this.state.shouldCloseOnEscape}
onKeyDown={this.handleKeyDown}
>
<ErrorBoundary>
{this.renderNodeHeader()}
Expand Down
19 changes: 11 additions & 8 deletions src/components/Toolbar.tsx
@@ -1,13 +1,13 @@
import { t } from 'ttag';
import { hsl } from 'd3-color';
import uniq from 'lodash/uniq';
import minBy from 'lodash/minBy';
import includes from 'lodash/includes';
import styled from 'styled-components';
import minBy from 'lodash/minBy';
import uniq from 'lodash/uniq';
import * as React from 'react';
import colors, { alpha } from '../lib/colors';
import { isOnSmallViewport } from '../lib/ViewportSize';
import ResizeObserverPolyfill from 'resize-observer-polyfill';
import styled from 'styled-components';
import { t } from 'ttag';
import { isOnSmallViewport } from '../lib/ViewportSize';
import colors, { alpha } from '../lib/colors';

type Props = {
className?: string;
Expand All @@ -23,6 +23,7 @@ type Props = {
isModal?: boolean;
enableTransitions?: boolean;
closeOnEscape?: boolean;
onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;
};

function mergeRefs(refs) {
Expand Down Expand Up @@ -522,14 +523,16 @@ const BaseToolbar = (
[props.isModal, touchStartY, ySamples, topOffset]
);

const { closeOnEscape, onKeyDown } = props;
const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLElement>) => {
if (props.closeOnEscape !== false && event.key === 'Escape' && scrollElementRef.current) {
if (closeOnEscape !== false && event.key === 'Escape' && scrollElementRef.current) {
const closeLink = scrollElementRef.current.querySelector('.close-link');
if (closeLink && closeLink['click']) {
closeLink['click']();
}
}
}, [props.closeOnEscape]);
onKeyDown?.(event);
}, [closeOnEscape, onKeyDown]);

const toolbarIsScrollable = React.useMemo(() => {
if (!scrollElementRef.current) {
Expand Down
26 changes: 14 additions & 12 deletions src/lib/Feature.ts
@@ -1,24 +1,22 @@
import { t } from 'ttag';
import get from 'lodash/get';
import pick from 'lodash/pick';
import { Point } from 'geojson';
import flatten from 'lodash/flatten';
import get from 'lodash/get';
import includes from 'lodash/includes';
import isEqual from 'lodash/isEqual';
import isArray from 'lodash/isArray';
import uniq from 'lodash/uniq';
import isEqual from 'lodash/isEqual';
import isPlainObject from 'lodash/isPlainObject';
import { Point } from 'geojson';
import pick from 'lodash/pick';
import uniq from 'lodash/uniq';
import { t } from 'ttag';
import { translatedStringFromObject } from './i18n';

import shouldUseImperialUnits from './shouldUseImperialUnits';
import { EquipmentInfo, EquipmentInfoProperties } from './EquipmentInfo';
import { isEquipmentAccessible } from './EquipmentInfo';
import { Category } from './Categories';
import { categoryNameFor, getCategoryIdFromProperties } from './Categories';
import { Category, categoryNameFor, getCategoryIdFromProperties } from './Categories';
import { ClientSideConfiguration } from './ClientSideConfiguration';
import { EquipmentInfo, EquipmentInfoProperties, isEquipmentAccessible } from './EquipmentInfo';
import { LocalizedString } from './i18n';
import { normalizeCoordinates } from './normalizeCoordinates';
import { SearchResultFeature } from './searchPlaces';
import { ClientSideConfiguration } from './ClientSideConfiguration';
import shouldUseImperialUnits from './shouldUseImperialUnits';

export type YesNoLimitedUnknown = 'yes' | 'no' | 'limited' | 'unknown';
export type YesNoUnknown = 'yes' | 'no' | 'unknown';
Expand Down Expand Up @@ -170,6 +168,10 @@ export type AccessibilityCloudProperties = {
phone: string | null,
phoneNumber: string | null,
placeWebsiteUrl?: string | null,
surveyProjectId?: string,
surveyResultId?: string,
organizationId?: string,
lastUpdate?: string,
} & AccessibilityDescription;

export type AccessibilityCloudFeature = {
Expand Down

0 comments on commit 97f57d5

Please sign in to comment.