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

feat: radix image upload #468

Open
wants to merge 8 commits into
base: feature/a11ymap
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
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"query-string": "^6.13.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-dropzone": "^14.3.5",
"react-error-boundary": "^4.1.2",
"react-map-gl": "^7.1.7",
"react-radio-group": "^3.0.3",
Expand Down
99 changes: 54 additions & 45 deletions src/components/CombinedFeaturePanel/CombinedFeaturePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,84 +1,93 @@
import { useHotkeys } from '@blueprintjs/core'
import { uniqBy } from 'lodash'
import React, { useMemo, useState } from 'react'
import styled from 'styled-components'
import { t } from 'ttag'
import { useHotkeys } from "@blueprintjs/core";
import { Box, Callout } from "@radix-ui/themes";
import { uniqBy } from "lodash";
import React, { useMemo, useState } from "react";
import { t } from "ttag";
import {
AnyFeature, getKey, isOSMFeature, isSearchResultFeature,
} from '../../lib/model/geo/AnyFeature'
import colors from '../../lib/util/colors'
import FeaturesDebugJSON from './components/FeaturesDebugJSON'
import PlaceOfInterestDetails from './type-specific/poi/PlaceOfInterestDetails'
import ErrorBoundary from '../shared/ErrorBoundary'
import OSMSidewalkDetails from './type-specific/surroundings/OSMSidewalkDetails'
import OSMBuildingDetails from './type-specific/building/OSMBuildingDetails'
import { Box, Callout } from '@radix-ui/themes'
type AnyFeature,
getKey,
isOSMFeature,
isSearchResultFeature,
} from "../../lib/model/geo/AnyFeature";
import ErrorBoundary from "../shared/ErrorBoundary";
import FeaturesDebugJSON from "./components/FeaturesDebugJSON";
import OSMBuildingDetails from "./type-specific/building/OSMBuildingDetails";
import PlaceOfInterestDetails from "./type-specific/poi/PlaceOfInterestDetails";
import OSMSidewalkDetails from "./type-specific/surroundings/OSMSidewalkDetails";

type Props = {
features: AnyFeature[];
focusImage?: string
}
activeImageId?: string;
isUploadDialogOpen?: boolean;
};

function FeatureSection({ feature }: { feature: AnyFeature }) {
if (!isOSMFeature(feature)) {
return <section>Feature type not supported</section>
return <section>Feature type not supported</section>;
}

if (feature.properties.building) {
return <OSMBuildingDetails feature={feature} />
return <OSMBuildingDetails feature={feature} />;
}

if (
feature.properties.highway === 'footway'
|| feature.properties.highway === 'pedestrian'
feature.properties.highway === "footway" ||
feature.properties.highway === "pedestrian"
) {
return <OSMSidewalkDetails feature={feature} />
return <OSMSidewalkDetails feature={feature} />;
}

return (
<section>
<h2>Feature type not supported</h2>
</section>
)
);
}


export function CombinedFeaturePanel(props: Props) {
const features = uniqBy(props.features, (feature) => (isSearchResultFeature(feature) ? feature.properties.osm_id : feature._id))
const features = uniqBy(props.features, (feature) =>
isSearchResultFeature(feature) ? feature.properties.osm_id : feature._id,
);

const [showDebugger, setShowDebugger] = useState(false)
const hotkeys = useMemo(() => [
{
combo: 'j',
global: true,
label: 'Show JSON Feature Debugger',
onKeyDown: () => setShowDebugger(!showDebugger),
},

], [showDebugger])
const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeys)
const surroundings = features?.length > 1 ? features.slice(1) : undefined
const [showDebugger, setShowDebugger] = useState(false);
const hotkeys = useMemo(
() => [
{
combo: "j",
global: true,
label: "Show JSON Feature Debugger",
onKeyDown: () => setShowDebugger(!showDebugger),
},
],
[showDebugger],
);
const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeys);
const surroundings = features?.length > 1 ? features.slice(1) : undefined;

return (
<React.StrictMode>
<ErrorBoundary>
<Box onKeyDown={handleKeyDown} onKeyUp={handleKeyUp}>
{features[0] && <PlaceOfInterestDetails feature={features[0]} focusImage={props.focusImage} />}
{surroundings?.map((feature) => <FeatureSection key={getKey(feature)} feature={feature} />)}
{features[0] && (
<PlaceOfInterestDetails
feature={features[0]}
activeImageId={props.activeImageId}
isUploadDialogOpen={props.isUploadDialogOpen}
/>
)}
{surroundings?.map((feature) => (
<FeatureSection key={getKey(feature)} feature={feature} />
))}

{(!features || features.length === 0) && (
<Callout.Root>
<Callout.Text>
{t`No features found.`}
</Callout.Text>
<Callout.Text>{t`No features found.`}</Callout.Text>
</Callout.Root>
)}

<p>
{showDebugger && <FeaturesDebugJSON features={features} /> }
</p>
<p>{showDebugger && <FeaturesDebugJSON features={features} />}</p>
</Box>
</ErrorBoundary>
</React.StrictMode>
)
);
}
35 changes: 4 additions & 31 deletions src/components/CombinedFeaturePanel/components/FeatureGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
import { CameraIcon } from "@radix-ui/react-icons";
import {
AspectRatio,
Box,
Button,
Callout,
Card,
Dialog,
Flex,
Grid,
Inset,
VisuallyHidden,
} from "@radix-ui/themes";
import { useRouter } from "next/router";
import {
type FC,
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
/* eslint-disable @next/next/no-img-element */
import { type FC, useMemo } from "react";
import useSWR from "swr";
import useAccessibilityCloudAPI from "~/lib/fetchers/ac/useAccessibilityCloudAPI";
import type { AccessibilityCloudImage } from "~/lib/model/ac/Feature";
import type { AnyFeature } from "~/lib/model/geo/AnyFeature";
import { Gallery } from "./Gallery/Gallery";
import { GalleryAddImageButton } from "./Gallery/GalleryAddImageButton";
import { makeImageIds, makeImageLocation } from "./Gallery/util";

const fetcher = (urls: string[]) => {
Expand All @@ -51,8 +25,8 @@ interface ImageResponse {

export const FeatureGallery: FC<{
feature: AnyFeature;
focusImage?: string;
}> = ({ feature, focusImage }) => {
activeImageId?: string;
}> = ({ feature, activeImageId }) => {
const ids = makeImageIds(feature);
const { baseUrl, appToken } = useAccessibilityCloudAPI({ cached: true });
const { data } = useSWR(
Expand All @@ -65,8 +39,7 @@ export const FeatureGallery: FC<{

return (
<>
<Gallery images={images} activeImageId={focusImage} />
<GalleryAddImageButton />
<Gallery images={images} activeImageId={activeImageId} />
</>
);
};
Loading