From 09f9fa6ffc548364c8c32ae3dd18a7b33e46ec8b Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Mon, 14 Aug 2023 18:21:14 +0200 Subject: [PATCH 01/11] fix warnings --- package.json | 2 +- src/components/modals/SettingsModal.jsx | 1 - yarn.lock | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a43351d3..b1019aa4 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ } }, "devDependencies": { - "@babel/plugin-proposal-private-property-in-object": "7.21.11", + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@capacitor/cli": "3.6.0", "concurrently": "8.0.1", "cordova-res": "0.15.4", diff --git a/src/components/modals/SettingsModal.jsx b/src/components/modals/SettingsModal.jsx index 061a5c56..fceb7528 100755 --- a/src/components/modals/SettingsModal.jsx +++ b/src/components/modals/SettingsModal.jsx @@ -1,7 +1,6 @@ import React, { useState, useEffect, useRef } from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import Modal from "react-modal"; -import { confirmAlert } from "react-confirm-alert"; import { deleteAccount, deleteCaches, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts, useResolvedAuthorAddress } from "@plebbit/plebbit-react-hooks"; import { StyledModal } from "../styled/modals/SettingsModal.styled"; import useError from "../../hooks/useError"; diff --git a/yarn.lock b/yarn.lock index ab7eeb01..0ac64f8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -399,7 +399,7 @@ resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz#7844f9289546efa9febac2de4cfe358a050bd703" integrity sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w== -"@babel/plugin-proposal-private-property-in-object@7.21.11": +"@babel/plugin-proposal-private-property-in-object@^7.21.11": version "7.21.11" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz#69d597086b6760c4126525cfa154f34631ff272c" integrity sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw== From e27c834089a55001e24c283f81f5c87ba4716f7f Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Tue, 15 Aug 2023 09:55:36 +0200 Subject: [PATCH 02/11] upgrade virtuoso --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b1019aa4..990d4f51 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "react-scripts": "5.0.1", "react-toastify": "9.1.1", "react-tooltip": "5.10.0", - "react-virtuoso": "4.3.2", + "react-virtuoso": "4.5.0", "rehype-sanitize": "5.0.1", "remark-breaks": "3.0.2", "styled-components": "5.3.9", diff --git a/yarn.lock b/yarn.lock index 0ac64f8e..896338a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12496,10 +12496,10 @@ react-tooltip@5.10.0: "@floating-ui/dom" "1.2.3" classnames "^2.3.2" -react-virtuoso@4.3.2: - version "4.3.2" - resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-4.3.2.tgz#91d4926c67f635cf7efc2dea29e7cd6de83575d1" - integrity sha512-n51V4fMk36VM6NapfaMbfs4w/IaVodp5asp+rtzlvz0yurG6uVrqA040ke43gpYtoOL6j6TxeXWo4b6GpO9N0A== +react-virtuoso@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-4.5.0.tgz#0bc043b4e3e928e7891aa541dd7e55d5b46db8c8" + integrity sha512-OMP6XrzJMMos1vbJZC16RxGW7utAxUMP7i5PNPi6epBNVH7nz+CF/DlmecNBep5wyjLud51dQ5epjb2A0w9W/Q== react@18.2.0: version "18.2.0" From 296284aaa30c9df7df83816f61dc24d85aa91019 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Tue, 15 Aug 2023 09:57:53 +0200 Subject: [PATCH 03/11] fix mod actions state to enable unpin and unlock --- src/components/modals/ModerationModal.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/modals/ModerationModal.jsx b/src/components/modals/ModerationModal.jsx index 9188516a..0c560045 100755 --- a/src/components/modals/ModerationModal.jsx +++ b/src/components/modals/ModerationModal.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import Modal from "react-modal"; import { Link } from "react-router-dom"; -import { usePublishCommentEdit } from "@plebbit/plebbit-react-hooks"; +import { useComment, usePublishCommentEdit } from "@plebbit/plebbit-react-hooks"; import { StyledModal } from "../styled/modals/ModerationModal.styled"; import useGeneralStore from "../../hooks/stores/useGeneralStore"; import useError from "../../hooks/useError"; @@ -20,9 +20,11 @@ const ModerationModal = ({ isOpen, closeModal, deletePost }) => { setResolveCaptchaPromise, } = useGeneralStore(state => state); - const [pin, setPin] = useState(false); + const comment = useComment({commentCid: moderatingCommentCid}); + + const [pin, setPin] = useState(comment?.pinned); const [deleteThread, setDeleteThread] = useState(deletePost); - const [close, setClose] = useState(false); + const [close, setClose] = useState(comment?.locked); const [reason, setReason] = useState(''); const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false); From 092059f223b431510f577ec9ec50b1851cf2f925 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Tue, 15 Aug 2023 17:31:31 +0200 Subject: [PATCH 04/11] fix mobile board selector --- src/components/views/Board.jsx | 3 +++ src/components/views/Catalog.jsx | 3 +++ src/components/views/Description.jsx | 3 +++ src/components/views/Pending.jsx | 3 +++ src/components/views/Rules.jsx | 3 +++ src/components/views/Thread.jsx | 3 +++ 6 files changed, 18 insertions(+) diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 4c39ceec..02d51e16 100755 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -786,6 +786,9 @@ const Board = () => { + {!defaultSubplebbits.some(subplebbit => subplebbit.address === selectedAddress) && ( + + )} {defaultSubplebbits.map(subplebbit => ( diff --git a/src/components/views/Description.jsx b/src/components/views/Description.jsx index c2af6868..5db65494 100644 --- a/src/components/views/Description.jsx +++ b/src/components/views/Description.jsx @@ -195,6 +195,9 @@ const Description = () => { + {!defaultSubplebbits.some(subplebbit => subplebbit.address === selectedAddress) && ( + + )} {defaultSubplebbits.map(subplebbit => ( diff --git a/src/components/views/Rules.jsx b/src/components/views/Rules.jsx index 78a98873..f75e8e59 100644 --- a/src/components/views/Rules.jsx +++ b/src/components/views/Rules.jsx @@ -201,6 +201,9 @@ const Rules = () => { + {!defaultSubplebbits.some(subplebbit => subplebbit.address === selectedAddress) && ( + + )} {defaultSubplebbits.map(subplebbit => ( From 6831b26945cd8268de7950619d63e89fff81744b Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Wed, 16 Aug 2023 08:51:28 +0200 Subject: [PATCH 05/11] fix settings route in description and rules --- src/components/views/Description.jsx | 6 +++--- src/components/views/Rules.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/views/Description.jsx b/src/components/views/Description.jsx index 5db65494..2ec02f19 100644 --- a/src/components/views/Description.jsx +++ b/src/components/views/Description.jsx @@ -181,7 +181,7 @@ const Description = () => { }>Create Board ] [ - setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings ] [ Home @@ -210,7 +210,7 @@ const Description = () => { }>Create Board
- setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings   {handleStyleChange({target: {value: "Yotsuba"}}); window.scrollTo(0, 0);}}>Home
@@ -496,7 +496,7 @@ const Description = () => { }>Create Board ] [ - setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings ] [ handleStyleChange({target: {value: "Yotsuba"}} diff --git a/src/components/views/Rules.jsx b/src/components/views/Rules.jsx index f75e8e59..9a30371b 100644 --- a/src/components/views/Rules.jsx +++ b/src/components/views/Rules.jsx @@ -187,7 +187,7 @@ const Rules = () => { }>Create Board ] [ - setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings ] [ Home @@ -216,7 +216,7 @@ const Rules = () => { }>Create Board
- setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings   {handleStyleChange({target: {value: "Yotsuba"}}); window.scrollTo(0, 0);}}>Home
@@ -494,7 +494,7 @@ const Rules = () => { }>Create Board ] [ - setIsSettingsOpen(true)}>Settings + setIsSettingsOpen(true)}>Settings ] [ handleStyleChange({target: {value: "Yotsuba"}} From 9b663345776c9198bfeba5409e7d920513e54f2d Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Wed, 16 Aug 2023 16:49:44 +0200 Subject: [PATCH 06/11] fix eslint --- src/components/views/Description.jsx | 1 - src/components/views/Rules.jsx | 1 - 2 files changed, 2 deletions(-) diff --git a/src/components/views/Description.jsx b/src/components/views/Description.jsx index 2ec02f19..19aa2605 100644 --- a/src/components/views/Description.jsx +++ b/src/components/views/Description.jsx @@ -28,7 +28,6 @@ const Description = () => { isSettingsOpen, setIsSettingsOpen, selectedAddress, setSelectedAddress, selectedStyle, - selectedThread, setSelectedTitle, } = useGeneralStore(state => state); diff --git a/src/components/views/Rules.jsx b/src/components/views/Rules.jsx index 9a30371b..ecdb6952 100644 --- a/src/components/views/Rules.jsx +++ b/src/components/views/Rules.jsx @@ -26,7 +26,6 @@ const Rules = () => { isSettingsOpen, setIsSettingsOpen, selectedAddress, setSelectedAddress, selectedStyle, - selectedThread, setSelectedTitle, } = useGeneralStore(state => state); From 9085e235e132bfaa3789729840a616754be20f9f Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 17 Aug 2023 13:15:37 +0200 Subject: [PATCH 07/11] add tooltip for post dates --- package.json | 1 + src/components/views/All.jsx | 21 ++++++++-- src/components/views/Board.jsx | 53 +++++++++++++++++++++----- src/components/views/Subscriptions.jsx | 21 ++++++++-- src/components/views/Thread.jsx | 23 +++++++++-- src/utils/getFormattedTime.js | 14 +++++++ yarn.lock | 14 ++++++- 7 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 src/utils/getFormattedTime.js diff --git a/package.json b/package.json index 990d4f51..bcaf0e0a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "eslint": "8.36.0", "eslint-config-react-app": "7.0.1", "ext-name": "5.0.0", + "javascript-time-ago": "^2.5.9", "lodash": "4.17.21", "mock-require": "3.0.3", "postcss": "8.4.21", diff --git a/src/components/views/All.jsx b/src/components/views/All.jsx index 01a647c5..3bfee60e 100755 --- a/src/components/views/All.jsx +++ b/src/components/views/All.jsx @@ -29,6 +29,7 @@ import SettingsModal from '../modals/SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import getFormattedTime from '../../utils/getFormattedTime'; import handleAddressClick from '../../utils/handleAddressClick'; import handleImageClick from '../../utils/handleImageClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; @@ -851,7 +852,10 @@ const All = () => { {{({ shortAuthorAddress }) => (shortAuthorAddress)}} )   - {getDate(thread.timestamp)} + {getDate(thread.timestamp)}   c/ @@ -1179,7 +1183,10 @@ const All = () => {   - {getDate(reply.timestamp)} + {getDate(reply.timestamp)}   c/ @@ -1778,7 +1785,10 @@ const All = () => { tooltipPlace="top" className="offline-mobile-sub" /> - + {getDate(thread.timestamp)}   c/ @@ -2016,7 +2026,10 @@ const All = () => { tooltipPlace="top" className="offline-mobile-sub-reply" /> - + {getDate(reply.timestamp)}  c/ {reply.shortCid ? ( diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 02d51e16..15e82c62 100755 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -30,6 +30,7 @@ import SettingsModal from '../modals/SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import getFormattedTime from '../../utils/getFormattedTime'; import handleAddressClick from '../../utils/handleAddressClick'; import handleImageClick from '../../utils/handleImageClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; @@ -953,7 +954,10 @@ const Board = () => { onClick={() => {setIsAdminListOpen(!isAdminListOpen)}} >## Board Admins   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}   Sticky @@ -1043,7 +1047,10 @@ const Board = () => { style={{marginBottom: "-15px"}}>Rules   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}  
@@ -1078,7 +1085,10 @@ const Board = () => { onClick={() => {setIsAdminListOpen(!isAdminListOpen)}} >## Board Admins   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}   Sticky @@ -1168,7 +1178,10 @@ const Board = () => { style={{marginBottom: "-15px"}}>Rules   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}  
@@ -1225,7 +1238,10 @@ const Board = () => { onClick={() => {setIsAdminListOpen(!isAdminListOpen)}} >## Board Admins   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}   Sticky @@ -1313,7 +1329,10 @@ const Board = () => { style={{marginBottom: "-15px"}}>Welcome to {subplebbit.title || subplebbit.address}   - {getDate(subplebbit.createdAt)} + {getDate(subplebbit.createdAt)}   {subplebbit.suggested?.avatarUrl ? ( @@ -1513,7 +1532,12 @@ const Board = () => { {({ shortAuthorAddress }) => (shortAuthorAddress)} )   - {getDate(thread.timestamp)} + + {getDate(thread.timestamp)} +   c/ @@ -1856,7 +1880,10 @@ const Board = () => {   - {getDate(reply.timestamp)} + {getDate(reply.timestamp)}   c/ @@ -2429,7 +2456,10 @@ const Board = () => { ) : null} - + {getDate(thread.timestamp)}   c/ @@ -2656,7 +2686,10 @@ const Board = () => {
- + {getDate(reply.timestamp)}  c/ {reply.shortCid ? ( diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx index 40829f72..6e674085 100755 --- a/src/components/views/Subscriptions.jsx +++ b/src/components/views/Subscriptions.jsx @@ -30,6 +30,7 @@ import SettingsModal from '../modals/SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import getFormattedTime from '../../utils/getFormattedTime'; import handleAddressClick from '../../utils/handleAddressClick'; import handleImageClick from '../../utils/handleImageClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; @@ -862,7 +863,10 @@ const Subscriptions = () => { {{({ shortAuthorAddress }) => (shortAuthorAddress)}} )   - {getDate(thread.timestamp)} + {getDate(thread.timestamp)}   c/ @@ -1190,7 +1194,10 @@ const Subscriptions = () => {   - {getDate(reply.timestamp)} + {getDate(reply.timestamp)}   c/ @@ -1789,7 +1796,10 @@ const Subscriptions = () => { tooltipPlace="top" className="offline-mobile-sub" /> - + {getDate(thread.timestamp)}   c/ @@ -2027,7 +2037,10 @@ const Subscriptions = () => { tooltipPlace="top" className="offline-mobile-sub-reply" /> - + {getDate(reply.timestamp)}  c/ {reply.shortCid ? ( diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index edc69436..541530f8 100755 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -28,6 +28,7 @@ import SettingsModal from '../modals/SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import getFormattedTime from '../../utils/getFormattedTime'; import handleAddressClick from '../../utils/handleAddressClick'; import handleImageClick from '../../utils/handleImageClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; @@ -998,7 +999,12 @@ const Thread = () => { )   - {getDate(comment?.timestamp)} + + {getDate(comment?.timestamp)} +   c/ @@ -1295,7 +1301,10 @@ const Thread = () => {   - + {getDate(reply?.timestamp)}  c/ @@ -1750,7 +1759,10 @@ const Thread = () => { {comment.title} ) : null} - + {getDate(comment?.timestamp)}   c/ @@ -1943,7 +1955,10 @@ const Thread = () => {
- + {getDate(reply?.timestamp)}  c/ {reply.shortCid ? ( diff --git a/src/utils/getFormattedTime.js b/src/utils/getFormattedTime.js new file mode 100644 index 00000000..3f301819 --- /dev/null +++ b/src/utils/getFormattedTime.js @@ -0,0 +1,14 @@ +import en from 'javascript-time-ago/locale/en' +import TimeAgo from 'javascript-time-ago' + +TimeAgo.addDefaultLocale(en); +const timeAgo = new TimeAgo('en-US'); + +const getFormattedTime = (timestamp) => { + try { + return timeAgo.format(timestamp * 1000) + } + catch (e) {} +}; + +export default getFormattedTime; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 896338a8..12a1c00f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8997,6 +8997,13 @@ jake@^10.8.5: filelist "^1.0.4" minimatch "^3.1.2" +javascript-time-ago@^2.5.9: + version "2.5.9" + resolved "https://registry.yarnpkg.com/javascript-time-ago/-/javascript-time-ago-2.5.9.tgz#3c5d8012cd493d764c6b26a0ffe6e8b20afcf1fe" + integrity sha512-pQ8mNco/9g9TqWXWWjP0EWl6i/lAQScOyEeXy5AB+f7MfLSdgyV9BJhiOD1zrIac/lrxPYOWNbyl/IW8CW5n0A== + dependencies: + relative-time-format "^1.1.6" + jest-changed-files@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-27.5.1.tgz#a348aed00ec9bf671cc58a66fcbe7c3dfd6a68f5" @@ -12496,7 +12503,7 @@ react-tooltip@5.10.0: "@floating-ui/dom" "1.2.3" classnames "^2.3.2" -react-virtuoso@^4.5.0: +react-virtuoso@4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-4.5.0.tgz#0bc043b4e3e928e7891aa541dd7e55d5b46db8c8" integrity sha512-OMP6XrzJMMos1vbJZC16RxGW7utAxUMP7i5PNPi6epBNVH7nz+CF/DlmecNBep5wyjLud51dQ5epjb2A0w9W/Q== @@ -12700,6 +12707,11 @@ relateurl@^0.2.7: resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog== +relative-time-format@^1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/relative-time-format/-/relative-time-format-1.1.6.tgz#724a5fbc3794b8e0471b6b61419af2ce699eb9f1" + integrity sha512-aCv3juQw4hT1/P/OrVltKWLlp15eW1GRcwP1XdxHrPdZE9MtgqFpegjnTjLhi2m2WI9MT/hQQtE+tjEWG1hgkQ== + remark-breaks@3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/remark-breaks/-/remark-breaks-3.0.2.tgz#f466b9d3474d7323146c0149fc1496dabadd908e" From e76f6a3fe3cb77fa651954f3f96b245e9c97955a Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 17 Aug 2023 13:29:46 +0200 Subject: [PATCH 08/11] add precise date time function --- package.json | 1 - src/utils/getFormattedTime.js | 39 ++++++++++++++++++++++++++++------- yarn.lock | 12 ----------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index bcaf0e0a..990d4f51 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "eslint": "8.36.0", "eslint-config-react-app": "7.0.1", "ext-name": "5.0.0", - "javascript-time-ago": "^2.5.9", "lodash": "4.17.21", "mock-require": "3.0.3", "postcss": "8.4.21", diff --git a/src/utils/getFormattedTime.js b/src/utils/getFormattedTime.js index 3f301819..82545135 100644 --- a/src/utils/getFormattedTime.js +++ b/src/utils/getFormattedTime.js @@ -1,14 +1,39 @@ -import en from 'javascript-time-ago/locale/en' -import TimeAgo from 'javascript-time-ago' - -TimeAgo.addDefaultLocale(en); -const timeAgo = new TimeAgo('en-US'); +const pluralize = (unit, value) => { + return `${value} ${unit}${value > 1 ? 's' : ''}`; +}; const getFormattedTime = (timestamp) => { try { - return timeAgo.format(timestamp * 1000) + const currentTime = new Date().getTime(); + const differenceInMilliseconds = currentTime - (timestamp * 1000); + + const years = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 365.25)); + const months = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 365.25)) / (1000 * 60 * 60 * 24 * 30)); + const days = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 30)) / (1000 * 60 * 60 * 24)); + const hours = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + const minutes = Math.floor((differenceInMilliseconds % (1000 * 60 * 60)) / (1000 * 60)); + const seconds = Math.floor((differenceInMilliseconds % (1000 * 60)) / 1000); + + if (years > 0) { + return months > 0 ? `${pluralize('year', years)} and ${pluralize('month', months)} ago` : `${pluralize('year', years)} ago`; + } else if (months > 0) { + return `${pluralize('month', months)} and ${pluralize('day', days)} ago`; + } else if (days > 0) { + return `${pluralize('day', days)} and ${pluralize('hour', hours)} ago`; + } else if (hours > 0) { + return `${pluralize('hour', hours)} and ${pluralize('minute', minutes)} ago`; + } else if (minutes > 0) { + return `${pluralize('minute', minutes)} and ${pluralize('second', seconds)} ago`; + } else if (seconds > 30) { + return `${pluralize('second', seconds)} ago`; + } else { + return "just now"; + } + } + catch (e) { + console.error("Error in getFormattedTime:", e); + return "[error]"; } - catch (e) {} }; export default getFormattedTime; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 12a1c00f..62e757e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8997,13 +8997,6 @@ jake@^10.8.5: filelist "^1.0.4" minimatch "^3.1.2" -javascript-time-ago@^2.5.9: - version "2.5.9" - resolved "https://registry.yarnpkg.com/javascript-time-ago/-/javascript-time-ago-2.5.9.tgz#3c5d8012cd493d764c6b26a0ffe6e8b20afcf1fe" - integrity sha512-pQ8mNco/9g9TqWXWWjP0EWl6i/lAQScOyEeXy5AB+f7MfLSdgyV9BJhiOD1zrIac/lrxPYOWNbyl/IW8CW5n0A== - dependencies: - relative-time-format "^1.1.6" - jest-changed-files@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-27.5.1.tgz#a348aed00ec9bf671cc58a66fcbe7c3dfd6a68f5" @@ -12707,11 +12700,6 @@ relateurl@^0.2.7: resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog== -relative-time-format@^1.1.6: - version "1.1.6" - resolved "https://registry.yarnpkg.com/relative-time-format/-/relative-time-format-1.1.6.tgz#724a5fbc3794b8e0471b6b61419af2ce699eb9f1" - integrity sha512-aCv3juQw4hT1/P/OrVltKWLlp15eW1GRcwP1XdxHrPdZE9MtgqFpegjnTjLhi2m2WI9MT/hQQtE+tjEWG1hgkQ== - remark-breaks@3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/remark-breaks/-/remark-breaks-3.0.2.tgz#f466b9d3474d7323146c0149fc1496dabadd908e" From c558951d619030ca66e5a88f24d6c4b09abc9b43 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 17 Aug 2023 13:47:25 +0200 Subject: [PATCH 09/11] update seeding tip in home --- src/components/views/Home.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/views/Home.jsx b/src/components/views/Home.jsx index 246ad53a..1af4c395 100644 --- a/src/components/views/Home.jsx +++ b/src/components/views/Home.jsx @@ -108,8 +108,7 @@ const Home = () => {
-

Plebchan is a serverless, adminless, decentralized 4chan alternative that uses the plebbit protocol. Users do not need to register an account before participating in a community; anyone can post comments, share media links, and . All the content is just text, and plebchan's speed depends on how many users are seeding. Search for any board address above, or feel free to click on a popular board below that interests you and jump right in!

+ >create a board. All the content is just text, and plebchan's speed depends on how many users are . Search for any board address above, or feel free to click on a popular board below that interests you and jump right in!


There are no global rules, each board is completely independent and its owner decides how/if it should be moderated.

From c11ce2d5dd52229a9075729bfc0b6169545ec0d7 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 18 Aug 2023 13:44:39 +0200 Subject: [PATCH 10/11] fix markdown double newline --- src/components/Post.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Post.jsx b/src/components/Post.jsx index 431c05f6..2c160279 100644 --- a/src/components/Post.jsx +++ b/src/components/Post.jsx @@ -6,7 +6,7 @@ import ForwardRefLink from './ForwardRefLink'; const Post = ({ content, postQuoteOnClick, postQuoteOnOver, postQuoteOnLeave, postQuoteRef }) => { - const doubleNewlineContent = useMemo(() => content?.replaceAll(/\n(?!\n)/g, '\n\n'), [content]); + const doubleNewlineContent = content.replace(/\n/g, ' \n\n'); const customSchema = useMemo(() => ({ ...defaultSchema, From 6783efd76193b48acd373e32a008b5af6f2ccff1 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 18 Aug 2023 13:47:41 +0200 Subject: [PATCH 11/11] fix undefined --- src/components/Post.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Post.jsx b/src/components/Post.jsx index 2c160279..4d94e10c 100644 --- a/src/components/Post.jsx +++ b/src/components/Post.jsx @@ -6,7 +6,7 @@ import ForwardRefLink from './ForwardRefLink'; const Post = ({ content, postQuoteOnClick, postQuoteOnOver, postQuoteOnLeave, postQuoteRef }) => { - const doubleNewlineContent = content.replace(/\n/g, ' \n\n'); + const doubleNewlineContent = content?.replace(/\n/g, ' \n\n'); const customSchema = useMemo(() => ({ ...defaultSchema,