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; background-color: $red;
border: none; border: none;
border-radius: 50%; border-radius: 50%;
width: 80px; width: 70px;
height: 80px; height: 70px;
&:focus { &:focus {
outline: none; outline: none;

View File

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

View File

@@ -10,7 +10,7 @@ import {
import { get, forEach, reject, isNil } from "lodash/fp" import { get, forEach, reject, isNil } from "lodash/fp"
import { createMatcher } from "utils/urlMatcher" import { createMatcher } from "utils/urlMatcher"
import remoteServices from "remoteServices" import remoteServices from "remoteServices"
import { queryTabs, isBrowserTab, getSettings, setStorage } from "utils/browser" import { queryTabs, isBrowserTab, getSettings } from "utils/browser"
const matcher = createMatcher(remoteServices) 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 } }) messenger.postMessage(tab, { type: "openPopup", payload: { loading: true } })
const fromDate = getStartOfWeek() const fromDate = getStartOfWeek()