diff --git a/src/js/api/Client.js b/src/js/api/Client.js index 1cee6c2..2782545 100644 --- a/src/js/api/Client.js +++ b/src/js/api/Client.js @@ -56,4 +56,6 @@ export default class Client { } createActivity = activity => this.#client.post("activities", { activity }) + + stopTimer = timedActivity => this.#client.get(`activities/${timedActivity.id}/stop_timer`) } diff --git a/src/js/background.js b/src/js/background.js index 225b4f9..fa70853 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -58,6 +58,19 @@ chrome.runtime.onMessage.addListener(action => { }) } + if (action.type === "stopTimer") { + const { timedActivity, service } = action.payload + getCurrentTab().then(tab => { + getSettings().then(settings => { + const apiClient = new ApiClient(settings) + apiClient + .stopTimer(timedActivity) + .then(() => resetBubble({ tab, apiClient, service })) + .catch(() => null) + }) + }) + } + if (action.type === "openOptions") { let url if (isChrome()) { diff --git a/src/js/components/App.js b/src/js/components/App.js index aa79e65..73e9c8d 100644 --- a/src/js/components/App.js +++ b/src/js/components/App.js @@ -3,6 +3,7 @@ import PropTypes from "prop-types" import Spinner from "components/Spinner" import Form from "components/Form" import Calendar from "components/Calendar" +import TimerView from "components/App/TimerView" import { observable, computed } from "mobx" import { Observer, observer } from "mobx-react" import { Spring, animated, config } from "react-spring/renderprops" @@ -135,6 +136,15 @@ class App extends Component { this.changeset.date = formatDate(date) } + handleStopTimer = timedActivity => { + const { service } = this.props + + chrome.runtime.sendMessage({ + type: "stopTimer", + payload: { timedActivity, service }, + }) + } + handleSubmit = event => { event.preventDefault() const { service } = this.props @@ -198,7 +208,9 @@ class App extends Component {
{() => - timedActivity ? null : ( + timedActivity ? ( + + ) : ( <> { + onStopTimer(timedActivity) + } + + return ( +
+

+ {timedActivity.customer_name}:
+ {timedActivity.assignment_name} +

+

{timedActivity.task_name}

+
+ + +
+ ) +} + +TimerView.propTypes = { + timedActivity: PropTypes.shape({ + customer_name: PropTypes.string.isRequired, + assignment_name: PropTypes.string.isRequired, + task_name: PropTypes.string.isRequired, + timer_started_at: PropTypes.string.isRequired, + seconds: PropTypes.number.isRequired, + }).isRequired, + onStopTimer: PropTypes.func.isRequired, +}