fix multi select notebook add not working

This commit is contained in:
ammarahm-ed
2020-12-16 11:08:58 +05:00
parent c40be0cc26
commit f7b166ec1c
2 changed files with 41 additions and 38 deletions

View File

@@ -137,6 +137,43 @@ const IntComponent = ({close, note, setNote}) => {
newTopicTitle = null; newTopicTitle = null;
}; };
const handlePress = async () => {
if (
note?.notebooks?.findIndex(
(o) =>
o.topics.findIndex((i) => {
return i === item.id;
}) > -1,
) > -1
) {
await db.notebooks
.notebook(item.notebookId)
.topics.topic(item.id)
.delete(note.id);
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
}
dispatch({type: Actions.NOTEBOOKS});
return;
}
let noteIds = [];
selectedItemsList.forEach((i) => noteIds.push(i.id));
console.log(noteIds, 'NOTE IDS');
await db.notes.move(
{
topic: item.id,
id: item.notebookId,
},
...noteIds,
);
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
}
dispatch({type: Actions.NOTEBOOKS});
};
return ( return (
<> <>
<View> <View>
@@ -361,42 +398,7 @@ const IntComponent = ({close, note, setNote}) => {
} }
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<PressableButton <PressableButton
onPress={async () => { onPress={handlePress}
if (
note?.notebooks?.findIndex(
(o) =>
o.topics.findIndex((i) => {
return i === item.id;
}) > -1,
) > -1
) {
await db.notebooks
.notebook(item.notebookId)
.topics.topic(item.id)
.delete(note.id);
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
}
dispatch({type: Actions.NOTEBOOKS});
return;
}
let noteIds = [];
selectedItemsList.forEach((i) => noteIds.push(i.id));
await db.notes.move(
{
topic: item.id,
id: item.notebookId,
},
...noteIds,
);
console.log(item.id, item.notebookId);
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
}
dispatch({type: Actions.NOTEBOOKS});
}}
type="gray" type="gray"
customStyle={{ customStyle={{
height: 50, height: 50,

View File

@@ -9,6 +9,7 @@ import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events'; import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils'; import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {ActionIcon} from '../ActionIcon'; import {ActionIcon} from '../ActionIcon';
import {TEMPLATE_DELETE} from '../DialogManager/Templates'; import {TEMPLATE_DELETE} from '../DialogManager/Templates';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
@@ -101,9 +102,9 @@ export const SelectionHeader = () => {
}}> }}>
{currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : (
<ActionIcon <ActionIcon
onPress={() => { onPress={async () => {
dispatch({type: Actions.SELECTION_MODE, enabled: false}); dispatch({type: Actions.SELECTION_MODE, enabled: false});
dispatch({type: Actions.CLEAR_SELECTION}); await sleep(100);
eSendEvent(eOpenMoveNoteDialog); eSendEvent(eOpenMoveNoteDialog);
}} }}
customStyle={{ customStyle={{