Skip to content

Commit

Permalink
Merge pull request #419 from pankona/use-call-method-to-call-cloud-fu…
Browse files Browse the repository at this point in the history
…nctions

Use call method to call cloud functions
  • Loading branch information
pankona committed Jan 28, 2022
2 parents 5f2f4b4 + 14e0bb8 commit d1f424f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
13 changes: 13 additions & 0 deletions hashira-web/src/App.tsx
Expand Up @@ -128,6 +128,19 @@ const App: React.VFC = () => {
[user]
);

const intervalMs = 1000 * 60 * 3; // 3 minutes

React.useEffect(() => {
firebase.ping();
const intervalId = setInterval(() => {
firebase.ping();
}, intervalMs);

return () => {
clearInterval(intervalId);
};
}, []);

React.useEffect(() => {
if (user) {
Promise.all([
Expand Down
20 changes: 17 additions & 3 deletions hashira-web/src/firebase.ts
Expand Up @@ -148,7 +148,7 @@ export const uploadTasks = async (tasks: string[]) => {
try {
await functions.httpsCallable(
functions.getFunctions(undefined, "asia-northeast1"),
"add"
"call?method=add"
)({
tasks: tasksObject,
priority: {
Expand Down Expand Up @@ -191,7 +191,7 @@ export const updateTasks = async (tasksObject: TasksObject) => {
try {
await functions.httpsCallable(
functions.getFunctions(undefined, "asia-northeast1"),
"add"
"call?method=add"
)({
tasks: tasksObject,
priority: priorities,
Expand All @@ -212,7 +212,7 @@ export const updateTasks2 = async (tasksObject: TasksObject) => {
try {
await functions.httpsCallable(
functions.getFunctions(undefined, "asia-northeast1"),
"add"
"call?method=add"
)({
tasks: tasksObject,
});
Expand All @@ -224,6 +224,20 @@ export const updateTasks2 = async (tasksObject: TasksObject) => {
}
};

export const ping = async () => {
try {
await functions.httpsCallable(
functions.getFunctions(undefined, "asia-northeast1"),
"call?method=ping"
)();
} catch (e) {
// FIXME:
// currently cloud functions doesn't return appropriate response
// that fits httpsCallable protocol even if the function succeeded.
console.log("error:", e);
}
};

export const fetchTaskAndPriorities = async (uid: string) => {
const db = getFirestore();
const docRef = doc(db, "tasksAndPriorities", uid);
Expand Down

0 comments on commit d1f424f

Please sign in to comment.