mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix note not updating
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
||||
import {Platform, RefreshControl, StyleSheet, Text, useWindowDimensions, View} from 'react-native';
|
||||
import {
|
||||
Platform,
|
||||
RefreshControl,
|
||||
StyleSheet,
|
||||
Text,
|
||||
useWindowDimensions,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import {initialWindowMetrics} from 'react-native-safe-area-context';
|
||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview';
|
||||
import {useTracked} from '../../provider';
|
||||
import {Actions} from '../../provider/Actions';
|
||||
import {eSendEvent, ToastEvent} from '../../services/EventManager';
|
||||
import {eClearSearch, eOpenLoginDialog, eScrollEvent,} from '../../utils/Events';
|
||||
import {eClearSearch, eOpenLoginDialog, eScrollEvent} from '../../utils/Events';
|
||||
import {PressableButton} from '../PressableButton';
|
||||
import {COLORS_NOTE} from "../../utils/Colors";
|
||||
import {SIZE, WEIGHT} from "../../utils/SizeUtils";
|
||||
import {db} from "../../utils/DB";
|
||||
import {COLORS_NOTE} from '../../utils/Colors';
|
||||
import {SIZE, WEIGHT} from '../../utils/SizeUtils';
|
||||
import {db} from '../../utils/DB';
|
||||
|
||||
const header = {
|
||||
type: 'MAIN_HEADER',
|
||||
@@ -27,7 +34,7 @@ const SimpleList = ({
|
||||
refreshCallback,
|
||||
}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, selectionMode, user} = state;
|
||||
const {colors, selectionMode, user, messageBoardState} = state;
|
||||
const searchResults = {...state.searchResults};
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [dataProvider, setDataProvider] = useState(
|
||||
@@ -58,10 +65,8 @@ const SimpleList = ({
|
||||
: listData;
|
||||
|
||||
let d = [header, ...mainData];
|
||||
setDataProvider(
|
||||
dataProvider.cloneWithRows(d),
|
||||
);
|
||||
}
|
||||
setDataProvider(dataProvider.cloneWithRows(d));
|
||||
};
|
||||
|
||||
const RenderSectionHeader = ({item}) => (
|
||||
<Text
|
||||
@@ -91,7 +96,7 @@ const SimpleList = ({
|
||||
ToastEvent.show('Sync Complete', 'success');
|
||||
} catch (e) {
|
||||
ToastEvent.show(
|
||||
"You must login to sync.",
|
||||
'You must login to sync.',
|
||||
'error',
|
||||
'global',
|
||||
5000,
|
||||
@@ -114,7 +119,6 @@ const SimpleList = ({
|
||||
}
|
||||
}
|
||||
dispatch({type: Actions.ALL});
|
||||
|
||||
}, []);
|
||||
|
||||
const _ListEmptyComponent = (
|
||||
@@ -134,7 +138,6 @@ const SimpleList = ({
|
||||
return dataProvider.getDataForIndex(index).type;
|
||||
},
|
||||
(type, dim) => {
|
||||
|
||||
switch (type) {
|
||||
case 'note':
|
||||
dim.width = width;
|
||||
@@ -159,7 +162,7 @@ const SimpleList = ({
|
||||
case 'MAIN_HEADER':
|
||||
dim.width = width;
|
||||
dim.height =
|
||||
(user && user.Id) || !listData[0] || selectionMode
|
||||
!messageBoardState.visible || !listData[0] || selectionMode
|
||||
? 0
|
||||
: 40 * fontScale;
|
||||
break;
|
||||
@@ -196,8 +199,8 @@ const SimpleList = ({
|
||||
? 130
|
||||
: 130 - 60
|
||||
: listData[0] && !selectionMode
|
||||
? 155 - initialWindowMetrics.insets.top
|
||||
: 155 - initialWindowMetrics.insets.top - 60,
|
||||
? 150 - initialWindowMetrics.insets.top
|
||||
: (150 - initialWindowMetrics.insets.top) - 60,
|
||||
};
|
||||
}, [selectionMode, listData, colors]);
|
||||
|
||||
@@ -234,7 +237,7 @@ const SimpleList = ({
|
||||
export default SimpleList;
|
||||
|
||||
const SearchHeader = () => {
|
||||
const [state,] = useTracked();
|
||||
const [state] = useTracked();
|
||||
const {colors} = state;
|
||||
const searchResults = {...state.searchResults};
|
||||
|
||||
@@ -263,17 +266,15 @@ const SearchHeader = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const LoginCard = ({type, data}) => {
|
||||
const [state,] = useTracked();
|
||||
const {colors, selectionMode, user, currentScreen} = state;
|
||||
const MessageCard = ({data}) => {
|
||||
const [state] = useTracked();
|
||||
const {colors, selectionMode, currentScreen, messageBoardState} = state;
|
||||
|
||||
return (
|
||||
<View>
|
||||
{(user && user.Id) || !data[0] || selectionMode ? null : (
|
||||
{!messageBoardState.visible || !data[0] || selectionMode ? null : (
|
||||
<PressableButton
|
||||
onPress={() => {
|
||||
eSendEvent(eOpenLoginDialog);
|
||||
}}
|
||||
onPress={messageBoardState.onPress}
|
||||
color={
|
||||
COLORS_NOTE[currentScreen]
|
||||
? COLORS_NOTE[currentScreen]
|
||||
@@ -300,7 +301,7 @@ const LoginCard = ({type, data}) => {
|
||||
}}>
|
||||
<Icon
|
||||
style={styles.loginIcon}
|
||||
name="account-outline"
|
||||
name={messageBoardState.icon}
|
||||
color="white"
|
||||
size={SIZE.xs}
|
||||
/>
|
||||
@@ -315,7 +316,7 @@ const LoginCard = ({type, data}) => {
|
||||
color: colors.icon,
|
||||
fontSize: SIZE.xxs - 1,
|
||||
}}>
|
||||
You are not logged in
|
||||
{messageBoardState.message}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
@@ -324,7 +325,7 @@ const LoginCard = ({type, data}) => {
|
||||
: colors.accent,
|
||||
fontSize: SIZE.xxs,
|
||||
}}>
|
||||
Login to sync your {type}.
|
||||
{messageBoardState.data.actionText}
|
||||
</Text>
|
||||
</View>
|
||||
</PressableButton>
|
||||
@@ -334,13 +335,13 @@ const LoginCard = ({type, data}) => {
|
||||
};
|
||||
|
||||
const ListHeaderComponent = ({type, data}) => {
|
||||
const [state,] = useTracked();
|
||||
const [state] = useTracked();
|
||||
const searchResults = {...state.searchResults};
|
||||
|
||||
return searchResults.type === type && searchResults.results.length > 0 ? (
|
||||
<SearchHeader />
|
||||
) : (
|
||||
<LoginCard type={type} data={data}/>
|
||||
<MessageCard type={type} data={data} />
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -73,5 +73,13 @@ export const defaultState = {
|
||||
bottomButtonOnPress: () => {},
|
||||
bottomButtonText: 'Create a new note',
|
||||
},
|
||||
messageBoardState: {
|
||||
visible:false,
|
||||
message:null,
|
||||
actionText:null,
|
||||
onPress:() => {},
|
||||
data:{},
|
||||
icon:'account-outline'
|
||||
},
|
||||
keyword: [],
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ export async function setSetting(settings, name, value) {
|
||||
let s = {...settings};
|
||||
s[name] = value;
|
||||
await MMKV.setStringAsync('settings', JSON.stringify(s));
|
||||
|
||||
updateEvent({type: Actions.SETTINGS, settings: s});
|
||||
}
|
||||
|
||||
@@ -17,7 +16,6 @@ export const dirs = RNFetchBlob.fs.dirs;
|
||||
export const ANDROID_PATH = dirs.SDCardDir + '/Notesnook/';
|
||||
export const IOS_PATH = dirs.DocumentDir;
|
||||
|
||||
|
||||
export const getElevation = (elevation) => {
|
||||
return {
|
||||
elevation,
|
||||
@@ -45,8 +43,6 @@ export const history = {
|
||||
selectedItemsList: [],
|
||||
};
|
||||
|
||||
|
||||
|
||||
export async function showContext(event, title) {
|
||||
eSendEvent('showContextMenu', {
|
||||
location: {
|
||||
|
||||
@@ -261,7 +261,7 @@ export async function saveNote(caller) {
|
||||
},
|
||||
id: id,
|
||||
});
|
||||
if (!id) {
|
||||
if (!id || saveCounter < 3) {
|
||||
updateEvent({
|
||||
type: Actions.NOTES,
|
||||
});
|
||||
|
||||
@@ -39,9 +39,8 @@ export const Notebook = ({route, navigation}) => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onFocus = useCallback(() => {
|
||||
const onFocus = () => {
|
||||
onLoad();
|
||||
|
||||
dispatch({
|
||||
type: Actions.HEADER_TEXT_STATE,
|
||||
state: {
|
||||
@@ -61,7 +60,7 @@ export const Notebook = ({route, navigation}) => {
|
||||
type: Actions.CURRENT_SCREEN,
|
||||
screen: 'notebook',
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
navigation.addListener('focus', onFocus);
|
||||
|
||||
@@ -55,6 +55,7 @@ export const Notes = ({route, navigation}) => {
|
||||
}, []);
|
||||
|
||||
const init = (data) => {
|
||||
console.log('refreshing notes!');
|
||||
params = route.params;
|
||||
if (data) {
|
||||
params = data;
|
||||
|
||||
Reference in New Issue
Block a user