Skip to content

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

fix rendering of note item

ammarahm-ed10246ba8a8ff
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 871fbef38..928818c7b 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import {Platform, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
@@ -7,7 +7,7 @@ import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {COLORS_NOTE} from '../../utils/Colors';
import {db} from '../../utils/database';
-import {eOnNewTopicAdded, refreshNotesPage} from '../../utils/Events';
+import {refreshNotesPage} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
import {Button} from '../Button';
@@ -29,8 +29,8 @@ const navigateToTopic = topic => {
};
function navigateToTag(item) {
- let tags = db.tags.all;
- let _tag = tags.find(t => t.title === item);
+ let _tag = db.tags.tag(item.id);
+ if (!_tag) return;
let params = {
..._tag,
type: 'tag',
@@ -76,12 +76,10 @@ const NoteItem = ({item, isTrash, tags}) => {
const {colors} = state;
const settings = useSettingStore(state => state.settings);
const compactMode = settings.notesListMode === 'compact';
- const allTags = useTagStore(state => state.tags);
function getNotebook() {
- if (isTrash || !item.notebooks) return [];
+ if (isTrash || !item.notebooks || item.notebooks.length < 1) return [];
let item_notebook = item.notebooks?.slice(0, 1)[0];
-
notebook = db.notebooks.notebook(item_notebook.id);
if (!notebook) return [];
@@ -98,6 +96,10 @@ const NoteItem = ({item, isTrash, tags}) => {
];
}
+ useEffect(() => {
+ console.log('rendering',item.id);
+ })
+
return (
<>
<View
@@ -112,7 +114,7 @@ const NoteItem = ({item, isTrash, tags}) => {
alignItems: 'center',
zIndex: 10,
elevation: 10,
- marginBottom:2.5
+ marginBottom: 2.5
}}>
{getNotebook().map(_item => (
<Button
@@ -242,27 +244,29 @@ const NoteItem = ({item, isTrash, tags}) => {
) : null}
{!isTrash && !compactMode && tags
- ? tags.slice(0, 3)?.map(item => (
- <Button
- title={'#' + db.tags.alias(item)}
- key={item}
- height={20}
- type="gray"
- textStyle={{
- textDecorationLine: 'underline'
- }}
- hitSlop={{top: 8, bottom: 12, left: 0, right: 0}}
- fontSize={SIZE.xs + 1}
- style={{
- borderRadius: 5,
- paddingHorizontal: 2,
- marginRight: 4,
- zIndex: 10,
- maxWidth: tags?.slice(0, 3)?.length > 1 ? 130 : null
- }}
- onPress={() => navigateToTag(item)}
- />
- ))
+ ? tags.map(item =>
+ item.id ? (
+ <Button
+ title={'#' + item.alias}
+ key={item.id}
+ height={20}
+ type="gray"
+ textStyle={{
+ textDecorationLine: 'underline'
+ }}
+ hitSlop={{top: 8, bottom: 12, left: 0, right: 0}}
+ fontSize={SIZE.xs + 1}
+ style={{
+ borderRadius: 5,
+ paddingHorizontal: 2,
+ marginRight: 4,
+ zIndex: 10,
+ maxWidth: tags.length > 1 ? 130 : null
+ }}
+ onPress={() => navigateToTag(item)}
+ />
+ ) : null
+ )
: null}
</>
) : (
diff --git a/apps/mobile/src/components/NoteItem/wrapper.js b/apps/mobile/src/components/NoteItem/wrapper.js
index 876921ff0..951517aa4 100644
--- a/apps/mobile/src/components/NoteItem/wrapper.js
+++ b/apps/mobile/src/components/NoteItem/wrapper.js
@@ -5,61 +5,54 @@ import { useSelectionStore, useTrashStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, openVault, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
-import { editing, history } from '../../utils';
+import { history } from '../../utils';
import { db } from '../../utils/database';
import { eOnLoadNote, eShowMergeDialog } from '../../utils/Events';
import { tabBarRef } from '../../utils/Refs';
-import { sleep } from '../../utils/TimeUtils';
import { presentDialog } from '../Dialog/functions';
import SelectionWrapper from '../SelectionWrapper';
-export const NoteWrapper = React.memo(({item, index,tags,compactMode}) => {
- const isTrash = item.type === 'trash';
- const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
+export const NoteWrapper = React.memo(
+ ({item, index, tags, compactMode}) => {
+ const isTrash = item.type === 'trash';
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
- const onPress = async () => {
- // let diff = !editing.lastClosedTime ? 0 : (editing.lastClosedTime + 800) - Date.now();
- // console.log('diff:',diff);
- // if (diff > 0) {
- // console.log('sleeping');
- // await sleep(diff + 10);
- // }
-
- let _note = item;
- if (!isTrash) {
- _note = db.notes.note(item.id).data;
- }
+ const onPress = async () => {
+ let _note = item;
+ if (!isTrash) {
+ _note = db.notes.note(item.id).data;
+ }
- if (history.selectedItemsList.length > 0 && history.selectionMode) {
- setSelectedItem(_note);
- return;
- } else {
- history.selectedItemsList = [];
- }
+ if (history.selectedItemsList.length > 0 && history.selectionMode) {
+ setSelectedItem(_note);
+ return;
+ } else {
+ history.selectedItemsList = [];
+ }
- if (_note.conflicted) {
- eSendEvent(eShowMergeDialog, _note);
- return;
- }
+ if (_note.conflicted) {
+ eSendEvent(eShowMergeDialog, _note);
+ return;
+ }
- if (_note.locked) {
- openVault({
- item: _note,
- novault: true,
- locked: true,
- goToEditor: true,
- title: 'Open note',
- description: 'Unlock note to open it in editor.',
- });
- return;
- }
- if (isTrash) {
- presentDialog({
- title: `Restore ${item.itemType}`,
- paragraph: `Restore or delete ${item.itemType} forever`,
- positiveText: 'Restore',
- negativeText: 'Delete',
- positivePress: async () => {
+ if (_note.locked) {
+ openVault({
+ item: _note,
+ novault: true,
+ locked: true,
+ goToEditor: true,
+ title: 'Open note',
+ description: 'Unlock note to open it in editor.'
+ });
+ return;
+ }
+ if (isTrash) {
+ presentDialog({
+ title: `Restore ${item.itemType}`,
+ paragraph: `Restore or delete ${item.itemType} forever`,
+ positiveText: 'Restore',
+ negativeText: 'Delete',
+ positivePress: async () => {
await db.trash.restore(item.id);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
@@ -67,51 +60,56 @@ export const NoteWrapper = React.memo(({item, index,tags,compactMode}) => {
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash,
+ Navigation.routeNames.Trash
]);
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Restore successful',
+ type: 'success'
+ });
+ },
+ onClose: async () => {
+ await db.trash.delete(item.id);
+ useTrashStore.getState().setTrash();
+ useSelectionStore.getState().setSelectionMode(false);
+ ToastEvent.show({
+ heading: 'Permanantly deleted items',
type: 'success',
+ context: 'local'
});
- },
- onClose: async () => {
- await db.trash.delete(item.id);
- useTrashStore.getState().setTrash();
- useSelectionStore.getState().setSelectionMode(false);
- ToastEvent.show({
- heading: 'Permanantly deleted items',
- type: 'success',
- context: 'local',
- });
- },
- });
- } else {
- eSendEvent(eOnLoadNote, _note);
- if (!DDS.isTab) {
- tabBarRef.current?.goToPage(1);
+ }
+ });
+ } else {
+ eSendEvent(eOnLoadNote, _note);
+ if (!DDS.isTab) {
+ tabBarRef.current?.goToPage(1);
+ }
}
+ };
+
+ return (
+ <SelectionWrapper
+ index={index}
+ height={100}
+ testID={notesnook.ids.note.get(index)}
+ onPress={onPress}
+ item={item}>
+ <NoteItem item={item} tags={tags} isTrash={isTrash} />
+ </SelectionWrapper>
+ );
+ },
+ (prev, next) => {
+
+ if (
+ JSON.stringify(prev.tags) !== JSON.stringify(next.tags)
+ ) {
+ return false;
}
-
- };
- return (
- <SelectionWrapper
- index={index}
- height={100}
- testID={notesnook.ids.note.get(index)}
- onPress={onPress}
- item={item}>
- <NoteItem item={item} tags={tags} isTrash={isTrash} />
- </SelectionWrapper>
- );
-},(prev,next) => {
- if (prev.tags.length !== next.tags.length) {
- return false;
- }
- if (prev.item !== next.item) {
- return false;
- }
+ if (prev.item !== next.item) {
+ return false;
+ }
- return true;
-});
+ return true;
+ }
+);
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 8923893b8..f55cf078c 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -1,8 +1,9 @@
import React, {useEffect, useRef, useState} from 'react';
-import {FlatList, RefreshControl} from 'react-native';
+import {FlatList, RefreshControl, View} from 'react-native';
import {useTracked} from '../../provider';
import {eSendEvent} from '../../services/EventManager';
import Sync from '../../services/Sync';
+import {db} from '../../utils/database';
import {eScrollEvent} from '../../utils/Events';
import JumpToDialog from '../JumpToDialog';
import {NotebookWrapper} from '../NotebookItem/wrapper';
@@ -19,17 +20,26 @@ let renderItems = {
notebook: NotebookWrapper,
topic: NotebookWrapper,
tag: TagItem,
- section: SectionHeader
+ section: SectionHeader,
+ header: SectionHeader
};
-const RenderItem = ({item, index}) => {
- if (!item) return <View/>
- const Item = renderItems[item.itemType || item.type] || <View/>
+const RenderItem = ({item, index}, ...restArgs) => {
+ if (!item) return <View />;
+ const Item = renderItems[item.itemType || item.type] || View;
- return (
- <Item item={item} tags={item.tags ? [...item.tags] : []} index={index} />
- );
-};
+ let tags =
+ item.tags?.slice(0, 3)?.map(item => {
+ let tag = db.tags.tag(item);
+ return {
+ title:tag.title,
+ id:tag.id,
+ alias:tag.alias
+ }
+ }) || [];
+
+ return <Item item={item} tags={tags} index={index} {...restArgs} />;
+}
const SimpleList = ({
listData,
@@ -69,18 +79,15 @@ const SimpleList = ({
}, [loading]);
const renderItem = React.useCallback(
- ({item, index}) =>
- item.type === 'header' ? (
- <SectionHeader
- item={item}
- index={index}
- color={headerProps.color}
- title={headerProps.heading}
- type={screen === 'Notes' ? 'home' : type}
- />
- ) : (
- <RenderItem item={item} index={index} />
- ),
+ ({item, index}) => (
+ <RenderItem
+ item={item}
+ index={index}
+ color={headerProps.color}
+ title={headerProps.heading}
+ type={screen === 'Notes' ? 'home' : type}
+ />
+ ),
[]
);
@@ -108,7 +115,7 @@ const SimpleList = ({
width: '100%',
minHeight: 1,
minWidth: 1,
- backgroundColor:colors.bg
+ backgroundColor: colors.bg
};
const _keyExtractor = item => item.id || item.title;