Replace moment with date-fns

This commit is contained in:
Ariful Alam 2022-05-19 19:38:55 +06:00
parent 36097918fd
commit 6b3d089b4b
4 changed files with 34 additions and 24 deletions

36
package-lock.json generated
View File

@ -18,11 +18,11 @@
"autoprefixer": "^10.4.4", "autoprefixer": "^10.4.4",
"axios": "^0.26.1", "axios": "^0.26.1",
"daisyui": "^2.11.0", "daisyui": "^2.11.0",
"date-fns": "^2.28.0",
"eslint": "^8.11.0", "eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4", "eslint-plugin-react": "^7.29.4",
"moment": "^2.29.1",
"postcss": "^8.4.12", "postcss": "^8.4.12",
"prettier": "^2.6.0", "prettier": "^2.6.0",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
@ -1087,6 +1087,19 @@
"postcss": "^8.1.6" "postcss": "^8.1.6"
} }
}, },
"node_modules/date-fns": {
"version": "2.28.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
"dev": true,
"engines": {
"node": ">=0.11"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/date-fns"
}
},
"node_modules/debug": { "node_modules/debug": {
"version": "4.3.4", "version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -2757,15 +2770,6 @@
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true "dev": true
}, },
"node_modules/moment": {
"version": "2.29.3",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz",
"integrity": "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==",
"dev": true,
"engines": {
"node": "*"
}
},
"node_modules/ms": { "node_modules/ms": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -4709,6 +4713,12 @@
"tailwindcss": "^3.0" "tailwindcss": "^3.0"
} }
}, },
"date-fns": {
"version": "2.28.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
"dev": true
},
"debug": { "debug": {
"version": "4.3.4", "version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -5838,12 +5848,6 @@
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true "dev": true
}, },
"moment": {
"version": "2.29.3",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz",
"integrity": "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==",
"dev": true
},
"ms": { "ms": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",

View File

@ -47,11 +47,11 @@
"autoprefixer": "^10.4.4", "autoprefixer": "^10.4.4",
"axios": "^0.26.1", "axios": "^0.26.1",
"daisyui": "^2.11.0", "daisyui": "^2.11.0",
"date-fns": "^2.28.0",
"eslint": "^8.11.0", "eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4", "eslint-plugin-react": "^7.29.4",
"moment": "^2.29.1",
"postcss": "^8.4.12", "postcss": "^8.4.12",
"prettier": "^2.6.0", "prettier": "^2.6.0",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",

View File

@ -1,6 +1,5 @@
import axios from 'axios'; import axios from 'axios';
import { Fragment, useCallback, useEffect, useState } from 'react'; import { Fragment, useCallback, useEffect, useState } from 'react';
import moment from 'moment';
import HeadTagEditor from './head-tag-editor'; import HeadTagEditor from './head-tag-editor';
import ErrorPage from './error-page'; import ErrorPage from './error-page';
import ThemeChanger from './theme-changer'; import ThemeChanger from './theme-changer';
@ -23,6 +22,7 @@ import {
import { HelmetProvider } from 'react-helmet-async'; import { HelmetProvider } from 'react-helmet-async';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import '../assets/index.css'; import '../assets/index.css';
import { formatDistance } from 'date-fns';
const GitProfile = ({ config }) => { const GitProfile = ({ config }) => {
const [error, setError] = useState( const [error, setError] = useState(
@ -103,9 +103,13 @@ const GitProfile = ({ config }) => {
const handleError = (error) => { const handleError = (error) => {
console.error('Error:', error); console.error('Error:', error);
try { try {
let reset = moment( let reset = formatDistance(
new Date(error.response.headers['x-ratelimit-reset'] * 1000) new Date(error.response.headers['x-ratelimit-reset'] * 1000),
).fromNow(); new Date(),
{
addSuffix: true,
}
);
if (error.response.status === 403) { if (error.response.status === 403) {
setError(tooManyRequestError(reset)); setError(tooManyRequestError(reset));
@ -129,7 +133,7 @@ const GitProfile = ({ config }) => {
social={sanitizedConfig.social} social={sanitizedConfig.social}
/> />
)} )}
<div className="fade-in h-screen"> <div className="fade-in">
{error ? ( {error ? (
<ErrorPage <ErrorPage
status={`${error.status}`} status={`${error.status}`}

View File

@ -1,10 +1,10 @@
import moment from 'moment';
import { Fragment, useEffect, useState } from 'react'; import { Fragment, useEffect, useState } from 'react';
import { ga, skeleton } from '../../helpers/utils'; import { ga, skeleton } from '../../helpers/utils';
import LazyImage from '../lazy-image'; import LazyImage from '../lazy-image';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { AiOutlineContainer } from 'react-icons/ai'; import { AiOutlineContainer } from 'react-icons/ai';
import { getDevPost, getMediumPost } from '@arifszn/blog-js'; import { getDevPost, getMediumPost } from '@arifszn/blog-js';
import { formatDistance } from 'date-fns';
const displaySection = (blog) => { const displaySection = (blog) => {
if ( if (
@ -147,7 +147,9 @@ const Blog = ({ loading, blog, googleAnalytics }) => {
{article.title} {article.title}
</h2> </h2>
<p className="opacity-50 text-xs"> <p className="opacity-50 text-xs">
{moment(article.publishedAt).fromNow()} {formatDistance(article.publishedAt, new Date(), {
addSuffix: true,
})}
</p> </p>
<p className="mt-3 text-base-content text-opacity-60 text-sm"> <p className="mt-3 text-base-content text-opacity-60 text-sm">
{article.description} {article.description}