Replace momentjs - it is too large of a dependency
parent
041bfa22a9
commit
efc28b0098
|
@ -32,7 +32,6 @@
|
||||||
"lodash.omit": "^4.5.0",
|
"lodash.omit": "^4.5.0",
|
||||||
"mobx": "^6.6.1",
|
"mobx": "^6.6.1",
|
||||||
"mobx-react-lite": "^3.4.0",
|
"mobx-react-lite": "^3.4.0",
|
||||||
"moment": "^2.29.4",
|
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-circular-progressbar": "^2.1.0",
|
"react-circular-progressbar": "^2.1.0",
|
||||||
"react-dom": "17.0.2",
|
"react-dom": "17.0.2",
|
||||||
|
|
|
@ -2,11 +2,11 @@ import React from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
|
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
|
||||||
import {bsky, AdxUri} from '@adxp/mock-api'
|
import {bsky, AdxUri} from '@adxp/mock-api'
|
||||||
import moment from 'moment'
|
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {OnNavigateContent} from '../../routes/types'
|
import {OnNavigateContent} from '../../routes/types'
|
||||||
import {FeedViewItemModel} from '../../../state/models/feed-view'
|
import {FeedViewItemModel} from '../../../state/models/feed-view'
|
||||||
import {s} from '../../lib/styles'
|
import {s} from '../../lib/styles'
|
||||||
|
import {ago} from '../../lib/strings'
|
||||||
import {AVIS} from '../../lib/assets'
|
import {AVIS} from '../../lib/assets'
|
||||||
|
|
||||||
export const FeedItem = observer(function FeedItem({
|
export const FeedItem = observer(function FeedItem({
|
||||||
|
@ -78,7 +78,7 @@ export const FeedItem = observer(function FeedItem({
|
||||||
@{item.author.name}
|
@{item.author.name}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||||
· {moment(item.indexedAt).fromNow(true)}
|
· {ago(item.indexedAt)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text style={[styles.postText, s.f15, s['lh15-1.3']]}>
|
<Text style={[styles.postText, s.f15, s['lh15-1.3']]}>
|
||||||
|
|
|
@ -2,12 +2,11 @@ import React from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
|
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
|
||||||
import {bsky, AdxUri} from '@adxp/mock-api'
|
import {bsky, AdxUri} from '@adxp/mock-api'
|
||||||
import moment from 'moment'
|
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {OnNavigateContent} from '../../routes/types'
|
import {OnNavigateContent} from '../../routes/types'
|
||||||
import {PostThreadViewPostModel} from '../../../state/models/post-thread-view'
|
import {PostThreadViewPostModel} from '../../../state/models/post-thread-view'
|
||||||
import {s} from '../../lib/styles'
|
import {s} from '../../lib/styles'
|
||||||
import {pluralize} from '../../lib/strings'
|
import {ago, pluralize} from '../../lib/strings'
|
||||||
import {AVIS} from '../../lib/assets'
|
import {AVIS} from '../../lib/assets'
|
||||||
|
|
||||||
function iter<T>(n: number, fn: (_i: number) => T): Array<T> {
|
function iter<T>(n: number, fn: (_i: number) => T): Array<T> {
|
||||||
|
@ -97,7 +96,7 @@ export const PostThreadItem = observer(function PostThreadItem({
|
||||||
@{item.author.name}
|
@{item.author.name}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||||
· {moment(item.indexedAt).fromNow(true)}
|
· {ago(item.indexedAt)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text
|
<Text
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import moment from 'moment'
|
|
||||||
import {library} from '@fortawesome/fontawesome-svg-core'
|
import {library} from '@fortawesome/fontawesome-svg-core'
|
||||||
|
|
||||||
import {faArrowLeft} from '@fortawesome/free-solid-svg-icons/faArrowLeft'
|
import {faArrowLeft} from '@fortawesome/free-solid-svg-icons/faArrowLeft'
|
||||||
|
@ -16,26 +15,6 @@ import {faRetweet} from '@fortawesome/free-solid-svg-icons/faRetweet'
|
||||||
import {faX} from '@fortawesome/free-solid-svg-icons/faX'
|
import {faX} from '@fortawesome/free-solid-svg-icons/faX'
|
||||||
|
|
||||||
export function setup() {
|
export function setup() {
|
||||||
moment.updateLocale('en', {
|
|
||||||
relativeTime: {
|
|
||||||
future: 'in %s',
|
|
||||||
past: '%s ago',
|
|
||||||
s: 'a few seconds',
|
|
||||||
ss: '%ds',
|
|
||||||
m: 'a minute',
|
|
||||||
mm: '%dm',
|
|
||||||
h: 'an hour',
|
|
||||||
hh: '%dh',
|
|
||||||
d: 'a day',
|
|
||||||
dd: '%dd',
|
|
||||||
w: 'a week',
|
|
||||||
ww: '%dw',
|
|
||||||
M: 'a month',
|
|
||||||
MM: '%dmo',
|
|
||||||
y: 'a year',
|
|
||||||
yy: '%dy',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
library.add(
|
library.add(
|
||||||
faArrowLeft,
|
faArrowLeft,
|
||||||
faBars,
|
faBars,
|
||||||
|
|
|
@ -21,3 +21,35 @@ export function makeRecordUri(
|
||||||
urip.recordKey = recordKey
|
urip.recordKey = recordKey
|
||||||
return urip.toString()
|
return urip.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MINUTE = 60
|
||||||
|
const HOUR = MINUTE * 60
|
||||||
|
const DAY = HOUR * 24
|
||||||
|
const MONTH = DAY * 30
|
||||||
|
const YEAR = DAY * 365
|
||||||
|
export function ago(date: number | string | Date): string {
|
||||||
|
let ts: number
|
||||||
|
if (typeof date === 'string') {
|
||||||
|
ts = Number(new Date(date))
|
||||||
|
} else if (date instanceof Date) {
|
||||||
|
ts = Number(date)
|
||||||
|
} else {
|
||||||
|
ts = date
|
||||||
|
}
|
||||||
|
const diffSeconds = Math.floor((Date.now() - ts) / 1e3)
|
||||||
|
if (diffSeconds === 0) {
|
||||||
|
return 'just now'
|
||||||
|
} else if (diffSeconds < MINUTE) {
|
||||||
|
return `${diffSeconds}s`
|
||||||
|
} else if (diffSeconds < HOUR) {
|
||||||
|
return `${Math.floor(diffSeconds / MINUTE)}m`
|
||||||
|
} else if (diffSeconds < DAY) {
|
||||||
|
return `${Math.floor(diffSeconds / HOUR)}h`
|
||||||
|
} else if (diffSeconds < MONTH) {
|
||||||
|
return `${Math.floor(diffSeconds / DAY)}d`
|
||||||
|
} else if (diffSeconds < YEAR) {
|
||||||
|
return `${Math.floor(diffSeconds / MONTH)}mo`
|
||||||
|
} else {
|
||||||
|
return new Date(ts).toLocaleDateString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -12,5 +12,3 @@ Paul's todo list
|
||||||
- Linking
|
- Linking
|
||||||
- Web linking
|
- Web linking
|
||||||
- App linking
|
- App linking
|
||||||
- Housekeeping
|
|
||||||
- Remove moment.js -- it's too heavy a dependency
|
|
|
@ -9753,11 +9753,6 @@ mobx@^6.6.1:
|
||||||
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.6.1.tgz#70ee6aa82f25aeb7e7d522bd621207434e509318"
|
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.6.1.tgz#70ee6aa82f25aeb7e7d522bd621207434e509318"
|
||||||
integrity sha512-7su3UZv5JF+ohLr2opabjbUAERfXstMY+wiBtey8yNAPoB8H187RaQXuhFjNkH8aE4iHbDWnhDFZw0+5ic4nGQ==
|
integrity sha512-7su3UZv5JF+ohLr2opabjbUAERfXstMY+wiBtey8yNAPoB8H187RaQXuhFjNkH8aE4iHbDWnhDFZw0+5ic4nGQ==
|
||||||
|
|
||||||
moment@^2.29.4:
|
|
||||||
version "2.29.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
|
|
||||||
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
|
|
||||||
|
|
||||||
ms@2.0.0:
|
ms@2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||||
|
|
Loading…
Reference in New Issue