Skip to content

Commit 682b965

Browse files
committed
feat: add geolocation in save action
1 parent e03895a commit 682b965

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

public/app/listeners/postAction.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const postAction = (mainWindow, db) => (event, payload = {}) => {
1111
format,
1212
verb,
1313
data,
14+
geolocation,
1415
visibility = 'private',
1516
} = payload;
1617

@@ -27,6 +28,7 @@ const postAction = (mainWindow, db) => (event, payload = {}) => {
2728
data,
2829
format,
2930
verb,
31+
geolocation,
3032
visibility,
3133
user: userId,
3234
id: ObjectId().str,

src/actions/action.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { POST_ACTION_SUCCEEDED } from '../types';
22
import { POST_ACTION_CHANNEL } from '../config/channels';
33

4-
const postAction = async (ddd = {}, callback) => () => {
5-
const {
4+
const postAction = async (
5+
{
66
userId,
77
id: appInstanceId,
88
spaceId,
99
subSpaceId,
1010
format,
1111
data,
1212
verb,
13+
geolocation,
1314
visibility,
14-
} = ddd;
15+
} = {},
16+
callback
17+
) => () => {
1518
try {
1619
window.ipcRenderer.send(POST_ACTION_CHANNEL, {
1720
userId,
@@ -21,6 +24,7 @@ const postAction = async (ddd = {}, callback) => () => {
2124
format,
2225
data,
2326
verb,
27+
geolocation,
2428
visibility,
2529
});
2630

src/components/phase/PhaseApp.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class PhaseApp extends Component {
5555
appInstance: PropTypes.shape({
5656
id: PropTypes.string.isRequired,
5757
}),
58+
geolocation: PropTypes.instanceOf(Map),
59+
geolocationEnabled: PropTypes.bool.isRequired,
5860
};
5961

6062
static defaultProps = {
@@ -63,6 +65,7 @@ class PhaseApp extends Component {
6365
appInstance: null,
6466
name: 'Image',
6567
lang: DEFAULT_LANGUAGE,
68+
geolocation: undefined,
6669
};
6770

6871
state = {
@@ -108,6 +111,8 @@ class PhaseApp extends Component {
108111
dispatchGetAppInstance,
109112
appInstance,
110113
dispatchPostAction,
114+
geolocation,
115+
geolocationEnabled,
111116
} = this.props;
112117

113118
// get app instance id in message
@@ -129,8 +134,16 @@ class PhaseApp extends Component {
129134
return patchAppInstanceResource(payload, this.postMessage);
130135
case GET_APP_INSTANCE:
131136
return dispatchGetAppInstance(payload, this.postMessage);
132-
case POST_ACTION:
137+
case POST_ACTION: {
138+
// add geolocation to action if enabled
139+
if (geolocationEnabled) {
140+
const {
141+
coords: { latitude, longitude },
142+
} = geolocation.toJS();
143+
payload.geolocation = { ll: [latitude, longitude] };
144+
}
133145
return dispatchPostAction(payload, this.postMessage);
146+
}
134147
default:
135148
return false;
136149
}
@@ -285,6 +298,9 @@ const mapStateToProps = ({ User, Space }) => ({
285298
lang:
286299
Space.getIn(['current', 'content', 'language']) ||
287300
User.getIn(['current', 'lang']),
301+
302+
geolocation: User.getIn(['current', 'geolocation']),
303+
geolocationEnabled: User.getIn(['current', 'geolocationEnabled']),
288304
});
289305

290306
const mapDispatchToProps = {

0 commit comments

Comments
 (0)