Skip to content

Commit

Permalink
add method to remove features from the upload wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Feb 22, 2025
1 parent 64294e6 commit 0ad2f4e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/pages/upload/MapPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const MapPreview: React.FC<{
fetchCache: FetchCache | undefined;
bboxFromOsmPatch: Bbox | undefined;
setFocusedFeatureId(id: string | number): void;
removeFeatureFromPatch(id: string | number): Promise<void>;
moveNode:
| ((feature: OsmPatchFeature, lat: number, lng: number) => void)
| false;
Expand All @@ -36,6 +37,7 @@ export const MapPreview: React.FC<{
fetchCache,
bboxFromOsmPatch,
setFocusedFeatureId,
removeFeatureFromPatch,
moveNode,
}) => {
const allowEdit = !!moveNode;
Expand Down Expand Up @@ -104,6 +106,15 @@ export const MapPreview: React.FC<{
click: () => setFocusedFeatureId(feature.id!),
dragstart: () => setFocusedFeatureId(feature.id!),
dragend: (event) => onDragEnd(event, feature),
dblclick: async () => {
if (
// this is not for end users, so the UX can be a bit crude
// eslint-disable-next-line no-restricted-globals, no-alert
confirm('u want to remove this feature from the diff?')
) {
await removeFeatureFromPatch(feature.id!);
}
},
}}
draggable={allowEdit && !feature.properties.__action}
/>
Expand Down
9 changes: 9 additions & 0 deletions src/pages/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ const UploadInner: React.FC = () => {
}
}

async function removeFeatureFromPatch(id: string) {
await rebuildOsmChange({
...osmPatch!,
features: osmPatch!.features.filter((feature) => feature.id !== id),
});
}

async function onFileUpload(files: FileList | null) {
if (!files?.length) {
// the user unselected the current file, so reset
Expand Down Expand Up @@ -313,6 +320,7 @@ const UploadInner: React.FC = () => {
osmPatch={osmPatch}
bboxFromOsmPatch={bboxFromOsmPatch}
setFocusedFeatureId={setFocusedFeatureId}
removeFeatureFromPatch={removeFeatureFromPatch}
moveNode={allowEdit && moveNode}
/>
</div>
Expand All @@ -321,6 +329,7 @@ const UploadInner: React.FC = () => {
<DiffForFeature
feature={focusedFeature}
original={fetchCache?.[`${focusedFeature.id}`]}
removeFeatureFromPatch={removeFeatureFromPatch}
/>
) : (
<em>Select a feature to view more details</em>
Expand Down
12 changes: 10 additions & 2 deletions src/pages/upload/components/DiffForFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const EMPTY_CELL = <td>&nbsp;</td>;
export const DiffForFeature: React.FC<{
feature: OsmPatchFeature;
original: OsmFeature | undefined;
}> = ({ feature, original }) => {
removeFeatureFromPatch(id: string | number): Promise<void>;
}> = ({ feature, original, removeFeatureFromPatch }) => {
const tag2link = useTag2link();
const { user: me } = useContext(AuthContext);

Expand All @@ -42,7 +43,14 @@ export const DiffForFeature: React.FC<{
<header style={{ textTransform: 'capitalize' }}>
{action ? (
<>
{type} {id}<OpenInLinks type={type} id={id} />
{type} {id}{' '}
<button
type="button"
onClick={() => removeFeatureFromPatch(feature.id!)}
>
Remove
</button>{' '}
<OpenInLinks type={type} id={id} />
</>
) : (
<>🆕 {feature.id}</>
Expand Down

0 comments on commit 0ad2f4e

Please sign in to comment.