Skip to content

Commit

Permalink
Making default zoom levels a single source of truth
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Aug 24, 2023
1 parent 1412804 commit ee15972
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/dashboard/src/components/app-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const AppEvents = {
refreshAlertCount: new Subject<number>(),
alertListOpenedAlert: new Subject<Alert | null>(),
disabledLayers: new ReplaySubject<Record<string, boolean>>(),
zoom: new BehaviorSubject<number>(5),
zoom: new BehaviorSubject<number | null>(null),
mapCenter: new BehaviorSubject<[number, number]>([0, 0]),
};
6 changes: 4 additions & 2 deletions packages/dashboard/src/components/map-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const TrajectoryUpdateInterval = 2000;
const SettingsKey = 'mapAppSettings';
const colorManager = new ColorManager();

const DEFAULT_ZOOM_LEVEL = 5;

function getRobotId(fleetName: string, robotName: string): string {
return `${fleetName}/${robotName}`;
}
Expand Down Expand Up @@ -214,11 +216,11 @@ export const MapApp = styled(
const [imageUrl, setImageUrl] = React.useState<string | null>(null);
const [bounds, setBounds] = React.useState<L.LatLngBoundsLiteral | null>(null);
const [center, setCenter] = React.useState<L.LatLngTuple>([0, 0]);
const [zoom, setZoom] = React.useState<number>(5);
const [zoom, setZoom] = React.useState<number>(DEFAULT_ZOOM_LEVEL);

React.useEffect(() => {
const sub = AppEvents.zoom.subscribe((currentValue) => {
setZoom(currentValue);
setZoom(currentValue ?? DEFAULT_ZOOM_LEVEL);
});
return () => sub.unsubscribe();
}, []);
Expand Down

0 comments on commit ee15972

Please sign in to comment.