mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
fix note cannot be removed from topic sometimes
This commit is contained in:
@@ -74,7 +74,7 @@ const ActionSheetWrapper = ({
|
|||||||
return (
|
return (
|
||||||
<ActionSheet
|
<ActionSheet
|
||||||
ref={fwdRef}
|
ref={fwdRef}
|
||||||
hideUnderlay={largeTablet || smallTablet ? true : false}
|
hideUnderlay={true}
|
||||||
containerStyle={style}
|
containerStyle={style}
|
||||||
gestureEnabled={gestureEnabled}
|
gestureEnabled={gestureEnabled}
|
||||||
extraScroll={largeTablet ? 50 : 0}
|
extraScroll={largeTablet ? 50 : 0}
|
||||||
|
|||||||
@@ -12,6 +12,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 {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';
|
||||||
@@ -81,7 +82,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
const [expanded, setExpanded] = useState('');
|
const [expanded, setExpanded] = useState('');
|
||||||
const [notebookInputFocused, setNotebookInputFocused] = useState(false);
|
const [notebookInputFocused, setNotebookInputFocused] = useState(false);
|
||||||
const [topicInputFocused, setTopicInputFocused] = useState(false);
|
const [topicInputFocused, setTopicInputFocused] = useState(false);
|
||||||
|
const [noteExists, setNoteExists] = useState([]);
|
||||||
const addNewNotebook = async () => {
|
const addNewNotebook = async () => {
|
||||||
if (!newNotebookTitle || newNotebookTitle.trim().length === 0)
|
if (!newNotebookTitle || newNotebookTitle.trim().length === 0)
|
||||||
return ToastEvent.show({
|
return ToastEvent.show({
|
||||||
@@ -117,14 +118,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handlePress = async (item, index) => {
|
const handlePress = async (item, index) => {
|
||||||
if (
|
if (note && item.notes.indexOf(note.id) > -1) {
|
||||||
note?.notebooks?.findIndex(
|
|
||||||
(o) =>
|
|
||||||
o.topics.findIndex((i) => {
|
|
||||||
return i === item.id;
|
|
||||||
}) > -1,
|
|
||||||
) > -1
|
|
||||||
) {
|
|
||||||
await db.notebooks
|
await db.notebooks
|
||||||
.notebook(item.notebookId)
|
.notebook(item.notebookId)
|
||||||
.topics.topic(item.id)
|
.topics.topic(item.id)
|
||||||
@@ -163,6 +157,19 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
dispatch({type: Actions.NOTEBOOKS});
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<View>
|
<View>
|
||||||
@@ -290,7 +297,9 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
marginBottom: 5,
|
marginBottom: 5,
|
||||||
borderBottomWidth: 1,
|
borderBottomWidth: 1,
|
||||||
borderBottomColor:
|
borderBottomColor:
|
||||||
expanded === item.id ? colors.accent : colors.nav,
|
expanded === item.id || noteExists.indexOf(item.id) > -1
|
||||||
|
? colors.accent
|
||||||
|
: colors.nav,
|
||||||
}}>
|
}}>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@@ -303,13 +312,16 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
}}>
|
}}>
|
||||||
<View>
|
<View>
|
||||||
<Heading
|
<Heading
|
||||||
color={expanded === item.id ? colors.accent : null}
|
color={
|
||||||
|
expanded === item.id || noteExists.indexOf(item.id) > -1
|
||||||
|
? colors.accent
|
||||||
|
: null
|
||||||
|
}
|
||||||
size={SIZE.md}>
|
size={SIZE.md}>
|
||||||
{item.title}
|
{item.title}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Paragraph size={SIZE.xs} color={colors.icon}>
|
<Paragraph size={SIZE.xs} color={colors.icon}>
|
||||||
Notebook{' '}
|
{getTotalNotes(item) +
|
||||||
{item.totalNotes +
|
|
||||||
' notes' +
|
' notes' +
|
||||||
' & ' +
|
' & ' +
|
||||||
item.topics.length +
|
item.topics.length +
|
||||||
@@ -431,12 +443,10 @@ const MoveNoteComponent = ({close, note, setNote}) => {
|
|||||||
{item.title}
|
{item.title}
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Paragraph color={colors.icon} size={SIZE.xs}>
|
<Paragraph color={colors.icon} size={SIZE.xs}>
|
||||||
{item.totalNotes + ' notes'}
|
{item.notes.length + ' notes'}
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</View>
|
</View>
|
||||||
{note?.notebooks?.findIndex(
|
{note && item.notes.indexOf(note.id) > -1 ? (
|
||||||
(o) => o.topics.indexOf(item.id) > -1,
|
|
||||||
) > -1 ? (
|
|
||||||
<Button
|
<Button
|
||||||
onPress={() => handlePress(item, index)}
|
onPress={() => handlePress(item, index)}
|
||||||
title="Remove note"
|
title="Remove note"
|
||||||
|
|||||||
Reference in New Issue
Block a user