Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
feat: remove date-fns
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jan 9, 2020
1 parent 4452ca2 commit 09ad2b4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
"dependencies": {
"@types/styled-components": "^4.4.2",
"date-fns": "^2.9.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"styled-components": "^4.4.1",
Expand Down
28 changes: 5 additions & 23 deletions src/Chat/TimeAgo.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import * as React from 'react'
import { useState, useEffect } from 'react'
import { formatDistance } from 'date-fns'
import { enGB } from 'date-fns/locale'

const d = (from: Date) => formatDistance(from, new Date(), { locale: enGB })

export const TimeAgo = ({ from, ...props }: { from: Date }) => {
const [ago, setTimeAgo] = useState<string>(d(from))

useEffect(() => {
const i = setInterval(() => {
setTimeAgo(d(from))
}, 60000)
return () => {
clearInterval(i)
}
})

return (
<time dateTime={from.toISOString()} {...props}>
{ago}
</time>
)
}
export const TimeAgo = ({ from, ...props }: { from: Date }) => (
<time dateTime={from.toISOString()} {...props}>
{from.toLocaleTimeString()} {from.toLocaleDateString()}
</time>
)
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Distribute Aid: Chat</h1>
<script src="./main.js"></script>
<script type="text/javascript">
window.onload = () => {
DAChat({ context: 'public' })
DAChat({ context: document.querySelector("meta[name='chat:context']").getAttribute("content") })
}
</script>
</body>
Expand Down
7 changes: 0 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ const cfg = {
react: 'React',
'react-dom': 'ReactDOM',
},
plugins: [
// See https://date-fns.org/v2.9.0/docs/webpack
new webpack.ContextReplacementPlugin(
/date\-fns[\/\\]/,
new RegExp(`[/\\\\\](${['en'].join('|')})[/\\\\\]`),
),
],
}

module.exports = [
Expand Down

0 comments on commit 09ad2b4

Please sign in to comment.