Skip to content

Commit

Permalink
trial: posting call-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Naveen-g09 committed Jan 11, 2024
1 parent 192bf1a commit 8473a3b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 33 deletions.
24 changes: 8 additions & 16 deletions app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import call from "react-native-phone-call";
import { Text, View } from "../../components/Themed";
import {
getTasks,
sync,
getCallLogs,
postCallLogs,
updateTask,
} from "../../lib/db_helpers";
import { Task } from "../../lib/types";

Expand All @@ -28,19 +28,6 @@ export default function TabOneScreen() {
}
};

// const updateTrials = async (taskId: string) => {
// const updatedTasks = tasks.map((task) => {
// if (task.id === taskId) {
// return {
// ...task,
// trials: task.trials + 1,
// };
// }
// return task;
// });
// setTasks(updatedTasks);
// };

const handleRefresh = useCallback(async () => {
setRefreshing(true);
await fetchTasks();
Expand All @@ -57,8 +44,13 @@ export default function TabOneScreen() {
return () => clearInterval(intervalId);
}, []);

const handleCallPress = (contactNumber: string, taskId: string) => {
RNImmediatePhoneCall.immediatePhoneCall(contactNumber);
const handleCallPress = async (contactNumber: string, taskId: number) => {
try {
await updateTask(taskId);
RNImmediatePhoneCall.immediatePhoneCall(contactNumber);
} catch (error) {
console.error("Error handling call press:", error);
}
};

// Uncomment the following code to use react-native-phone-call instead of react-native-immediate-phone-call
Expand Down
31 changes: 31 additions & 0 deletions external.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
h1 {
color: brown;
font-size: 66px;
font-family: cursive;
background-color: yellow;
}

/*idname*/
#a {
color: green;
font-size: 66px;
font-family: cursive;
background-color: violet;
}

h1#b {
font-size: 100px;
font-family: fantasy;
background: red;
color: white;
}

.myclass {
color: navy;
font-family: fantasy;
font-size: 55px;
}

.myclass1 {
background-color: orange;
}
49 changes: 32 additions & 17 deletions lib/db_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import CallLogs from "react-native-call-log";

import { checkPermission } from "../lib/permissions";
// const API_URL = process.env.API_URL;

const getContactNumbers = async () => {
try {
Expand Down Expand Up @@ -41,41 +40,57 @@ const getTasks = async () => {
console.error("Error fetching tasks:", error);
}
};

const postCallLogs = async (callLogs: any) => {
try {
const formattedCallLogs = callLogs.map((log: any) => {
return {
taskId: log.taskId,
callTime: log.timestamp,
callStatus: log.callType,
duration: log.duration,
};
});

const response = await fetch(
"https://worker-turso-ts.technoculture.workers.dev/call-logs",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(callLogs),
body: JSON.stringify(formattedCallLogs),
},
);

console.log("Call logs posted successfully:", response);
return response;
} catch (error) {
console.error("Error posting call logs:", error);
}
};
const sync = async () => {

const updateTask = async (taskId: number) => {
try {
if (!(await checkPermission())) return [];
const callLogs = await getCallLogs();
const tasks = await getTasks();
const callLogsToPost = callLogs.filter((log: any) => {
return tasks.some((task: any) => {
return task.contactNumber === log.phoneNumber;
//what is this?
});
});
await postCallLogs(callLogsToPost);
return tasks;
const response = await fetch(
`https://worker-turso-ts.technoculture.workers.dev/tasks/${taskId}`,
);
const task = await response.json();
task.targetCallCount = Math.max(task.targetCallCount - 1, 0);
await fetch(
`https://worker-turso-ts.technoculture.workers.dev/tasks/${taskId}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(task),
},
);
console.log("Task updated successfully:", task);
} catch (error) {
console.error("Error syncing:", error);
return [];
console.error("Error updating task:", error);
}
};

export { getCallLogs, getTasks, sync, postCallLogs, getContactNumbers };
export { getCallLogs, getTasks, postCallLogs, getContactNumbers, updateTask };

0 comments on commit 8473a3b

Please sign in to comment.