Fix: List updating incorrectly on new note creation

This commit is contained in:
ammarahm-ed
2020-10-14 11:47:29 +05:00
parent 4e9d71a969
commit 345338f091
3 changed files with 21 additions and 14 deletions

View File

@@ -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) {

View File

@@ -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 ? (

View File

@@ -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({