mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
Fix: List updating incorrectly on new note creation
This commit is contained in:
@@ -23,6 +23,11 @@ export const NoteItemWrapper = ({
|
||||
const {colors, selectionMode} = state;
|
||||
const [note, setNote] = useState(item);
|
||||
const [editing, setEditing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setNote(item);
|
||||
},[item])
|
||||
|
||||
const onNoteChange = (data) => {
|
||||
if (data.id !== note.id) {
|
||||
return;
|
||||
@@ -34,7 +39,6 @@ export const NoteItemWrapper = ({
|
||||
if (data.closed) {
|
||||
setEditing(false);
|
||||
}
|
||||
|
||||
setNote(db.notes.note(data.id).data)
|
||||
}
|
||||
|
||||
@@ -43,9 +47,7 @@ export const NoteItemWrapper = ({
|
||||
return () => {
|
||||
eUnSubscribeEvent(eOnNoteEdited + note.id, onNoteChange);
|
||||
}
|
||||
}, [editing]);
|
||||
|
||||
|
||||
}, [editing,item]);
|
||||
|
||||
const style = useMemo(() => {
|
||||
return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
|
||||
@@ -62,7 +64,6 @@ export const NoteItemWrapper = ({
|
||||
const onPress = async () => {
|
||||
if (item.conflicted) {
|
||||
eSendEvent(eShowMergeDialog, item);
|
||||
|
||||
return;
|
||||
}
|
||||
if (selectionMode) {
|
||||
|
||||
@@ -63,10 +63,15 @@ const SimpleList = ({
|
||||
} */
|
||||
setDataProvider(
|
||||
new DataProvider((r1, r2) => {
|
||||
return r1 !== r2;
|
||||
|
||||
return r1.id !== r2.id ||
|
||||
r1.locked !== r2.locked ||
|
||||
r1.pinned !== r2.pinned ||
|
||||
r1.favorite !== r2.favorite ||
|
||||
r1.title !== r2.title
|
||||
}).cloneWithRows(d),
|
||||
);
|
||||
}, [listData]);
|
||||
}, [listData, searchResults]);
|
||||
|
||||
const RenderSectionHeader = ({item}) => (
|
||||
<Text
|
||||
@@ -117,8 +122,9 @@ const SimpleList = ({
|
||||
if (refreshCallback) {
|
||||
refreshCallback();
|
||||
}
|
||||
dispatch({type: Actions.ALL});
|
||||
}
|
||||
dispatch({type: Actions.ALL});
|
||||
|
||||
}, []);
|
||||
|
||||
const _ListEmptyComponent = (
|
||||
@@ -212,6 +218,7 @@ const SimpleList = ({
|
||||
dataProvider={dataProvider}
|
||||
rowRenderer={_renderRow}
|
||||
onScroll={_onScroll}
|
||||
renderFooter={() => <View style={{height:400}} />}
|
||||
scrollViewProps={{
|
||||
refreshControl: (
|
||||
<RefreshControl
|
||||
|
||||
@@ -95,7 +95,6 @@ export async function loadNote(item) {
|
||||
const onChange = (data) => {
|
||||
if (!data || data === '') return;
|
||||
let rawData = JSON.parse(data);
|
||||
console.log(content, "onChange", noteEdited);
|
||||
if (rawData.type === 'content') {
|
||||
if (
|
||||
!id && rawData.text !== "" ||
|
||||
@@ -231,9 +230,7 @@ async function addToCollection(id) {
|
||||
|
||||
export async function saveNote() {
|
||||
if (!checkIfContentIsSavable()) return;
|
||||
console.log("saving", id);
|
||||
let lockedNote = id ? db.notes.note(id).data.locked : null;
|
||||
post('saving', 'Saving');
|
||||
|
||||
if (!lockedNote) {
|
||||
let rId = await db.notes.add({
|
||||
@@ -244,9 +241,8 @@ export async function saveNote() {
|
||||
},
|
||||
id: id,
|
||||
});
|
||||
console.log(rId);
|
||||
await setNoteInEditorAfterSaving(id, rId);
|
||||
if (saveCounter < 2) {
|
||||
if (saveCounter < 3) {
|
||||
updateEvent({
|
||||
type: Actions.NOTES,
|
||||
});
|
||||
@@ -255,6 +251,9 @@ export async function saveNote() {
|
||||
|
||||
eSendEvent(eOnNoteEdited + rId, {id: rId});
|
||||
|
||||
|
||||
|
||||
|
||||
if (id) {
|
||||
await addToCollection(id);
|
||||
updateEvent({
|
||||
|
||||
Reference in New Issue
Block a user