From 524bca74c57b0ccc7b69e0f06048f6835753177e Mon Sep 17 00:00:00 2001 From: manubo Date: Tue, 24 Sep 2019 10:45:49 +0200 Subject: [PATCH] Code cleanup --- src/css/popup.scss | 11 +++++++++-- src/js/background.js | 28 +++++++++++++++------------- src/js/components/App.js | 14 +------------- src/js/components/Form.js | 3 ++- src/js/content.js | 4 ---- 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/css/popup.scss b/src/css/popup.scss index 312127b..ccb5622 100644 --- a/src/css/popup.scss +++ b/src/css/popup.scss @@ -28,7 +28,6 @@ html { flex: 0 0 48px; width: 48px; height: 48px; - } h1 { @@ -66,7 +65,6 @@ html { flex: 0 0 42px; color: white; background-color: #eee; - } &.moco-bx-calendar__day--filled { @@ -89,6 +87,15 @@ html { } } } + + .moco-bx-timer-view { + text-align: center; + margin-top: 4rem; + + .btn-stop-timer { + margin-top: 3rem; + } + } } .moco-bx-error-container { diff --git a/src/js/background.js b/src/js/background.js index 70ac8cb..225b4f9 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -6,6 +6,20 @@ import { tabUpdated, settingsChanged, togglePopup } 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: { + bookedHours: parseFloat(data.hours), + timedActivity: data.timed_activity, + service, + }, + }) + }) +} + messenger.on("togglePopup", () => { getCurrentTab().then(tab => { if (tab && !isBrowserTab(tab)) { @@ -31,19 +45,7 @@ chrome.runtime.onMessage.addListener(action => { const apiClient = new ApiClient(settings) apiClient .createActivity(activity) - .then(() => { - messenger.postMessage(tab, { type: "closePopup" }) - apiClient.activitiesStatus(service).then(({ data }) => { - messenger.postMessage(tab, { - type: "showBubble", - payload: { - bookedHours: parseFloat(data.hours), - timedActivity: data.timed_activity, - service, - }, - }) - }) - }) + .then(() => resetBubble({ tab, apiClient, service })) .catch(error => { if (error.response?.status === 422) { chrome.runtime.sendMessage({ diff --git a/src/js/components/App.js b/src/js/components/App.js index 8a0b193..aa79e65 100644 --- a/src/js/components/App.js +++ b/src/js/components/App.js @@ -22,19 +22,9 @@ import InvalidConfigurationError from "components/Errors/InvalidConfigurationErr import UpgradeRequiredError from "components/Errors/UpgradeRequiredError" import UnknownError from "components/Errors/UnknownError" import Header from "./shared/Header" -import { head, isNil } from "lodash" +import { head } from "lodash" import TimeInputParser from "utils/TimeInputParser" -const findTimedActivity = (activities, service) => { - if (!service) { - return null - } - - return activities.find( - activity => activity.remote_id === service.id && !isNil(activity.timer_started_at), - ) -} - @observer class App extends Component { static propTypes = { @@ -181,7 +171,6 @@ class App extends Component { schedules, fromDate, toDate, - service, errorType, errorMessage, } = this.props @@ -222,7 +211,6 @@ class App extends Component {
{ closePopup() }) - - messenger.on("activityCreated", () => { - closePopup() - }) })