Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/extensions/activities/tota/TOTAExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { totaFindAllByLocation, totaFindOneByReference, registerTOTADataFile } f
import { TOTAActivityOptions } from './TOTAActivityOptions'
import { TOTALoggingControl } from './TOTALoggingControl'
import { TOTAPostSelfSpot } from './TOTAPostSelfSpot'
import { TOTAPostOtherSpot } from './TOTAPostOtherSpot'

const Extension = {
...Info,
Expand Down Expand Up @@ -55,6 +56,7 @@ const ActivityHook = {
}
},
postSelfSpot: TOTAPostSelfSpot,
postOtherSpot: TOTAPostOtherSpot,
Options: TOTAActivityOptions,
generalHuntingType: ({ operation, settings }) => Info.huntingType,
sampleOperations: ({ t, settings, callInfo }) => {
Expand Down
49 changes: 49 additions & 0 deletions src/extensions/activities/tota/TOTAPostOtherSpot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright ©️ 2024 Sebastian Delmont <sd@ham2k.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { Alert } from 'react-native'

import { reportError } from '../../../distro'
import GLOBAL from '../../../GLOBAL'

import { findRef } from '../../../tools/refTools'
import { apiTOTA } from '../../../store/apis/apiTOTA'
import { Info } from './TOTAInfo'

export const TOTAPostOtherSpot = ({ t, comments, qso }) => async (dispatch) => {
if (GLOBAL?.flags?.services?.tota === false) return false

const ref = findRef(qso, Info.huntingType)

if (ref && ref.ref) {
const spot = {
callsign: qso.their.call,
frequency: qso.freq,
mode: qso.mode,
tower_ref: ref.ref,
comment: comments,
}

try {
const apiPromise = await dispatch(apiTOTA.endpoints.spot.initiate(spot, { forceRefetch: true }))
await Promise.all(dispatch(apiTOTA.util.getRunningQueriesThunk()))
const apiResults = await dispatch((_dispatch, _getState) => apiTOTA.endpoints.spot.select(spot)(_getState()))
apiPromise.unsubscribe && apiPromise.unsubscribe()
// Don't worry about duplicates
if (apiResults?.error && !apiResults?.error?.data?.message?.match(/Duplicate self-spot/)) {
Alert.alert(t('extensions.activities.tota.postSpotAPI.error', 'Error posting TOTA spot'),
t('extensions.tota.postSpotAPI.serverResponse', 'Server responded with status {{status}} {{message}}', { status: apiResults.error?.status, message: apiResults.error?.data?.message }))
return false
}
} catch (error) {
Alert.alert(t('extensions.tota.postSpotAPI.error', 'Error posting TOTA spot'), error.message)
reportError('Error posting TOTA spot', error)
return false
}
return true
}
}
Loading