Skip to content

Commit

Permalink
new api call names
Browse files Browse the repository at this point in the history
only create device if we got a expo push token
  • Loading branch information
tgxn committed Dec 20, 2022
1 parent 549446c commit 94a2a30
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions components/CustomNavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ function ViewDeviceButtons({ navigation, deviceData }) {
const [deleteVisible, setDeleteVisible] = useState(false);

const saveDevice = async () => {
await apiService.device.upsertDevice(deviceData.deviceKey, {
await apiService.device.update(deviceData.deviceKey, {
name: deviceName,
});

setEditVisible(false);
};

const deleteDevice = async () => {
await apiService.device.deleteDevice(deviceData.id);
await apiService.device.delete(deviceData.id);

setDeleteVisible(false);
navigation.navigate("ConfigScreen", { refresh: true });
Expand Down
2 changes: 1 addition & 1 deletion components/ViewTopic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ViewTopic = ({ navigation, route }) => {

const topicDeviceArray = topicData.devices.map((device) => device.id);

const response = await apiService.device.getList();
const response = await apiService.device.list();

setDeviceList(response.devices);

Expand Down
18 changes: 11 additions & 7 deletions reducers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ export function reducer(state, action) {
const defaultDeviceNameFormat = `${platform} (${Device.deviceName})`;
console.log("defaultDeviceNameFormat", defaultDeviceNameFormat);

// create registration
apiService.device.createDevice({
deviceKey: state.deviceKey,
name: defaultDeviceNameFormat,
token: state.expoPushToken,
nativeToken: state.nativePushToken,
});
// create registration only if we have an expo token
// TODO this should also update the device if the keys have changed
// currently it just tries to create the device every time
if (state.expoPushToken) {
apiService.device.create({
deviceKey: state.deviceKey,
name: defaultDeviceNameFormat,
token: state.expoPushToken,
nativeToken: state.nativePushToken,
});
}

return {
...state,
Expand Down
2 changes: 1 addition & 1 deletion screens/ConfigScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ConfigScreen = ({ navigation, route }) => {
setTokenList([]);

try {
const response = await apiService.device.getList();
const response = await apiService.device.list();
setTokenList(response.devices);
} catch (error) {
alert(error);
Expand Down
22 changes: 16 additions & 6 deletions service/api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { showToast } from "../components/Shared";

import { BACKEND_URL } from "../const";

import APIService from "@pushme-tgxn/pushmesdk";

const apiService = new APIService({
logging: (message, ...args) => {
console.log(message, ...args);
showToast(message);
},
});
function createApiService() {
const apiService = new APIService({
backendUrl: BACKEND_URL,
// logging: (message) => {
// console.log(message);
// showToast(message);
// },
});
console.log("createApiService", apiService.backendUrl);

return apiService;
}

const apiService = createApiService();
export default apiService;

0 comments on commit 94a2a30

Please sign in to comment.