mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
cleanup onRefresh
This commit is contained in:
@@ -3,20 +3,20 @@ import {
|
||||
FlatList,
|
||||
Platform,
|
||||
RefreshControl,
|
||||
SectionList,
|
||||
Text,
|
||||
View,
|
||||
SectionList,
|
||||
} from 'react-native';
|
||||
import {useSafeArea} from 'react-native-safe-area-context';
|
||||
import {SIZE, WEIGHT} from '../../common/common';
|
||||
import {useTracked} from '../../provider';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
import {eSendEvent} from '../../services/eventManager';
|
||||
import {eClearSearch, eScrollEvent} from '../../services/events';
|
||||
import {hexToRGBA, ToastEvent, db} from '../../utils/utils';
|
||||
import {db, hexToRGBA, ToastEvent} from '../../utils/utils';
|
||||
import {NotebookItem} from '../NotebookItem';
|
||||
import SelectionWrapper from '../SelectionWrapper';
|
||||
import {useSafeArea} from 'react-native-safe-area-context';
|
||||
import NoteItem from '../NoteItem';
|
||||
import SelectionWrapper from '../SelectionWrapper';
|
||||
const sectionListRef = createRef();
|
||||
const SimpleList = ({
|
||||
data,
|
||||
@@ -26,6 +26,8 @@ const SimpleList = ({
|
||||
focused,
|
||||
placeholderText,
|
||||
pinned = null,
|
||||
customRefresh,
|
||||
customRefreshing,
|
||||
isMove,
|
||||
hideMore,
|
||||
noteToMove,
|
||||
@@ -328,9 +330,9 @@ const SimpleList = ({
|
||||
<RefreshControl
|
||||
tintColor={colors.accent}
|
||||
colors={[colors.accent]}
|
||||
progressViewOffset={-200}
|
||||
onRefresh={_onRefresh}
|
||||
refreshing={refreshing}
|
||||
progressViewOffset={150}
|
||||
onRefresh={customRefresh ? customRefresh : _onRefresh}
|
||||
refreshing={customRefresh ? customRefreshing : refreshing}
|
||||
/>
|
||||
}
|
||||
keyExtractor={_listKeyExtractor}
|
||||
|
||||
@@ -24,8 +24,6 @@ export const Folders = ({navigation}) => {
|
||||
notebooks,
|
||||
preventDefaultMargins,
|
||||
} = state;
|
||||
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
let isFocused = useIsFocused();
|
||||
|
||||
const handleBackPress = () => {
|
||||
@@ -66,21 +64,6 @@ export const Folders = ({navigation}) => {
|
||||
|
||||
const params = navigation.state.params;
|
||||
|
||||
const _onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await db.sync();
|
||||
dispatch({type: ACTIONS.NOTEBOOKS});
|
||||
dispatch({type: ACTIONS.PINNED});
|
||||
dispatch({type: ACTIONS.USER});
|
||||
setRefreshing(false);
|
||||
ToastEvent.show('Sync Complete', 'success');
|
||||
} catch (e) {
|
||||
setRefreshing(false);
|
||||
ToastEvent.show('Sync failed, network error', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const _renderItem = ({item, index}) => (
|
||||
<SelectionWrapper item={item}>
|
||||
<NotebookItem
|
||||
@@ -129,9 +112,7 @@ export const Folders = ({navigation}) => {
|
||||
<SimpleList
|
||||
data={notebooks}
|
||||
type="notebooks"
|
||||
refreshing={refreshing}
|
||||
focused={isFocused}
|
||||
onRefresh={_onRefresh}
|
||||
renderItem={_renderItem}
|
||||
hideMore={params.hideMore}
|
||||
isMove={params.isMove}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {useIsFocused} from 'react-navigation-hooks';
|
||||
import Container from '../../components/Container';
|
||||
import {AddTopicEvent} from '../../components/DialogManager/recievers';
|
||||
import {NotebookPlaceHolder} from '../../components/ListPlaceholders';
|
||||
import {NotebookItem} from '../../components/NotebookItem';
|
||||
import SelectionWrapper from '../../components/SelectionWrapper';
|
||||
import SimpleList from '../../components/SimpleList';
|
||||
import {useTracked} from '../../provider';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
import {
|
||||
@@ -15,10 +18,7 @@ import {
|
||||
eOnNewTopicAdded,
|
||||
eScrollEvent,
|
||||
} from '../../services/events';
|
||||
import {ToastEvent, w, db} from '../../utils/utils';
|
||||
import SimpleList from '../../components/SimpleList';
|
||||
import {NotebookPlaceHolder} from '../../components/ListPlaceholders';
|
||||
import {AddTopicEvent} from '../../components/DialogManager/recievers';
|
||||
import {db, ToastEvent, w} from '../../utils/utils';
|
||||
|
||||
export const Notebook = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
@@ -144,9 +144,9 @@ export const Notebook = ({navigation}) => {
|
||||
<SimpleList
|
||||
data={topics}
|
||||
type="topics"
|
||||
refreshing={refreshing}
|
||||
customRefreshing={refreshing}
|
||||
focused={isFocused}
|
||||
onRefresh={_onRefresh}
|
||||
customRefresh={_onRefresh}
|
||||
renderItem={_renderItem}
|
||||
placeholder={<NotebookPlaceHolder colors={colors} />}
|
||||
placeholderText="Topics added to notebook appear here."
|
||||
|
||||
@@ -124,7 +124,6 @@ export const Notes = ({navigation}) => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await db.sync();
|
||||
|
||||
init();
|
||||
dispatch({type: ACTIONS.USER});
|
||||
setRefreshing(false);
|
||||
@@ -184,9 +183,9 @@ export const Notes = ({navigation}) => {
|
||||
<SimpleList
|
||||
data={notes}
|
||||
type="notes"
|
||||
refreshing={refreshing}
|
||||
customRefreshing={refreshing}
|
||||
focused={isFocused}
|
||||
onRefresh={_onRefresh}
|
||||
customRefresh={_onRefresh}
|
||||
renderItem={_renderItem}
|
||||
placeholder={<NotesPlaceHolder colors={colors} />}
|
||||
placeholderText={`Add some notes to this" ${
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Dimensions, Text, TouchableOpacity, View } from 'react-native';
|
||||
import React, {useEffect} from 'react';
|
||||
import {Text, TouchableOpacity, View} from 'react-native';
|
||||
import {useIsFocused} from 'react-navigation-hooks';
|
||||
import {pv, SIZE, WEIGHT} from '../../common/common';
|
||||
import Container from '../../components/Container';
|
||||
@@ -12,7 +12,6 @@ import NavigationService from '../../services/NavigationService';
|
||||
export const Tags = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, tags} = state;
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const isFocused = useIsFocused();
|
||||
useEffect(() => {
|
||||
if (isFocused) {
|
||||
@@ -24,10 +23,6 @@ export const Tags = ({ navigation }) => {
|
||||
}
|
||||
}, [isFocused]);
|
||||
|
||||
const _onRefresh = () => {
|
||||
//Handle
|
||||
};
|
||||
|
||||
const _renderItem = ({item, index}) => (
|
||||
<TouchableOpacity
|
||||
key={item.title}
|
||||
@@ -94,9 +89,7 @@ export const Tags = ({ navigation }) => {
|
||||
<SimpleList
|
||||
data={tags}
|
||||
type="tags"
|
||||
refreshing={refreshing}
|
||||
focused={isFocused}
|
||||
onRefresh={_onRefresh}
|
||||
renderItem={_renderItem}
|
||||
placeholder={<TagsPlaceHolder colors={colors} />}
|
||||
placeholderText="Tags added to notes appear here"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import React, {useEffect} from 'react';
|
||||
import {useIsFocused} from 'react-navigation-hooks';
|
||||
import Container from '../../components/Container';
|
||||
import {simpleDialogEvent} from '../../components/DialogManager/recievers';
|
||||
import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/templates';
|
||||
import {TrashPlaceHolder} from '../../components/ListPlaceholders';
|
||||
import {NotebookItem} from '../../components/NotebookItem';
|
||||
import NoteItem from '../../components/NoteItem';
|
||||
@@ -8,14 +10,11 @@ import SelectionWrapper from '../../components/SelectionWrapper';
|
||||
import SimpleList from '../../components/SimpleList';
|
||||
import {useTracked} from '../../provider';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
import {db, ToastEvent, w} from '../../utils/utils';
|
||||
import {simpleDialogEvent} from '../../components/DialogManager/recievers';
|
||||
import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/templates';
|
||||
import {w} from '../../utils/utils';
|
||||
|
||||
export const Trash = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, selectionMode, trash} = state;
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const isFocused = useIsFocused();
|
||||
useEffect(() => {
|
||||
@@ -84,20 +83,6 @@ export const Trash = ({navigation}) => {
|
||||
</SelectionWrapper>
|
||||
);
|
||||
|
||||
const _onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await db.sync();
|
||||
setRefreshing(false);
|
||||
ToastEvent.show('Sync Complete', 'success');
|
||||
} catch (e) {
|
||||
setRefreshing(false);
|
||||
ToastEvent.show('Sync failed, network error', 'error');
|
||||
}
|
||||
dispatch({type: ACTIONS.TRASH});
|
||||
dispatch({type: ACTIONS.USER});
|
||||
};
|
||||
|
||||
return (
|
||||
<Container
|
||||
bottomButtonOnPress={() => {
|
||||
@@ -114,9 +99,7 @@ export const Trash = ({navigation}) => {
|
||||
<SimpleList
|
||||
data={trash}
|
||||
type="trash"
|
||||
refreshing={refreshing}
|
||||
focused={isFocused}
|
||||
onRefresh={_onRefresh}
|
||||
renderItem={_renderItem}
|
||||
placeholder={<TrashPlaceHolder colors={colors} />}
|
||||
placeholderText="Deleted notes & notebooks appear here."
|
||||
|
||||
Reference in New Issue
Block a user