Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: change shown date according to sort options (#196)

Muhammad Alicd2ed0505c97
diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.js
index 40ef694e0..9bb57f0c1 100644
--- a/apps/web/src/common/list-profiles.js
+++ b/apps/web/src/common/list-profiles.js
@@ -18,7 +18,7 @@ function createProfile(item, itemHeight, estimatedItemHeight) {
}
const NotesProfile = createProfile(
- (index, item, context) => (
+ (index, item, type, context) => (
<Note
index={index}
pinnable={!context}
@@ -26,6 +26,7 @@ const NotesProfile = createProfile(
tags={getTags(item)}
notebook={getNotebook(item.notebooks, context?.type)}
attachments={getAttachmentsCount(item.id)}
+ date={getDate(item, type)}
context={context}
/>
),
@@ -34,8 +35,13 @@ const NotesProfile = createProfile(
);
const NotebooksProfile = createProfile(
- (index, item) => (
- <Notebook index={index} item={item} totalNotes={getTotalNotes(item)} />
+ (index, item, type) => (
+ <Notebook
+ index={index}
+ item={item}
+ totalNotes={getTotalNotes(item)}
+ date={getDate(item, type)}
+ />
),
getNotebookHeight,
MAX_HEIGHTS.notebook
@@ -60,7 +66,9 @@ const TopicsProfile = createProfile(
);
const TrashProfile = createProfile(
- (index, item) => <TrashItem index={index} item={item} />,
+ (index, item, type) => (
+ <TrashItem index={index} item={item} date={getDate(item, type)} />
+ ),
(item) => {
if (item.itemType === "note") return getNoteHeight(item);
else if (item.itemType === "notebook") return getNotebookHeight(item);
@@ -112,3 +120,19 @@ function getNotebook(notebooks, contextType) {
function getAttachmentsCount(noteId) {
return db.attachments.ofNote(noteId, "all").length;
}
+
+function getDate(item, groupType) {
+ const sortBy = db.settings.getGroupOptions(groupType).sortBy;
+ switch (sortBy) {
+ case "dateEdited":
+ return item.dateEdited;
+ case "dateCreated":
+ return item.dateCreated;
+ case "dateModified":
+ return item.dateModified;
+ case "dateDeleted":
+ return item.dateDeleted;
+ default:
+ return undefined;
+ }
+}
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js
index 2f5e8d40f..68ba98261 100644
--- a/apps/web/src/components/list-container/index.js
+++ b/apps/web/src/components/list-container/index.js
@@ -83,7 +83,7 @@ function ListContainer(props) {
/>
);
default:
- return profile.item(index, item, context);
+ return profile.item(index, item, groupType, context);
}
}}
/>
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index 27f7d02a2..2eb2c0315 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -17,7 +17,7 @@ import Vault from "../../common/vault";
import IconTag from "../icon-tag";
function Note(props) {
- const { tags, notebook, item, index, context, attachments } = props;
+ const { tags, notebook, item, index, context, attachments, date } = props;
const note = item;
const isOpened = useStore((store) => store.selectedNote === note.id);
const isCompact = useStore((store) => store.viewMode === "compact");
@@ -94,7 +94,7 @@ function Note(props) {
data-test-id={`note-${index}-locked`}
/>
)}
- <TimeAgo live={true} datetime={note.dateCreated} locale="short" />
+ <TimeAgo live={true} datetime={date} locale="short" />
</>
) : (
<>
@@ -106,7 +106,7 @@ function Note(props) {
sx={{ flexShrink: 0 }}
locale="en_short"
live={true}
- datetime={note.dateCreated}
+ datetime={date}
mr={1}
/>
@@ -170,6 +170,7 @@ export default React.memo(Note, function (prevProps, nextProps) {
const prevItem = prevProps.item;
const nextItem = nextProps.item;
return (
+ prevProps.date === nextProps.date &&
prevItem.pinned === nextItem.pinned &&
prevItem.favorite === nextItem.favorite &&
prevItem.headline === nextItem.headline &&
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 96f2eb226..a70eedbc4 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -11,7 +11,7 @@ import IconTag from "../icon-tag";
import { showToast } from "../../utils/toast";
function Notebook(props) {
- const { item, index, totalNotes } = props;
+ const { item, index, totalNotes, date } = props;
const notebook = item;
const isCompact = useStore((store) => store.viewMode === "compact");
@@ -63,10 +63,8 @@ function Notebook(props) {
<Text as="span" mx={1}>
•
</Text>
- {new Date(notebook.dateCreated).toLocaleDateString("en", {
- month: "long",
- day: "2-digit",
- year: "numeric",
+ {new Date(date).toLocaleDateString("en", {
+ dateStyle: "medium",
})}
<Text as="span" mx={1}>
•
@@ -86,6 +84,7 @@ export default React.memo(Notebook, (prev, next) => {
const nextItem = next.item;
return (
+ prev.date === next.date &&
prevItem.pinned === nextItem.pinned &&
prevItem.title === nextItem.title &&
prevItem.description === nextItem.description &&
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index 120c7c229..703a0fd4f 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -9,7 +9,7 @@ import { toTitleCase } from "../../utils/string";
import { showToast } from "../../utils/toast";
import { showPermanentDeleteToast } from "../../common/toasts";
-function TrashItem({ item, index }) {
+function TrashItem({ item, index, date }) {
return (
<ListItem
selectable
@@ -19,10 +19,7 @@ function TrashItem({ item, index }) {
index={index}
footer={
<Flex mt={1} sx={{ fontSize: "subBody", color: "fontTertiary" }}>
- <TimeAgo
- live={true}
- datetime={item.dateDeleted || item.dateCreated}
- />
+ <TimeAgo live={true} datetime={date} />
<Text as="span" mx={1}>
•
</Text>