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