fix move note dialog

This commit is contained in:
ammarahm-ed
2021-07-17 20:40:09 +05:00
parent 38e44d0ae0
commit 74b09b15b4

View File

@@ -5,7 +5,7 @@ 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 {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import { useNotebookStore, useSelectionStore } from '../../provider/stores'; import {useNotebookStore, useSelectionStore} from '../../provider/stores';
import { import {
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
@@ -13,7 +13,7 @@ import {
ToastEvent, ToastEvent,
} from '../../services/EventManager'; } from '../../services/EventManager';
import Navigation from '../../services/Navigation'; import Navigation from '../../services/Navigation';
import { getTotalNotes } from '../../utils'; import {getTotalNotes} from '../../utils';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import {eOpenMoveNoteDialog} from '../../utils/Events'; import {eOpenMoveNoteDialog} from '../../utils/Events';
import {pv, SIZE} from '../../utils/SizeUtils'; import {pv, SIZE} from '../../utils/SizeUtils';
@@ -63,7 +63,7 @@ const MoveNoteDialog = () => {
]); ]);
}; };
const update = (note) => { const update = note => {
setNote(note); setNote(note);
}; };
@@ -80,7 +80,9 @@ const MoveNoteComponent = ({close, note, setNote}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors} = state;
const notebooks = useNotebookStore(state => state.notebooks); const notebooks = useNotebookStore(state =>
state.notebooks.filter(n => n.type === 'notebook'),
);
const selectedItemsList = useSelectionStore(state => state.selectedItemsList); const selectedItemsList = useSelectionStore(state => state.selectedItemsList);
const setNotebooks = useNotebookStore(state => state.setNotebooks); const setNotebooks = useNotebookStore(state => state.setNotebooks);
@@ -143,7 +145,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
} }
let noteIds = []; let noteIds = [];
selectedItemsList.forEach((i) => noteIds.push(i.id)); selectedItemsList.forEach(i => noteIds.push(i.id));
await db.notes.move( await db.notes.move(
{ {
@@ -167,13 +169,16 @@ const MoveNoteComponent = ({close, note, setNote}) => {
useEffect(() => { useEffect(() => {
if (!note?.id) return; if (!note?.id) return;
let ids = []; let ids = [];
for (let i = 0; i < notebooks.length; i++) { for (let i = 0; i < notebooks.length; i++) {
if (notebooks[i].topics) {
for (let t = 0; t < notebooks[i].topics.length; t++) { for (let t = 0; t < notebooks[i].topics.length; t++) {
if (notebooks[i].topics[t].notes.indexOf(note.id) > -1) { if (notebooks[i].topics[t].notes.indexOf(note.id) > -1) {
ids.push(notebooks[i].id); ids.push(notebooks[i].id);
} }
} }
} }
}
setNoteExists(ids); setNoteExists(ids);
}, []); }, []);
@@ -237,7 +242,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}}> }}>
<TextInput <TextInput
ref={notebookInput} ref={notebookInput}
onChangeText={(value) => { onChangeText={value => {
newNotebookTitle = value; newNotebookTitle = value;
}} }}
testID={notesnook.ids.dialogs.addTo.addNotebook} testID={notesnook.ids.dialogs.addTo.addNotebook}
@@ -304,7 +309,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
marginBottom: 5, marginBottom: 5,
borderBottomWidth: 1, borderBottomWidth: 1,
borderBottomColor: borderBottomColor:
expanded === item.id || noteExists.indexOf(item.id) > -1 noteExists.indexOf(item.id) > -1
? colors.accent ? colors.accent
: colors.nav, : colors.nav,
}}> }}>
@@ -320,20 +325,20 @@ const MoveNoteComponent = ({close, note, setNote}) => {
<View> <View>
<Heading <Heading
color={ color={
expanded === item.id || noteExists.indexOf(item.id) > -1 noteExists.indexOf(item.id) > -1 ? colors.accent : null
? colors.accent
: null
} }
size={SIZE.md}> size={SIZE.md}>
{item.title} {item.title}
</Heading> </Heading>
{item.topics?.length > 0 ? (
<Paragraph size={SIZE.xs} color={colors.icon}> <Paragraph size={SIZE.xs} color={colors.icon}>
{getTotalNotes(item) + {getTotalNotes(item) + ' notes' + ' & '}
' notes' + {item.topics.length === 1
' & ' + ? item.topics.length + ' topic'
item.topics.length + : item.topics.length + ' topics'}
' topics'}
</Paragraph> </Paragraph>
) : null}
</View> </View>
<Icon <Icon
@@ -381,7 +386,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}}> }}>
<TextInput <TextInput
ref={topicInput} ref={topicInput}
onChangeText={(value) => { onChangeText={value => {
newTopicTitle = value; newTopicTitle = value;
}} }}
testID={notesnook.ids.dialogs.addTo.addTopic} testID={notesnook.ids.dialogs.addTo.addTopic}
@@ -456,10 +461,10 @@ const MoveNoteComponent = ({close, note, setNote}) => {
{note && item.notes.indexOf(note.id) > -1 ? ( {note && item.notes.indexOf(note.id) > -1 ? (
<Button <Button
onPress={() => handlePress(item, index)} onPress={() => handlePress(item, index)}
title="Remove note" title="Remove"
type="error" type="error"
height={25} height={25}
fontSize={SIZE.sm} fontSize={SIZE.xs + 1}
style={{ style={{
margin: 1, margin: 1,
marginRight: 5, marginRight: 5,