Skip to content

Commit 7b27bd2

Browse files
authored
feat: edit indicator doesn't show unless after 5 minutes (#2061)
1 parent 5da19b5 commit 7b27bd2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/features/labels/Edited.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useIonAlert } from "@ionic/react";
2+
import { differenceInMinutes } from "date-fns";
23
import { pencil } from "ionicons/icons";
34
import { MouseEvent } from "react";
45
import { CommentView, PostView } from "threadiverse";
56

67
import Stat from "#/features/post/detail/Stat";
8+
import { isPost } from "#/helpers/lemmy";
79

810
import { formatRelativeToNow } from "./Ago";
911

@@ -18,28 +20,31 @@ interface EditedProps {
1820
export default function Edited({ item, showDate, className }: EditedProps) {
1921
const [present] = useIonAlert();
2022

21-
const edited = "comment" in item ? item.comment.updated : item.post.updated;
23+
const updated = isPost(item) ? item.post.updated : item.comment.updated;
2224

2325
const editedLabelIfNeeded = (() => {
24-
if (!edited) return;
26+
if (!updated) return;
2527
if (!showDate) return;
2628

27-
const createdLabel = formatRelativeToNow(new Date(item.counts.published));
28-
const editedLabel = formatRelativeToNow(new Date(edited));
29+
const created = new Date(item.counts.published);
30+
const edited = new Date(updated);
2931

30-
if (createdLabel === editedLabel) return;
32+
// Don't show as edited if changed within 5 minutes of creation
33+
if (differenceInMinutes(created, edited) < 5) return;
34+
35+
const editedLabel = formatRelativeToNow(edited);
3136

3237
return editedLabel;
3338
})();
3439

35-
if (!edited) return;
40+
if (!editedLabelIfNeeded) return;
3641

3742
function presentEdited(e: MouseEvent) {
3843
e.stopPropagation();
3944

40-
if (!edited) return;
45+
if (!updated) return;
4146

42-
const date = new Date(edited);
47+
const date = new Date(updated);
4348

4449
present({
4550
header: `Edited ${formatRelativeToNow(date)} Ago`,

0 commit comments

Comments
 (0)