Skip to content

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

feat: show dateEdited/dateCreated on items in list

ammarahm-ed10da8a1c945b
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index fc5a3c78d..4c97f1c0c 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -1,7 +1,7 @@
-import React, { useEffect } from 'react';
+import React, {useEffect} from 'react';
import {Platform, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { notesnook } from '../../../e2e/test.ids';
+import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import {useSettingStore, useTagStore} from '../../provider/stores';
import {eSendEvent} from '../../services/EventManager';
@@ -67,17 +67,18 @@ const showActionSheet = (item, isTrash) => {
'Vault',
'Delete',
'RemoveTopic',
- "History",
+ 'History',
...android
]
);
};
-const NoteItem = ({item, isTrash, tags}) => {
+const NoteItem = ({item, isTrash, tags, dateBy = 'dateCreated'}) => {
const [state] = useTracked();
const {colors} = state;
const settings = useSettingStore(state => state.settings);
const compactMode = settings.notesListMode === 'compact';
+ const attachmentCount = db.attachments?.ofNote(item.id)?.length || 0;
function getNotebook() {
if (isTrash || !item.notebooks || item.notebooks.length < 1) return [];
@@ -99,7 +100,7 @@ const NoteItem = ({item, isTrash, tags}) => {
}
];
}
-
+
return (
<>
<View
@@ -188,13 +189,13 @@ const NoteItem = ({item, isTrash, tags}) => {
color: colors.icon,
marginRight: 6
}}
- time={item.dateCreated}
+ time={item[dateBy]}
updateFrequency={
- Date.now() - item.dateCreated < 60000 ? 2000 : 60000
+ Date.now() - item[dateBy] < 60000 ? 2000 : 60000
}
/>
- {/* {db.attachments?.ofNote(item.id)?.length === 0 ? (
+ {attachmentCount > 0 ? (
<View
style={{
flexDirection: 'row',
@@ -203,10 +204,10 @@ const NoteItem = ({item, isTrash, tags}) => {
}}>
<Icon name="attachment" size={SIZE.md} color={colors.icon} />
<Paragraph color={colors.icon} size={SIZE.xs}>
- 10
+ {attachmentCount}
</Paragraph>
</View>
- ) : null} */}
+ ) : null}
{item.pinned ? (
<Icon
diff --git a/apps/mobile/src/components/NoteItem/wrapper.js b/apps/mobile/src/components/NoteItem/wrapper.js
index 442a672d9..9e713f769 100644
--- a/apps/mobile/src/components/NoteItem/wrapper.js
+++ b/apps/mobile/src/components/NoteItem/wrapper.js
@@ -1,22 +1,21 @@
import React from 'react';
import NoteItem from '.';
-import { notesnook } from '../../../e2e/test.ids';
-import { useSelectionStore, useTrashStore } from '../../provider/stores';
-import { DDS } from '../../services/DeviceDetection';
-import { eSendEvent, openVault, ToastEvent } from '../../services/EventManager';
+import {notesnook} from '../../../e2e/test.ids';
+import {useSelectionStore, useTrashStore} from '../../provider/stores';
+import {DDS} from '../../services/DeviceDetection';
+import {eSendEvent, openVault, ToastEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
-import { history } from '../../utils';
-import { db } from '../../utils/database';
-import { eOnLoadNote, eShowMergeDialog } from '../../utils/Events';
-import { tabBarRef } from '../../utils/Refs';
-import { presentDialog } from '../Dialog/functions';
+import {history} from '../../utils';
+import {db} from '../../utils/database';
+import {eOnLoadNote, eShowMergeDialog} from '../../utils/Events';
+import {tabBarRef} from '../../utils/Refs';
+import {presentDialog} from '../Dialog/functions';
import SelectionWrapper from '../SelectionWrapper';
export const NoteWrapper = React.memo(
- ({item, index, tags, compactMode}) => {
+ ({item, index, tags, compactMode, dateBy}) => {
const isTrash = item.type === 'trash';
const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
-
const onPress = async () => {
let _note = item;
if (!isTrash) {
@@ -94,19 +93,19 @@ export const NoteWrapper = React.memo(
testID={notesnook.ids.note.get(index)}
onPress={onPress}
item={item}>
- <NoteItem item={item} tags={tags} isTrash={isTrash} />
+ <NoteItem item={item} dateBy={dateBy} tags={tags} isTrash={isTrash} />
</SelectionWrapper>
);
},
(prev, next) => {
-
+ if (prev.dateBy !== next.dateBy ) {
+ return false;
+ }
if (prev.item?.dateEdited !== next.item?.dateEdited) {
return false;
}
- if (
- JSON.stringify(prev.tags) !== JSON.stringify(next.tags)
- ) {
+ if (JSON.stringify(prev.tags) !== JSON.stringify(next.tags)) {
return false;
}
diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js
index fd298e323..8975acec2 100644
--- a/apps/mobile/src/components/NotebookItem/index.js
+++ b/apps/mobile/src/components/NotebookItem/index.js
@@ -1,210 +1,213 @@
-import React, { useEffect } from 'react';
-import {View} from 'react-native';
+import React from 'react';
+import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {notesnook} from '../../../e2e/test.ids';
-import {useTracked} from '../../provider';
-import {useSettingStore} from '../../provider/stores';
-import {eSendEvent} from '../../services/EventManager';
+import { notesnook } from '../../../e2e/test.ids';
+import { useTracked } from '../../provider';
+import { useSettingStore } from '../../provider/stores';
+import { eSendEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
-import {getTotalNotes, history} from '../../utils';
-import {refreshNotesPage} from '../../utils/Events';
-import {SIZE} from '../../utils/SizeUtils';
-import {ActionIcon} from '../ActionIcon';
-import {Button} from '../Button';
-import {ActionSheetEvent} from '../DialogManager/recievers';
+import { getTotalNotes, history } from '../../utils';
+import { refreshNotesPage } from '../../utils/Events';
+import { SIZE } from '../../utils/SizeUtils';
+import { ActionIcon } from '../ActionIcon';
+import { Button } from '../Button';
+import { ActionSheetEvent } from '../DialogManager/recievers';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
-export const NotebookItem = ({item, isTopic = false, notebookID, isTrash}) => {
- const [state] = useTracked();
- const {colors} = state;
- const settings = useSettingStore(state => state.settings);
- const compactMode = settings.notebooksListMode === 'compact';
+export const NotebookItem = ({
+ item,
+ isTopic = false,
+ notebookID,
+ isTrash,
+ dateBy
+}) => {
+ const [state] = useTracked();
+ const {colors} = state;
+ const settings = useSettingStore(state => state.settings);
+ const compactMode = settings.notebooksListMode === 'compact';
+ const topics = item.topics?.slice(0, 3) || [];
+ const totalNotes = getTotalNotes(item);
+ const showActionSheet = () => {
+ let rowItems =
+ item.type === 'topic'
+ ? ['Edit Topic', 'Add Shortcut', 'Delete']
+ : ['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete'];
+ rowItems = isTrash ? ['Restore', 'PermDelete'] : rowItems;
- const topics = item.topics?.slice(0, 3) || [];
+ ActionSheetEvent(item, false, false, rowItems, {
+ notebookID: notebookID
+ });
+ };
- const totalNotes = getTotalNotes(item);
- const showActionSheet = () => {
- let rowItems =
- item.type === 'topic'
- ? ['Edit Topic', 'Add Shortcut', 'Delete']
- : ['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete'];
- rowItems = isTrash ? ['Restore', 'PermDelete'] : rowItems;
-
- ActionSheetEvent(item, false, false, rowItems, {
- notebookID: notebookID
- });
- };
-
- const navigateToTopic = topic => {
- if (history.selectedItemsList.length > 0) return;
- let routeName = 'NotesPage';
- let params = {...topic, menu: false, get: 'topics'};
- let headerState = {
- heading: topic.title,
- id: topic.id,
- type: topic.type
- };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
+ const navigateToTopic = topic => {
+ if (history.selectedItemsList.length > 0) return;
+ let routeName = 'NotesPage';
+ let params = {...topic, menu: false, get: 'topics'};
+ let headerState = {
+ heading: topic.title,
+ id: topic.id,
+ type: topic.type
};
+ eSendEvent(refreshNotesPage, params);
+ Navigation.navigate(routeName, params, headerState);
+ };
-
- return (
- <>
- <View
+ return (
+ <>
+ <View
+ style={{
+ flexGrow: 1,
+ flexShrink: 1
+ }}>
+ <Heading
+ size={SIZE.md}
+ numberOfLines={1}
style={{
- flexGrow: 1,
- flexShrink: 1
+ flexWrap: 'wrap'
}}>
- <Heading
- size={SIZE.md}
- numberOfLines={1}
+ {item.title}
+ </Heading>
+ {isTopic || !item.description || compactMode ? null : (
+ <Paragraph
+ size={SIZE.sm}
+ numberOfLines={2}
style={{
flexWrap: 'wrap'
}}>
- {item.title}
- </Heading>
- {isTopic || !item.description || compactMode ? null : (
- <Paragraph
- size={SIZE.sm}
- numberOfLines={2}
- style={{
- flexWrap: 'wrap'
- }}>
- {item.description}
- </Paragraph>
- )}
-
- {isTopic || compactMode ? null : (
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- flexWrap: 'wrap'
- }}>
- {topics.map(topic => (
- <Button
- title={topic.title}
- key={topic.id}
- height={null}
- textStyle={{
- fontWeight: 'normal',
- fontFamily: null
- }}
- type="grayBg"
- fontSize={SIZE.xs}
- icon="bookmark-outline"
- textStyle={{
- marginRight: 0
- }}
- iconSize={SIZE.sm}
- style={{
- borderRadius: 5,
- maxWidth: 120,
- borderWidth: 0.5,
- paddingVertical: 2.5,
- borderColor: colors.icon,
- paddingHorizontal: 6,
- marginVertical: 5,
- marginRight: 5
- }}
- onPress={() => navigateToTopic(topic)}
- />
- ))}
- </View>
- )}
+ {item.description}
+ </Paragraph>
+ )}
+ {isTopic || compactMode ? null : (
<View
style={{
flexDirection: 'row',
- justifyContent: 'flex-start',
alignItems: 'center',
- marginTop: 5,
- height: SIZE.md + 2
+ flexWrap: 'wrap'
}}>
- <Paragraph
- color={colors.accent}
- size={SIZE.xs}
- style={{
- marginRight: 6
- }}>
- {isTopic ? 'Topic' : 'Notebook'}
- </Paragraph>
+ {topics.map(topic => (
+ <Button
+ title={topic.title}
+ key={topic.id}
+ height={null}
+ textStyle={{
+ fontWeight: 'normal',
+ fontFamily: null
+ }}
+ type="grayBg"
+ fontSize={SIZE.xs}
+ icon="bookmark-outline"
+ textStyle={{
+ marginRight: 0
+ }}
+ iconSize={SIZE.sm}
+ style={{
+ borderRadius: 5,
+ maxWidth: 120,
+ borderWidth: 0.5,
+ paddingVertical: 2.5,
+ borderColor: colors.icon,
+ paddingHorizontal: 6,
+ marginVertical: 5,
+ marginRight: 5
+ }}
+ onPress={() => navigateToTopic(topic)}
+ />
+ ))}
+ </View>
+ )}
- {isTrash ? (
- <>
- <Paragraph
- color={colors.icon}
- size={SIZE.xs}
- style={{
- textAlignVertical: 'center',
- marginRight: 6
- }}>
- {'Deleted on ' +
- new Date(item.dateDeleted).toISOString().slice(0, 10)}
- </Paragraph>
- <Paragraph
- color={colors.accent}
- size={SIZE.xs}
- style={{
- textAlignVertical: 'center',
- marginRight: 6
- }}>
- {item.itemType[0].toUpperCase() + item.itemType.slice(1)}
- </Paragraph>
- </>
- ) : (
+ <View
+ style={{
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ marginTop: 5,
+ height: SIZE.md + 2
+ }}>
+ <Paragraph
+ color={colors.accent}
+ size={SIZE.xs}
+ style={{
+ marginRight: 6
+ }}>
+ {isTopic ? 'Topic' : 'Notebook'}
+ </Paragraph>
+
+ {isTrash ? (
+ <>
<Paragraph
color={colors.icon}
size={SIZE.xs}
style={{
+ textAlignVertical: 'center',
+ marginRight: 6
+ }}>
+ {'Deleted on ' +
+ new Date(item.dateDeleted).toISOString().slice(0, 10)}
+ </Paragraph>
+ <Paragraph
+ color={colors.accent}
+ size={SIZE.xs}
+ style={{
+ textAlignVertical: 'center',
marginRight: 6
}}>
- {new Date(item.dateCreated).toDateString().substring(4)}
+ {item.itemType[0].toUpperCase() + item.itemType.slice(1)}
</Paragraph>
- )}
+ </>
+ ) : (
<Paragraph
color={colors.icon}
size={SIZE.xs}
style={{
marginRight: 6
}}>
- {item && totalNotes > 1
- ? totalNotes + ' notes'
- : totalNotes === 1
- ? totalNotes + ' note'
- : '0 notes'}
+ {new Date(item[dateBy]).toDateString().substring(4)}
</Paragraph>
+ )}
+ <Paragraph
+ color={colors.icon}
+ size={SIZE.xs}
+ style={{
+ marginRight: 6
+ }}>
+ {item && totalNotes > 1
+ ? totalNotes + ' notes'
+ : totalNotes === 1
+ ? totalNotes + ' note'
+ : '0 notes'}
+ </Paragraph>
- {item.pinned ? (
- <Icon
- style={{marginRight: 6}}
- name="pin-outline"
- size={SIZE.sm}
- style={{
- marginRight: 10,
- marginTop: 2
- }}
- color={colors.accent}
- />
- ) : null}
- </View>
+ {item.pinned ? (
+ <Icon
+ style={{marginRight: 6}}
+ name="pin-outline"
+ size={SIZE.sm}
+ style={{
+ marginRight: 10,
+ marginTop: 2
+ }}
+ color={colors.accent}
+ />
+ ) : null}
</View>
- <ActionIcon
- color={colors.heading}
- name="dots-horizontal"
- testID={notesnook.ids.notebook.menu}
- size={SIZE.xl}
- onPress={showActionSheet}
- customStyle={{
- justifyContent: 'center',
- height: 35,
- width: 35,
- borderRadius: 100,
- alignItems: 'center'
- }}
- />
- </>
- );
- }
\ No newline at end of file
+ </View>
+ <ActionIcon
+ color={colors.heading}
+ name="dots-horizontal"
+ testID={notesnook.ids.notebook.menu}
+ size={SIZE.xl}
+ onPress={showActionSheet}
+ customStyle={{
+ justifyContent: 'center',
+ height: 35,
+ width: 35,
+ borderRadius: 100,
+ alignItems: 'center'
+ }}
+ />
+ </>
+ );
+};
diff --git a/apps/mobile/src/components/NotebookItem/wrapper.js b/apps/mobile/src/components/NotebookItem/wrapper.js
index 49b26058c..565cc5355 100644
--- a/apps/mobile/src/components/NotebookItem/wrapper.js
+++ b/apps/mobile/src/components/NotebookItem/wrapper.js
@@ -8,7 +8,7 @@ import {eOnNewTopicAdded, refreshNotesPage} from '../../utils/Events';
import SelectionWrapper from '../SelectionWrapper';
export const NotebookWrapper = React.memo(
- ({item, index}) => {
+ ({item, index,dateBy}) => {
const isTrash = item.type === 'trash';
const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
@@ -51,6 +51,7 @@ export const NotebookWrapper = React.memo(
<NotebookItem
isTopic={item.type === 'topic'}
item={item}
+ dateBy={dateBy}
index={index}
isTrash={isTrash}
/>
@@ -58,6 +59,10 @@ export const NotebookWrapper = React.memo(
);
},
(prev, next) => {
+ if (prev.dateBy !== next.dateBy ) {
+ return false;
+ }
+
if (prev.item?.dateEdited !== next.item?.dateEdited) {
return false;
}
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 33686d051..8d8e8c0d6 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -24,9 +24,12 @@ let renderItems = {
header: SectionHeader
};
-const RenderItem = ({item, index, ...restArgs}) => {
+const RenderItem = ({item, index, type, ...restArgs}) => {
if (!item) return <View />;
const Item = renderItems[item.itemType || item.type] || View;
+ const groupOptions = db.settings?.getGroupOptions(type);
+ const dateBy =
+ groupOptions.sortBy !== 'title' ? groupOptions.sortBy : 'dateEdited';
let tags =
item.tags
@@ -42,7 +45,16 @@ const RenderItem = ({item, index, ...restArgs}) => {
};
})
.filter(t => t !== null) || [];
- return <Item item={item} tags={tags} index={index} {...restArgs} />;
+ return (
+ <Item
+ item={item}
+ tags={tags}
+ dateBy={dateBy}
+ index={index}
+ type={type}
+ {...restArgs}
+ />
+ );
};
const SimpleList = ({