fix note cannot be removed from topic sometimes

This commit is contained in:
ammarahm-ed
2021-02-26 14:29:29 +05:00
parent d5103c5862
commit bf8fd201fe
2 changed files with 28 additions and 18 deletions

View File

@@ -74,7 +74,7 @@ const ActionSheetWrapper = ({
return (
<ActionSheet
ref={fwdRef}
hideUnderlay={largeTablet || smallTablet ? true : false}
hideUnderlay={true}
containerStyle={style}
gestureEnabled={gestureEnabled}
extraScroll={largeTablet ? 50 : 0}

View File

@@ -12,6 +12,7 @@ import {
ToastEvent,
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import { getTotalNotes } from '../../utils';
import {db} from '../../utils/DB';
import {eOpenMoveNoteDialog} from '../../utils/Events';
import {pv, SIZE} from '../../utils/SizeUtils';
@@ -81,7 +82,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
const [expanded, setExpanded] = useState('');
const [notebookInputFocused, setNotebookInputFocused] = useState(false);
const [topicInputFocused, setTopicInputFocused] = useState(false);
const [noteExists, setNoteExists] = useState([]);
const addNewNotebook = async () => {
if (!newNotebookTitle || newNotebookTitle.trim().length === 0)
return ToastEvent.show({
@@ -117,14 +118,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
};
const handlePress = async (item, index) => {
if (
note?.notebooks?.findIndex(
(o) =>
o.topics.findIndex((i) => {
return i === item.id;
}) > -1,
) > -1
) {
if (note && item.notes.indexOf(note.id) > -1) {
await db.notebooks
.notebook(item.notebookId)
.topics.topic(item.id)
@@ -163,6 +157,19 @@ const MoveNoteComponent = ({close, note, setNote}) => {
dispatch({type: Actions.NOTEBOOKS});
};
useEffect(() => {
if (!note?.id) return;
let ids = [];
for (let i = 0; i < notebooks.length; i++) {
for (let t = 0; t < notebooks[i].topics.length; t++) {
if (notebooks[i].topics[t].notes.indexOf(note.id) > -1) {
ids.push(notebooks[i].id);
}
}
}
setNoteExists(ids);
}, []);
return (
<>
<View>
@@ -290,7 +297,9 @@ const MoveNoteComponent = ({close, note, setNote}) => {
marginBottom: 5,
borderBottomWidth: 1,
borderBottomColor:
expanded === item.id ? colors.accent : colors.nav,
expanded === item.id || noteExists.indexOf(item.id) > -1
? colors.accent
: colors.nav,
}}>
<View
style={{
@@ -303,13 +312,16 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}}>
<View>
<Heading
color={expanded === item.id ? colors.accent : null}
color={
expanded === item.id || noteExists.indexOf(item.id) > -1
? colors.accent
: null
}
size={SIZE.md}>
{item.title}
</Heading>
<Paragraph size={SIZE.xs} color={colors.icon}>
Notebook{' '}
{item.totalNotes +
{getTotalNotes(item) +
' notes' +
' & ' +
item.topics.length +
@@ -431,12 +443,10 @@ const MoveNoteComponent = ({close, note, setNote}) => {
{item.title}
</Paragraph>
<Paragraph color={colors.icon} size={SIZE.xs}>
{item.totalNotes + ' notes'}
{item.notes.length + ' notes'}
</Paragraph>
</View>
{note?.notebooks?.findIndex(
(o) => o.topics.indexOf(item.id) > -1,
) > -1 ? (
{note && item.notes.indexOf(note.id) > -1 ? (
<Button
onPress={() => handlePress(item, index)}
title="Remove note"