Skip to content

Commit

Permalink
Re-center device on click
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed May 29, 2024
1 parent e2f50c9 commit 731898d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/map/main/MapSelectedDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import { usePrevious } from '../../reactHelper';
import { useAttributePreference } from '../../common/util/preferences';

const MapSelectedDevice = () => {
const selectedDeviceId = useSelector((state) => state.devices.selectedId);
const previousDeviceId = usePrevious(selectedDeviceId);
const currentTime = useSelector((state) => state.devices.selectTime);
const currentId = useSelector((state) => state.devices.selectedId);
const previousTime = usePrevious(currentTime);
const previousId = usePrevious(currentId);

const selectZoom = useAttributePreference('web.selectZoom', 10);
const mapFollow = useAttributePreference('mapFollow', false);

const position = useSelector((state) => state.session.positions[selectedDeviceId]);
const position = useSelector((state) => state.session.positions[currentId]);

useEffect(() => {
if ((selectedDeviceId !== previousDeviceId || mapFollow) && position) {
if ((currentId !== previousId || currentTime !== previousTime || mapFollow) && position) {
map.easeTo({
center: [position.longitude, position.latitude],
zoom: Math.max(map.getZoom(), selectZoom),
Expand Down
5 changes: 2 additions & 3 deletions src/store/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ const { reducer, actions } = createSlice({
update(state, action) {
action.payload.forEach((item) => state.items[item.id] = item);
},
select(state, action) {
state.selectedId = action.payload;
},
selectId(state, action) {
state.selectTime = Date.now();
state.selectedId = action.payload;
state.selectedIds = state.selectedId ? [state.selectedId] : [];
},
selectIds(state, action) {
state.selectTime = Date.now();
state.selectedIds = action.payload;
[state.selectedId] = state.selectedIds;
},
Expand Down

0 comments on commit 731898d

Please sign in to comment.