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 {colors, selectionMode} = state;
|
||||||
const [note, setNote] = useState(item);
|
const [note, setNote] = useState(item);
|
||||||
const [editing, setEditing] = useState(false);
|
const [editing, setEditing] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setNote(item);
|
||||||
|
},[item])
|
||||||
|
|
||||||
const onNoteChange = (data) => {
|
const onNoteChange = (data) => {
|
||||||
if (data.id !== note.id) {
|
if (data.id !== note.id) {
|
||||||
return;
|
return;
|
||||||
@@ -34,7 +39,6 @@ export const NoteItemWrapper = ({
|
|||||||
if (data.closed) {
|
if (data.closed) {
|
||||||
setEditing(false);
|
setEditing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
setNote(db.notes.note(data.id).data)
|
setNote(db.notes.note(data.id).data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +47,7 @@ export const NoteItemWrapper = ({
|
|||||||
return () => {
|
return () => {
|
||||||
eUnSubscribeEvent(eOnNoteEdited + note.id, onNoteChange);
|
eUnSubscribeEvent(eOnNoteEdited + note.id, onNoteChange);
|
||||||
}
|
}
|
||||||
}, [editing]);
|
}, [editing,item]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const style = useMemo(() => {
|
const style = useMemo(() => {
|
||||||
return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
|
return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
|
||||||
@@ -62,7 +64,6 @@ export const NoteItemWrapper = ({
|
|||||||
const onPress = async () => {
|
const onPress = async () => {
|
||||||
if (item.conflicted) {
|
if (item.conflicted) {
|
||||||
eSendEvent(eShowMergeDialog, item);
|
eSendEvent(eShowMergeDialog, item);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selectionMode) {
|
if (selectionMode) {
|
||||||
|
|||||||
@@ -63,10 +63,15 @@ const SimpleList = ({
|
|||||||
} */
|
} */
|
||||||
setDataProvider(
|
setDataProvider(
|
||||||
new DataProvider((r1, r2) => {
|
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),
|
}).cloneWithRows(d),
|
||||||
);
|
);
|
||||||
}, [listData]);
|
}, [listData, searchResults]);
|
||||||
|
|
||||||
const RenderSectionHeader = ({item}) => (
|
const RenderSectionHeader = ({item}) => (
|
||||||
<Text
|
<Text
|
||||||
@@ -117,8 +122,9 @@ const SimpleList = ({
|
|||||||
if (refreshCallback) {
|
if (refreshCallback) {
|
||||||
refreshCallback();
|
refreshCallback();
|
||||||
}
|
}
|
||||||
dispatch({type: Actions.ALL});
|
|
||||||
}
|
}
|
||||||
|
dispatch({type: Actions.ALL});
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const _ListEmptyComponent = (
|
const _ListEmptyComponent = (
|
||||||
@@ -212,6 +218,7 @@ const SimpleList = ({
|
|||||||
dataProvider={dataProvider}
|
dataProvider={dataProvider}
|
||||||
rowRenderer={_renderRow}
|
rowRenderer={_renderRow}
|
||||||
onScroll={_onScroll}
|
onScroll={_onScroll}
|
||||||
|
renderFooter={() => <View style={{height:400}} />}
|
||||||
scrollViewProps={{
|
scrollViewProps={{
|
||||||
refreshControl: (
|
refreshControl: (
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
@@ -336,7 +343,7 @@ const LoginCard = ({type, data}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ListHeaderComponent = ({type, data}) => {
|
const ListHeaderComponent = ({type, data}) => {
|
||||||
const [state, ] = useTracked();
|
const [state,] = useTracked();
|
||||||
const searchResults = {...state.searchResults};
|
const searchResults = {...state.searchResults};
|
||||||
|
|
||||||
return searchResults.type === type && searchResults.results.length > 0 ? (
|
return searchResults.type === type && searchResults.results.length > 0 ? (
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ export async function loadNote(item) {
|
|||||||
const onChange = (data) => {
|
const onChange = (data) => {
|
||||||
if (!data || data === '') return;
|
if (!data || data === '') return;
|
||||||
let rawData = JSON.parse(data);
|
let rawData = JSON.parse(data);
|
||||||
console.log(content, "onChange", noteEdited);
|
|
||||||
if (rawData.type === 'content') {
|
if (rawData.type === 'content') {
|
||||||
if (
|
if (
|
||||||
!id && rawData.text !== "" ||
|
!id && rawData.text !== "" ||
|
||||||
@@ -231,9 +230,7 @@ async function addToCollection(id) {
|
|||||||
|
|
||||||
export async function saveNote() {
|
export async function saveNote() {
|
||||||
if (!checkIfContentIsSavable()) return;
|
if (!checkIfContentIsSavable()) return;
|
||||||
console.log("saving", id);
|
|
||||||
let lockedNote = id ? db.notes.note(id).data.locked : null;
|
let lockedNote = id ? db.notes.note(id).data.locked : null;
|
||||||
post('saving', 'Saving');
|
|
||||||
|
|
||||||
if (!lockedNote) {
|
if (!lockedNote) {
|
||||||
let rId = await db.notes.add({
|
let rId = await db.notes.add({
|
||||||
@@ -244,9 +241,8 @@ export async function saveNote() {
|
|||||||
},
|
},
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
console.log(rId);
|
|
||||||
await setNoteInEditorAfterSaving(id, rId);
|
await setNoteInEditorAfterSaving(id, rId);
|
||||||
if (saveCounter < 2) {
|
if (saveCounter < 3) {
|
||||||
updateEvent({
|
updateEvent({
|
||||||
type: Actions.NOTES,
|
type: Actions.NOTES,
|
||||||
});
|
});
|
||||||
@@ -255,6 +251,9 @@ export async function saveNote() {
|
|||||||
|
|
||||||
eSendEvent(eOnNoteEdited + rId, {id: rId});
|
eSendEvent(eOnNoteEdited + rId, {id: rId});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
await addToCollection(id);
|
await addToCollection(id);
|
||||||
updateEvent({
|
updateEvent({
|
||||||
|
|||||||
Reference in New Issue
Block a user