mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
minor refactor
This commit is contained in:
@@ -3,22 +3,24 @@ import NoteItem from '../../components/NoteItem';
|
||||
import SelectionWrapper from '../../components/SelectionWrapper';
|
||||
import {useTracked} from '../../provider';
|
||||
import {Actions} from '../../provider/Actions';
|
||||
import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent, openVault} from '../../services/EventManager';
|
||||
import {
|
||||
eSendEvent,
|
||||
eSubscribeEvent,
|
||||
eUnSubscribeEvent,
|
||||
openVault,
|
||||
} from '../../services/EventManager';
|
||||
import {eShowMergeDialog, eOnLoadNote, eOnNoteEdited} from '../../utils/Events';
|
||||
import {simpleDialogEvent} from '../DialogManager/recievers';
|
||||
import {TEMPLATE_TRASH} from '../DialogManager/Templates';
|
||||
import {openEditorAnimation} from '../../utils/Animations';
|
||||
import {db} from "../../utils/DB";
|
||||
import {DDS} from "../../services/DeviceDetection";
|
||||
|
||||
|
||||
import {db} from '../../utils/DB';
|
||||
import {DDS} from '../../services/DeviceDetection';
|
||||
import { tabBarRef } from '../../utils/Refs';
|
||||
|
||||
export const NoteItemWrapper = ({
|
||||
item,
|
||||
index,
|
||||
isTrash = false,
|
||||
pinned = false,
|
||||
}) => {
|
||||
}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, selectionMode} = state;
|
||||
const [note, setNote] = useState(item);
|
||||
@@ -26,7 +28,7 @@ export const NoteItemWrapper = ({
|
||||
|
||||
useEffect(() => {
|
||||
setNote(item);
|
||||
},[item])
|
||||
}, [item]);
|
||||
|
||||
const onNoteChange = (data) => {
|
||||
if (data.id !== note.id || data.closed) {
|
||||
@@ -40,24 +42,27 @@ export const NoteItemWrapper = ({
|
||||
}
|
||||
let newNote = db.notes.note(data.id).data;
|
||||
|
||||
if (!data.noEdit && newNote.title === note.title && newNote.headline === note.headline) {
|
||||
if (
|
||||
!data.noEdit &&
|
||||
newNote.title === note.title &&
|
||||
newNote.headline === note.headline
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setNote(newNote);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
eSubscribeEvent(eOnNoteEdited , onNoteChange);
|
||||
eSubscribeEvent(eOnNoteEdited, onNoteChange);
|
||||
return () => {
|
||||
eUnSubscribeEvent(eOnNoteEdited , onNoteChange);
|
||||
}
|
||||
}, [editing,note]);
|
||||
eUnSubscribeEvent(eOnNoteEdited, onNoteChange);
|
||||
};
|
||||
}, [editing, note]);
|
||||
|
||||
const style = useMemo(() => {
|
||||
return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
|
||||
}, [selectionMode]);
|
||||
|
||||
|
||||
const onLongPress = () => {
|
||||
if (!selectionMode) {
|
||||
dispatch({type: Actions.SELECTION_MODE, enabled: true});
|
||||
@@ -83,15 +88,14 @@ export const NoteItemWrapper = ({
|
||||
eSendEvent(eOnLoadNote, note);
|
||||
}
|
||||
if (DDS.isPhone || DDS.isSmallTab) {
|
||||
openEditorAnimation(event.nativeEvent);
|
||||
tabBarRef.current?.goToPage(1);
|
||||
//openEditorAnimation(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<SelectionWrapper
|
||||
index={index}
|
||||
pinned={pinned}
|
||||
onLongPress={onLongPress}
|
||||
onPress={onPress}
|
||||
currentEditingNote={editing}
|
||||
@@ -106,4 +110,4 @@ export const NoteItemWrapper = ({
|
||||
/>
|
||||
</SelectionWrapper>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ export const NotebookItemWrapper = ({
|
||||
index,
|
||||
isTrash = false,
|
||||
pinned = false,
|
||||
isTopic,
|
||||
}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {selectionMode, preventDefaultMargins} = state;
|
||||
@@ -37,6 +38,14 @@ export const NotebookItemWrapper = ({
|
||||
onLongPress();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTopic) {
|
||||
NavigationService.navigate('NotesPage', {
|
||||
...item,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: Actions.HEADER_TEXT_STATE,
|
||||
state: {
|
||||
@@ -45,7 +54,7 @@ export const NotebookItemWrapper = ({
|
||||
});
|
||||
dispatch({
|
||||
type: Actions.HEADER_STATE,
|
||||
state:false,
|
||||
state: false,
|
||||
});
|
||||
|
||||
NavigationService.navigate('Notebook', {
|
||||
@@ -64,7 +73,7 @@ export const NotebookItemWrapper = ({
|
||||
item={item}>
|
||||
<NotebookItem
|
||||
hideMore={preventDefaultMargins}
|
||||
isTopic={item.type === 'topic'}
|
||||
isTopic={isTopic}
|
||||
customStyle={style}
|
||||
item={item}
|
||||
index={index}
|
||||
|
||||
Reference in New Issue
Block a user