forked from joelshepherd/tabliss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Time tracking widget for significant events joelshepherd#626
There is now two different way to count-up, but this one can also count time since something. I will be leaving both, choose whatever you want.
- Loading branch information
1 parent
029674b
commit 9789c3a
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Since | ||
&.relativeTime | ||
font-style: italic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { FC } from "react"; | ||
import { FormattedRelativeTime } from "react-intl"; | ||
|
||
import { useTime } from "../../../hooks"; | ||
import { Props, defaultData } from "./types"; | ||
import "./Since.sass"; | ||
|
||
const Since: FC<Props> = ({ data = defaultData }) => { | ||
|
||
const from = useTime().getTime(); | ||
const to = data.time; | ||
const diff = ((to - from) / 1000) | 0; | ||
|
||
|
||
return ( | ||
<div className="Since"> | ||
<h3> | ||
{data.title || "Since"} | ||
{diff > 0 ? "will be" : "was"} | ||
<span className={`Since relativeTime`}> | ||
<FormattedRelativeTime value={diff} updateIntervalInSeconds={1} /> | ||
</span> | ||
</h3> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Since; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { format } from "date-fns"; | ||
import React, { FC } from "react"; | ||
import { defaultData, Props } from "./types"; | ||
|
||
function formatDate(time: number): string { | ||
return format(time, "yyyy-MM-dd"); | ||
} | ||
|
||
function formatTime(time: number): string { | ||
return format(time, "HH:mm:ss"); | ||
} | ||
|
||
function buildDateObject(time: number, timeStr: string): Date { | ||
return new Date(`${formatDate(time)} ${timeStr || "00:00:00"}`); | ||
} | ||
|
||
const SinceSettings: FC<Props> = ({ data = defaultData, setData }) => ( | ||
<div className="CssSettings"> | ||
<label> | ||
What | ||
<input | ||
type="text" | ||
value={data.title || ""} | ||
onChange={(event) => setData({ ...data, title: event.target.value })} | ||
/> | ||
</label> | ||
|
||
<label> | ||
When | ||
<label> | ||
Date | ||
<input | ||
type="date" | ||
value={formatDate(data.time)} | ||
onChange={(event) => | ||
setData({ | ||
...data, | ||
time: (event.target.value | ||
? new Date(event.target.value) | ||
: new Date() | ||
).getTime(), | ||
}) | ||
} | ||
/> | ||
</label> | ||
<label> | ||
Time | ||
<input | ||
type="time" | ||
value={formatTime(data.time)} | ||
onChange={(event) => { | ||
setData({ | ||
...data, | ||
time: buildDateObject(data.time, event.target.value).getTime(), | ||
}); | ||
}} | ||
/> | ||
</label> | ||
</label> | ||
</div> | ||
); | ||
|
||
export default SinceSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Config } from '../../types'; | ||
import Since from './Since'; | ||
import SinceSettings from './SinceSettings'; | ||
|
||
const config: Config = { | ||
key: 'widget/since', | ||
name: 'Since', | ||
description: 'This widget tracks the time elapsed since or remaining until a specified event.', | ||
dashboardComponent: Since, | ||
settingsComponent: SinceSettings, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { API } from '../../types'; | ||
|
||
type Data = { | ||
time: number; | ||
title?: string; | ||
}; | ||
|
||
export type Props = API<Data>; | ||
|
||
export const defaultData: Data = { | ||
time: Date.now(), | ||
}; |