Skip to content

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

refactor NoteItem

ammarahm-ed9812a18e96a0
diff --git a/apps/mobile/src/components/SelectionWrapper/index.js b/apps/mobile/src/components/SelectionWrapper/index.js
index f2d98ee85..f4bf466b4 100644
--- a/apps/mobile/src/components/SelectionWrapper/index.js
+++ b/apps/mobile/src/components/SelectionWrapper/index.js
@@ -4,7 +4,6 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {ToastEvent} from '../../services/EventManager';
-import {getElevation} from '../../utils';
import {COLORS_NOTE} from '../../utils/Colors';
import {db} from '../../utils/DB';
import {SIZE} from '../../utils/SizeUtils';
@@ -13,15 +12,13 @@ import {PressableButton} from '../PressableButton';
const SelectionWrapper = ({
children,
item,
- currentEditingNote,
index,
background,
onLongPress,
-
onPress,
}) => {
const [state, dispatch] = useTracked();
- const {colors, selectionMode, selectedItemsList} = state;
+ const {colors, selectionMode, selectedItemsList, currentEditingNote} = state;
const [selected, setSelected] = useState(false);
useEffect(() => {
let exists = selectedItemsList.filter(
@@ -69,7 +66,7 @@ const SelectionWrapper = ({
return (
<PressableButton
color={
- currentEditingNote
+ currentEditingNote === item.id
? item.type === 'note' && item.colors[0]
? COLORS_NOTE[item.colors[0]]
: colors.shade
@@ -81,7 +78,7 @@ const SelectionWrapper = ({
onPress={onPress}
selectedColor={currentEditingNote ? colors.accent : colors.nav}
alpha={!colors.night ? -0.02 : 0.02}
- opacity={ currentEditingNote ? 0.15 : 1}
+ opacity={currentEditingNote ? 0.15 : 1}
customStyle={{
flexDirection: 'row',
justifyContent: 'space-between',
@@ -96,7 +93,7 @@ const SelectionWrapper = ({
? 30
: 0,
}}>
- {/* {item.pinned ? (
+ {/* {item.pinned ? (
<PressableButton
color={item.colors[0] ? COLORS_NOTE[item.colors[0]] : colors.accent}
selectedColor={
diff --git a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
index 39e6584da..a56c4f173 100644
--- a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
+++ b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
@@ -14,34 +14,22 @@ import {simpleDialogEvent} from '../DialogManager/recievers';
import {TEMPLATE_TRASH} from '../DialogManager/Templates';
import {db} from '../../utils/DB';
import {DDS} from '../../services/DeviceDetection';
-import { tabBarRef } from '../../utils/Refs';
+import {tabBarRef} from '../../utils/Refs';
-export const NoteItemWrapper = ({
- item,
- index,
- isTrash = false,
-}) => {
+export const NoteItemWrapper = ({item, index, isTrash = false}) => {
const [state, dispatch] = useTracked();
const {colors, selectionMode} = state;
const [note, setNote] = useState(item);
- const [editing, setEditing] = useState(false);
useEffect(() => {
setNote(item);
}, [item]);
const onNoteChange = (data) => {
- if (data.id !== note.id || data.closed) {
- if (editing) {
- setEditing(false);
- }
+ if (!data || data.id !== note.id || data.closed) {
return;
}
- if (!editing && !data.noEdit) {
- setEditing(true);
- }
let newNote = db.notes.note(data.id).data;
-
if (
!data.noEdit &&
newNote.title === note.title &&
@@ -57,7 +45,7 @@ export const NoteItemWrapper = ({
return () => {
eUnSubscribeEvent(eOnNoteEdited, onNoteChange);
};
- }, [editing, note]);
+ }, [note]);
const style = useMemo(() => {
return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
@@ -98,12 +86,10 @@ export const NoteItemWrapper = ({
index={index}
onLongPress={onLongPress}
onPress={onPress}
- currentEditingNote={editing}
item={note}>
<NoteItem
colors={colors}
customStyle={style}
- currentEditingNote={editing}
selectionMode={selectionMode}
item={note}
isTrash={isTrash}