Skip to content

Commit

Permalink
Minor frontend fix & enhancement (#2033)
Browse files Browse the repository at this point in the history
* fix(entities-geolocation): add geolocation to store

* fix(main): use entity centroid instead of event coordinate

* feat(package): turf/centroid package add

* fix(submissionsTable): spelling fix

* fix(home): show short description instead of description on home project summary
  • Loading branch information
NSUWAL123 authored Dec 26, 2024
1 parent bec592e commit 2a66a20
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const SubmissionsTable = ({ toggleView }) => {
rowClassName="codeRow"
dataFormat={(row) => (
<div className="fmtm-w-[7rem] fmtm-overflow-hidden fmtm-truncate">
<span>{row?.__system?.reviewState ? camelToFlat(row?.__system?.reviewState) : 'Recieved'}</span>
<span>{row?.__system?.reviewState ? camelToFlat(row?.__system?.reviewState) : 'Received'}</span>
</div>
)}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/src/components/home/ExploreProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export default function ExploreProjectCard({ data }: { data: projectType }) {
{data.name}
</p>

<p className="fmtm-capitalize fmtm-line-clamp-2 fmtm-mt-[5%] fmtm-text-[#7A7676]" title={data.description}>
{data.description}
<p
className="fmtm-capitalize fmtm-line-clamp-2 fmtm-mt-[5%] fmtm-text-[#7A7676]"
title={data.short_description}
>
{data.short_description}
</p>
<div className="fmtm-flex fmtm-items-start fmtm-mt-[1.63rem] fmtm-gap-2">
<AssetModules.LocationOn color="error" style={{ fontSize: '22px' }} />
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/models/home/homeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type homeProjectPaginationTypes = {
export type projectType = {
name: string;
centroid: [number, number];
description: string;
short_description: string;
hashtags: string | null;
id: number;
location_str: string;
Expand Down
1 change: 1 addition & 0 deletions src/mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@tiptap/starter-kit": "^2.10.3",
"@turf/bbox": "^7.1.0",
"@turf/buffer": "^7.1.0",
"@turf/centroid": "^7.1.0",
"@turf/helpers": "^7.1.0",
"@watergis/maplibre-gl-terradraw": "^0.5.1",
"drizzle-orm": "^0.35.3",
Expand Down
13 changes: 13 additions & 0 deletions src/mapper/pnpm-lock.yaml

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

14 changes: 7 additions & 7 deletions src/mapper/src/lib/components/map/geolocation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
let { map }: Props = $props();
let coords: LngLatLike | undefined = $state();
let rotationDeg: number | undefined = $state();
let watchId: number | undefined = $state();
let directions: MapLibreGlDirections = $state();
Expand Down Expand Up @@ -70,8 +69,8 @@
}
$effect(() => {
if (coords && entityToNavigate) {
setWaypoints(coords as [number, number], entityToNavigate?.coordinate);
if (entitiesStore.userLocationCoord && entityToNavigate) {
setWaypoints(entitiesStore.userLocationCoord as [number, number], entityToNavigate?.coordinate);
}
});
Expand All @@ -96,7 +95,7 @@
// zoom to user's current location
$effect(() => {
if (entityToNavigate) {
map?.setCenter(coords as LngLatLike);
map?.setCenter(entitiesStore.userLocationCoord as LngLatLike);
map?.setZoom(18);
}
});
Expand All @@ -116,10 +115,11 @@
// track users location
watchId = navigator.geolocation.watchPosition(
function (pos) {
coords = [pos.coords.longitude, pos.coords.latitude];
let latLong = [pos.coords.longitude, pos.coords.latitude];
entitiesStore.setUserLocationCoordinate(latLong);
if (entityToNavigate) {
// if user is in navigation mode, update the map center according to user's live location since swiping map isn't possible
map?.setCenter(coords);
map?.setCenter(latLong);
}
},
function (error) {
Expand Down Expand Up @@ -152,7 +152,7 @@
type: 'Feature',
geometry: {
type: 'Point',
coordinates: coords as number[],
coordinates: entitiesStore.userLocationCoord as number[],
},
// firefox & safari doesn't support device orientation sensor, so if the browser any of the two set orientation to false
properties: { orientation: !(isFirefox || isSafari) },
Expand Down
4 changes: 3 additions & 1 deletion src/mapper/src/lib/components/map/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import { projectSetupStep as projectSetupStepEnum } from '$constants/enums.ts';
import { baseLayers, osmStyle, pmtilesStyle } from '$constants/baseLayers.ts';
import { getEntitiesStatusStore } from '$store/entities.svelte.ts';
import { centroid } from '@turf/centroid';
type bboxType = [number, number, number, number];
Expand Down Expand Up @@ -152,11 +153,12 @@
});
// if clicked point contains entity then set it's osm id else set null to store
if (clickedEntityFeature && clickedEntityFeature?.length > 0) {
const entityCentroid = centroid(clickedEntityFeature[0].geometry);
const clickedEntityId = clickedEntityFeature[0]?.properties?.osm_id;
entitiesStore.setSelectedEntity(clickedEntityId);
entitiesStore.setSelectedEntityCoordinate({
entityId: clickedEntityId,
coordinate: [e.lngLat.lng, e.lngLat.lat],
coordinate: entityCentroid?.geometry?.coordinates,
});
} else {
entitiesStore.setSelectedEntity(null);
Expand Down
10 changes: 10 additions & 0 deletions src/mapper/src/store/entities.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ShapeStream, Shape } from '@electric-sql/client';
import type { ShapeData } from '@electric-sql/client';
import type { LngLatLike } from 'svelte-maplibre';

const API_URL = import.meta.env.VITE_API_URL;

Expand Down Expand Up @@ -31,6 +32,7 @@ type entityIdCoordinateMapType = {
coordinate: [number, number];
};

let userLocationCoord: LngLatLike | undefined = $state();
let selectedEntity: number | null = $state(null);
let entitiesShape: Shape;
let entitiesStatusList: entitiesStatusListType[] = $state([]);
Expand Down Expand Up @@ -117,6 +119,10 @@ function getEntitiesStatusStore() {
toggleGeolocation = status;
}

function setUserLocationCoordinate(coordinate: LngLatLike | undefined) {
userLocationCoord = coordinate;
}

return {
subscribeToEntityStatusUpdates: subscribeToEntityStatusUpdates,
setSelectedEntity: setSelectedEntity,
Expand All @@ -125,6 +131,7 @@ function getEntitiesStatusStore() {
setSelectedEntityCoordinate: setSelectedEntityCoordinate,
setEntityToNavigate: setEntityToNavigate,
setToggleGeolocation: setToggleGeolocation,
setUserLocationCoordinate: setUserLocationCoordinate,
get selectedEntity() {
return selectedEntity;
},
Expand All @@ -146,6 +153,9 @@ function getEntitiesStatusStore() {
get toggleGeolocation() {
return toggleGeolocation;
},
get userLocationCoord() {
return userLocationCoord;
},
};
}

Expand Down

0 comments on commit 2a66a20

Please sign in to comment.