Show activity form in popup after timer was stoped

This commit is contained in:
manubo
2019-10-02 16:44:47 +02:00
parent 9f7608ecd6
commit aad9fd13c5
3 changed files with 25 additions and 17 deletions

View File

@@ -118,8 +118,8 @@ html {
background-color: $red;
border: none;
border-radius: 50%;
width: 80px;
height: 80px;
width: 70px;
height: 70px;
&:focus {
outline: none;

View File

@@ -2,22 +2,30 @@ import "@babel/polyfill"
import ApiClient from "api/Client"
import { isChrome, getCurrentTab, getSettings, isBrowserTab } from "utils/browser"
import { BackgroundMessenger } from "utils/messaging"
import { tabUpdated, settingsChanged, togglePopup } from "utils/messageHandlers"
import { tabUpdated, settingsChanged, togglePopup, openPopup } from "utils/messageHandlers"
const messenger = new BackgroundMessenger()
function resetBubble({ tab, apiClient, service }) {
messenger.postMessage(tab, { type: "closePopup" })
apiClient.activitiesStatus(service).then(({ data }) => {
messenger.postMessage(tab, {
type: "showBubble",
payload: {
bookedSeconds: data.seconds,
timedActivity: data.timed_activity,
service,
},
function resetBubble({ tab, apiClient, service }, closePopup = true) {
apiClient
.activitiesStatus(service)
.then(({ data }) => {
messenger.postMessage(tab, {
type: "showBubble",
payload: {
bookedSeconds: data.seconds,
timedActivity: data.timed_activity,
service,
},
})
})
.then(() => {
if (closePopup) {
messenger.postMessage(tab, { type: "closePopup" })
} else {
openPopup(tab, { service, messenger })
}
})
})
}
messenger.on("togglePopup", () => {
@@ -65,7 +73,7 @@ chrome.runtime.onMessage.addListener(action => {
const apiClient = new ApiClient(settings)
apiClient
.stopTimer(timedActivity)
.then(() => resetBubble({ tab, apiClient, service }))
.then(() => resetBubble({ tab, apiClient, service }, false))
.catch(() => null)
})
})

View File

@@ -10,7 +10,7 @@ import {
import { get, forEach, reject, isNil } from "lodash/fp"
import { createMatcher } from "utils/urlMatcher"
import remoteServices from "remoteServices"
import { queryTabs, isBrowserTab, getSettings, setStorage } from "utils/browser"
import { queryTabs, isBrowserTab, getSettings } from "utils/browser"
const matcher = createMatcher(remoteServices)
@@ -76,7 +76,7 @@ export function togglePopup(tab, { messenger }) {
}
}
async function openPopup(tab, { service, messenger }) {
export async function openPopup(tab, { service, messenger }) {
messenger.postMessage(tab, { type: "openPopup", payload: { loading: true } })
const fromDate = getStartOfWeek()