Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add selection wrapper in all list items.

ammarahm-ed153e8f1757e2
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 1c79fe7f9..8e9e7de23 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -39,7 +39,7 @@ const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
const NoteItem = props => {
- const {colors} = useAppContext();
+ const {colors, updateDB} = useAppContext();
const [visible, setVisible] = useState(false);
const [vaultDialog, setVaultDialog] = useState(false);
const [unlock, setUnlock] = useState(false);
@@ -79,7 +79,7 @@ const NoteItem = props => {
await db.deleteNotes([item]);
ToastEvent.show('Note moved to trash', 'success', 3000);
setVisible(false);
- props.refresh();
+ updateDB();
};
return (
<View
@@ -114,7 +114,7 @@ const NoteItem = props => {
setVaultDialog(false);
setUnlock(false);
setIsPerm(false);
- props.refresh();
+ updateDB();
}}
note={item}
perm={isPerm}
@@ -317,7 +317,7 @@ const NoteItem = props => {
onClose={() => {
onMenuHide();
if (willRefresh) {
- props.refresh();
+ updateDB();
}
}}>
<ActionSheetComponent
diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js
index 1e6606b62..d5f66b2a3 100644
--- a/apps/mobile/src/components/NotebookItem/index.js
+++ b/apps/mobile/src/components/NotebookItem/index.js
@@ -24,12 +24,14 @@ export const NotebookItem = ({
notebookID,
numColumns,
isTrash,
- refresh = () => {},
+ customStyle,
+ onLongPress,
}) => {
- const {colors} = useAppContext();
+ const {colors, updateDB} = useAppContext();
const [isVisible, setVisible] = useState(false);
const [addTopic, setAddTopic] = useState(false);
const [addNotebook, setAddNotebook] = useState(false);
+ let actionSheet;
let setMenuRef = {};
let show = null;
let willRefresh;
@@ -43,7 +45,7 @@ export const NotebookItem = ({
ToastEvent.show('Notebook moved to trash', 'success', 3000);
}
setVisible(false);
- refresh();
+ updateDB();
};
const navigate = () => {
@@ -79,22 +81,23 @@ export const NotebookItem = ({
const showMenu = () => {
setMenuRef[index].show();
};
+
return (
<View
- style={{
- marginHorizontal: '5%',
- paddingVertical: isTopic ? pv / 2 : pv,
- borderRadius: br,
- justifyContent: 'flex-start',
- alignItems: 'center',
- flexDirection: 'row',
- paddingRight: 6,
- marginHorizontal: 12,
- width: w - 24,
- alignSelf: 'center',
- borderBottomWidth: 1,
- borderBottomColor: colors.nav,
- }}>
+ style={[
+ {
+ paddingVertical: isTopic ? pv / 2 : pv,
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ flexDirection: 'row',
+ paddingRight: 6,
+ marginHorizontal: 12,
+ alignSelf: 'center',
+ borderBottomWidth: 1,
+ borderBottomColor: colors.nav,
+ },
+ customStyle,
+ ]}>
<Dialog
visible={isVisible}
title={`Delete ${isTopic ? 'topic' : 'notebook'}`}
@@ -130,6 +133,7 @@ export const NotebookItem = ({
style={{
width: '75%',
}}
+ onLongPress={onLongPress}
onPress={navigate}>
<Text
numberOfLines={1}
@@ -276,7 +280,7 @@ export const NotebookItem = ({
alignItems: 'center',
}}
onPress={() => {
- ActionSheet._setModalVisible();
+ actionSheet._setModalVisible();
}}>
<Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />
</TouchableOpacity>
@@ -333,6 +337,7 @@ export const NotebookItem = ({
</View>
<ActionSheet
+ ref={ref => (actionSheet = ref)}
customStyles={{
backgroundColor: colors.bg,
}}
@@ -341,7 +346,7 @@ export const NotebookItem = ({
onClose={() => {
onMenuHide();
if (willRefresh) {
- refresh();
+ updateDB();
}
}}
children={
@@ -363,7 +368,7 @@ export const NotebookItem = ({
if (value) {
show = value;
}
- ActionSheet._setModalVisible();
+ actionSheet._setModalVisible();
}}
/>
}
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 01674092f..0c89fd07d 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -16,15 +16,12 @@ import Icon from 'react-native-vector-icons/Feather';
import {NotesPlaceHolder} from '../ListPlaceholders';
import {slideRight, slideLeft} from '../../utils/animations';
import {w} from '../../utils/utils';
+import SelectionWrapper from '../SelectionWrapper';
export const NotesList = ({
- keyword = null,
notes,
- margin,
onScroll,
isSearch = false,
isGrouped = false,
- isFavorites = false,
- emptyPlaceholderText = '',
refresh = () => {},
}) => {
const {
@@ -33,17 +30,12 @@ export const NotesList = ({
selectedItemsList,
changeSelectionMode,
updateSelectionList,
+ pinned,
} = useAppContext();
- const [numColumns, setNumColumns] = useState(1);
- const [pinned, setPinned] = useState([]);
-
useEffect(() => {
- let pinnedItems = db.getPinned();
-
- setPinned([...pinnedItems]);
+ console.log(notes, pinned);
}, [notes]);
-
return isGrouped && !isSearch ? (
<SectionList
sections={notes}
@@ -126,14 +118,14 @@ export const NotesList = ({
width: '100%',
paddingHorizontal: '5%',
paddingTop: 20,
+ marginHorizontal: 0,
marginBottom: 10,
+ paddingHorizontal: 12,
marginTop: 20,
borderBottomWidth: 0,
}}
pinned={true}
- refresh={() => refresh()}
item={item}
- numColumns={1}
index={index}
/>
) : null
@@ -168,42 +160,7 @@ export const NotesList = ({
) : null
}
renderItem={({item, index}) => (
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- width: w - 24,
- marginHorizontal: 12,
- }}>
- <TouchableOpacity
- onPress={() => updateSelectionList(item)}
- style={{
- width: 50,
- height: 70,
- justifyContent: 'center',
- alignItems: 'flex-start',
- display: selectionMode ? 'flex' : 'none',
- }}>
- <View
- style={{
- borderWidth: 2,
- borderColor: selectedItemsList.includes(item)
- ? colors.accent
- : colors.icon,
- width: 30,
- height: 30,
- justifyContent: 'center',
- alignItems: 'center',
- borderRadius: 100,
- paddingTop: 4,
- }}>
- {selectedItemsList.includes(item) ? (
- <Icon size={SIZE.md} color={colors.accent} name="check" />
- ) : null}
- </View>
- </TouchableOpacity>
-
+ <SelectionWrapper item={item}>
<NoteItem
customStyle={{
width: selectionMode ? w - 74 : '100%',
@@ -211,13 +168,12 @@ export const NotesList = ({
}}
onLongPress={() => {
changeSelectionMode(!selectionMode);
+ updateSelectionList(item);
}}
item={item}
- refresh={() => refresh()}
- numColumns={numColumns}
index={index}
/>
- </View>
+ </SelectionWrapper>
)}
/>
) : (
@@ -281,42 +237,7 @@ export const NotesList = ({
</View>
}
renderItem={({item, index}) => (
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- width: w - 24,
- marginHorizontal: 12,
- }}>
- <TouchableOpacity
- onPress={() => updateSelectionList(item)}
- style={{
- width: 50,
- height: 70,
- justifyContent: 'center',
- alignItems: 'flex-start',
- display: selectionMode ? 'flex' : 'none',
- }}>
- <View
- style={{
- borderWidth: 2,
- borderColor: selectedItemsList.includes(item)
- ? colors.accent
- : colors.icon,
- width: 30,
- height: 30,
- justifyContent: 'center',
- alignItems: 'center',
- borderRadius: 100,
- paddingTop: 4,
- }}>
- {selectedItemsList.includes(item) ? (
- <Icon size={SIZE.md} color={colors.accent} name="check" />
- ) : null}
- </View>
- </TouchableOpacity>
-
+ <SelectionWrapper item={item}>
<NoteItem
customStyle={{
width: selectionMode ? w - 74 : '100%',
@@ -324,13 +245,12 @@ export const NotesList = ({
}}
onLongPress={() => {
changeSelectionMode(!selectionMode);
+ updateSelectionList(item);
}}
item={item}
- refresh={() => refresh()}
- numColumns={numColumns}
index={index}
/>
- </View>
+ </SelectionWrapper>
)}
/>
);
diff --git a/apps/mobile/src/components/SelectionWrapper/index.js b/apps/mobile/src/components/SelectionWrapper/index.js
new file mode 100644
index 000000000..9249a5fbd
--- /dev/null
+++ b/apps/mobile/src/components/SelectionWrapper/index.js
@@ -0,0 +1,52 @@
+import React from 'react';
+import {View, TouchableOpacity} from 'react-native';
+import {SIZE} from '../../common/common';
+import Icon from 'react-native-vector-icons/Feather';
+import {w} from '../../utils/utils';
+import {useAppContext} from '../../provider/useAppContext';
+
+const SelectionWrapper = ({children, item}) => {
+ const {colors, selectedItemsList, selectionMode} = useAppContext();
+ return (
+ <View
+ style={{
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ width: w - 24,
+ marginHorizontal: 12,
+ }}>
+ <TouchableOpacity
+ onPress={() => updateSelectionList(item)}
+ style={{
+ width: 50,
+ height: 70,
+ justifyContent: 'center',
+ alignItems: 'flex-start',
+ display: selectionMode ? 'flex' : 'none',
+ }}>
+ <View
+ style={{
+ borderWidth: 2,
+ borderColor: selectedItemsList.includes(item)
+ ? colors.accent
+ : colors.icon,
+ width: 30,
+ height: 30,
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderRadius: 100,
+ paddingTop: 4,
+ }}>
+ {selectedItemsList.includes(item) ? (
+ <Icon size={SIZE.md} color={colors.accent} name="check" />
+ ) : null}
+ </View>
+ </TouchableOpacity>
+
+ {children}
+ </View>
+ );
+};
+
+export default SelectionWrapper;
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index fca01e404..16b6d3421 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -1,33 +1,29 @@
-import React, {useEffect, useState} from 'react';
-import {
- KeyboardAvoidingView,
- View,
- Text,
- FlatList,
- Platform,
-} from 'react-native';
+import React, {useState} from 'react';
+import {View, Text, FlatList, Platform} from 'react-native';
import {Header} from '../../components/header';
-import {AnimatedSafeAreaView} from '../Home';
import {useAppContext} from '../../provider/useAppContext';
import * as Animatable from 'react-native-animatable';
import {Search} from '../../components/SearchInput';
-import {db} from '../../../App';
import {SIZE, WEIGHT} from '../../common/common';
import NoteItem from '../../components/NoteItem';
import {NotebookItem} from '../../components/NotebookItem';
import {FavoritesPlaceHolder} from '../../components/ListPlaceholders';
+import Container from '../../components/Container';
export const Favorites = ({navigation}) => {
// Global State
- const {colors} = useAppContext();
+ const {
+ colors,
+ favorites,
+ selectionMode,
+ changeSelectionMode,
+ updateSelectionList,
+ } = useAppContext();
// Local State
-
const [text, setText] = useState('');
- const [margin, setMargin] = useState(185);
const [hideHeader, setHideHeader] = useState(false);
- const [favs, setFavs] = useState([]);
const [buttonHide, setButtonHide] = useState(false);
// Variables
@@ -38,180 +34,154 @@ export const Favorites = ({navigation}) => {
// Functions
- const fetchFavs = () => {
- let favs = db.getFavorites();
- if (!favs) return;
- setFavs([...favs]);
- };
-
- const slideRight = {
- 0: {
- transform: [{translateX: -4}],
- },
- 0.5: {
- transform: [{translateX: 0}],
- },
- 1: {
- transform: [{translateX: 4}],
- },
- };
- const slideLeft = {
- 0: {
- transform: [{translateX: 4}],
- },
- 0.5: {
- transform: [{translateX: 0}],
- },
- 1: {
- transform: [{translateX: -4}],
- },
- };
-
// Effects
-
- useEffect(() => {
- fetchFavs();
- }, []);
-
+ const onScroll = event => {
+ let y = event.nativeEvent.contentOffset.y;
+ if (buttonHide) return;
+ if (y < 30) setHideHeader(false);
+ if (y > offsetY) {
+ if (y - offsetY < 150 || countDown > 0) return;
+ countDown = 1;
+ countUp = 0;
+ setHideHeader(true);
+ } else {
+ if (offsetY - y < 150 || countUp > 0) return;
+ countDown = 0;
+ countUp = 1;
+ setHideHeader(false);
+ }
+ offsetY = y;
+ };
// Render
return (
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{
- height: '100%',
- backgroundColor: colors.bg,
- }}>
- <KeyboardAvoidingView
+ <Container noBottomButton={true}>
+ <Animatable.View
+ transition="backgroundColor"
+ duration={300}
style={{
- height: '100%',
+ position: 'absolute',
+ backgroundColor: colors.night ? colors.bg : colors.bg,
+ zIndex: 10,
+ width: '100%',
}}>
- <Animatable.View
- transition="backgroundColor"
- duration={300}
- style={{
- position: 'absolute',
- backgroundColor: colors.night ? colors.bg : colors.bg,
- zIndex: 10,
- width: '100%',
- }}>
- <Header
- menu={true}
+ <Header
+ menu={true}
+ hide={hideHeader}
+ showSearch={() => {
+ setHideHeader(false);
+ countUp = 0;
+ countDown = 0;
+ }}
+ colors={colors}
+ heading="Favorites"
+ canGoBack={false}
+ customIcon="menu"
+ />
+ {favorites.length > 0 ? (
+ <Search
+ clear={() => setText('')}
hide={hideHeader}
- showSearch={() => {
- setHideHeader(false);
- countUp = 0;
- countDown = 0;
- }}
- colors={colors}
- heading="Favorites"
- canGoBack={false}
- customIcon="menu"
+ placeholder="Search your notes"
+ value={text}
/>
- {favs.length > 0 ? (
- <Search
- clear={() => setText('')}
- hide={hideHeader}
- placeholder="Search your notes"
- value={text}
- />
- ) : null}
- </Animatable.View>
+ ) : null}
+ </Animatable.View>
- <FlatList
- //keyExtractor={item => item.dateCreated.toString()}
- style={{
- width: '100%',
- alignSelf: 'center',
- height: '100%',
- }}
- contentContainerStyle={{
- height: '100%',
- }}
- ListHeaderComponent={
- <View
+ <FlatList
+ //keyExtractor={item => item.dateCreated.toString()}
+ style={{
+ width: '100%',
+ alignSelf: 'center',
+ height: '100%',
+ }}
+ contentContainerStyle={{
+ height: '100%',
+ }}
+ ListHeaderComponent={
+ <View
+ style={{
+ marginTop:
+ Platform.OS == 'ios'
+ ? favorites[0]
+ ? 135
+ : 135 - 60
+ : favorites[0]
+ ? 155
+ : 155 - 60,
+ }}></View>
+ }
+ ListEmptyComponent={
+ <View
+ style={{
+ height: '80%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 0.8,
+ }}>
+ <FavoritesPlaceHolder />
+ <Text
style={{
- marginTop:
- Platform.OS == 'ios'
- ? favs[0]
- ? 135
- : 135 - 60
- : favs[0]
- ? 175
- : 175 - 60,
- }}></View>
- }
- ListEmptyComponent={
- <View
+ color: colors.pri,
+ fontSize: SIZE.md,
+ fontFamily: WEIGHT.regular,
+ marginTop: 20,
+ }}>
+ Favorite notes & notebooks appear here.
+ </Text>
+ <Text
style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
+ fontSize: SIZE.sm,
+ color: colors.icon,
+ marginTop: 20,
}}>
- <FavoritesPlaceHolder />
- <Text
- style={{
- color: colors.pri,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- marginTop: 20,
- }}>
- Favorite notes & notebooks appear here.
- </Text>
- <Text
- style={{
- fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
- }}>
- Favorites are empty.
- </Text>
- </View>
- }
- data={favs}
- onScroll={event => {
- let y = event.nativeEvent.contentOffset.y;
- if (buttonHide) return;
- if (y < 30) setHideHeader(false);
- if (y > offsetY) {
- if (y - offsetY < 150 || countDown > 0) return;
- countDown = 1;
- countUp = 0;
- setHideHeader(true);
- } else {
- if (offsetY - y < 150 || countUp > 0) return;
- countDown = 0;
- countUp = 1;
- setHideHeader(false);
- }
- offsetY = y;
- }}
- renderItem={({item, index}) =>
- item.type === 'note' ? (
+ Favorites are empty.
+ </Text>
+ </View>
+ }
+ data={favorites}
+ onScroll={onScroll}
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
+ {item.type === 'note' ? (
<NoteItem
- item={item}
- refresh={() => {
- fetchFavs();
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
}}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+ changeSelectionMode(!selectionMode);
+ }}
+ item={item}
index={index}
+ isTrash={true}
/>
) : (
<NotebookItem
- item={item}
- refresh={() => {
- fetchFavs();
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+ changeSelectionMode(!selectionMode);
}}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ item={item}
+ isTrash={true}
index={index}
/>
- )
- }
- />
- </KeyboardAvoidingView>
- </AnimatedSafeAreaView>
+ )}
+ </SelectionWrapper>
+ )}
+ />
+ </Container>
);
};
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 3984343b4..9a1104c32 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -1,279 +1,232 @@
-import React, {useEffect, useState} from 'react';
-import {
- View,
- Text,
- TouchableOpacity,
- Platform,
- KeyboardAvoidingView,
- FlatList,
-} from 'react-native';
-import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
-import Icon from 'react-native-vector-icons/Feather';
+import React, {useState} from 'react';
+import {View, Text, Platform, FlatList} from 'react-native';
+import {SIZE, WEIGHT} from '../../common/common';
import {AddNotebookDialog} from '../../components/AddNotebookDialog';
import {NotebookItem} from '../../components/NotebookItem';
import {Search} from '../../components/SearchInput';
-import {db} from '../../../App';
import {Header} from '../../components/header';
-import {AnimatedSafeAreaView} from '../Home';
import * as Animatable from 'react-native-animatable';
-import {NavigationEvents} from 'react-navigation';
import {useAppContext} from '../../provider/useAppContext';
import {NotebookPlaceHolder} from '../../components/ListPlaceholders';
import {slideRight, slideLeft} from '../../utils/animations';
-import {useIsFocused} from 'react-navigation-hooks';
+import Container from '../../components/Container';
+import SelectionHeader from '../../components/SelectionHeader';
+import SelectionWrapper from '../../components/SelectionWrapper';
import {w} from '../../utils/utils';
-export const Folders = ({navigation}) => {
- const {colors} = useAppContext();
+export const Folders = ({navigation}) => {
+ const {
+ colors,
+ notebooks,
+ pinned,
+ updateDB,
+ selectionMode,
+ changeSelectionMode,
+ updateSelectionList,
+ } = useAppContext();
const [addNotebook, setAddNotebook] = useState(false);
- const [notebooks, setNotebooks] = useState([]);
const [hideHeader, setHideHeader] = useState(false);
- const [buttonHide, setButtonHide] = useState(false);
- const [margin, setMargin] = useState(180);
- const [numColumns, setNumColumns] = useState(1);
- const [pinned, setPinned] = useState([]);
- const isFocused = useIsFocused();
const params = navigation.state.params;
let offsetY = 0;
let countUp = 0;
let countDown = 0;
- let headerHeight = 0;
- let searchHeight = 0;
- let marginSet = false;
-
- useEffect(() => {
- if (isFocused) {
- setNotebooks([...db.getNotebooks()]);
-
- let pinItems = db.getPinned();
- setPinned([...pinItems]);
- }
- }, [isFocused]);
-
- const refreshNotebooks = () => {
- let nb = db.getNotebooks();
- if (nb) {
- setNotebooks([...nb]);
+ const onScroll = event => {
+ y = event.nativeEvent.contentOffset.y;
+ if (y < 30) setHideHeader(false);
+ //if (buttonHide) return;
+ if (y > offsetY) {
+ if (y - offsetY < 150 || countDown > 0) return;
+ countDown = 1;
+ countUp = 0;
+ setHideHeader(true);
+ } else {
+ if (offsetY - y < 150 || countUp > 0) return;
+ countDown = 0;
+ countUp = 1;
+ setHideHeader(false);
}
+ offsetY = y;
};
return (
- <AnimatedSafeAreaView
- transition="backgroundColor"
- duration={300}
- style={{
- height: '100%',
- backgroundColor: colors.bg,
+ <Container
+ bottomButtonText="Add a new notebook"
+ bottomButtonOnPress={() => {
+ setAddNotebook(true);
}}>
- <NavigationEvents
- onDidBlur={() => {
- marginSet = false;
- }}
- />
<AddNotebookDialog
visible={addNotebook}
close={newNotes => {
setAddNotebook(false);
if (newNotes) {
- setNotebooks(db.getNotebooks());
+ updateDB();
}
}}
/>
- <KeyboardAvoidingView
+
+ <SelectionHeader />
+
+ <Animatable.View
+ transition={['backgroundColor', 'opacity', 'height']}
+ duration={300}
style={{
- height: '100%',
+ position: 'absolute',
+ backgroundColor: colors.bg,
+ height: selectionMode ? 0 : null,
+ opacity: selectionMode ? 0 : 1,
+ zIndex: 10,
+ width: '100%',
}}>
- <Animatable.View
- transition="backgroundColor"
- duration={300}
- style={{
- position: 'absolute',
- backgroundColor: colors.bg,
- zIndex: 10,
- width: '100%',
- }}>
- <Header
- hide={hideHeader}
- menu={params.canGoBack ? false : true}
- showSearch={() => {
- setHideHeader(false);
- countUp = 0;
- countDown = 0;
- }}
- colors={colors}
- heading={params.title}
- canGoBack={params.canGoBack}
- />
- {notebooks.length == 0 ? null : (
- <Search placeholder="Search your notebook" hide={hideHeader} />
- )}
- </Animatable.View>
-
- <FlatList
- style={{
- width: '100%',
- }}
- onScroll={event => {
- y = event.nativeEvent.contentOffset.y;
- if (y < 30) setHideHeader(false);
- if (buttonHide) return;
- if (y > offsetY) {
- if (y - offsetY < 150 || countDown > 0) return;
- countDown = 1;
- countUp = 0;
- setHideHeader(true);
- } else {
- if (offsetY - y < 150 || countUp > 0) return;
- countDown = 0;
- countUp = 1;
- setHideHeader(false);
- }
- offsetY = y;
+ <Header
+ hide={hideHeader}
+ menu={params.canGoBack ? false : true}
+ showSearch={() => {
+ setHideHeader(false);
+ countUp = 0;
+ countDown = 0;
}}
- ListHeaderComponent={
- <View
- style={{
- marginTop:
- Platform.OS == 'ios'
- ? notebooks[0]
- ? 135
- : 135 - 60
- : notebooks[0]
- ? 155
- : 155 - 60,
- }}>
- {pinned && pinned.length > 0 ? (
- <>
- <FlatList
- data={pinned}
- keyExtractor={(item, index) => item.dateCreated.toString()}
- renderItem={({item, index}) =>
- item.type === 'notebook' ? (
- <NoteItem
+ colors={colors}
+ heading={params.title}
+ canGoBack={params.canGoBack}
+ />
+ {notebooks.length == 0 ? null : (
+ <Search placeholder="Search your notebook" hide={hideHeader} />
+ )}
+ </Animatable.View>
+
+ <FlatList
+ style={{
+ width: '100%',
+ }}
+ onScroll={onScroll}
+ ListHeaderComponent={
+ <View
+ style={{
+ marginTop:
+ Platform.OS == 'ios'
+ ? notebooks[0] && !selectionMode
+ ? 135
+ : 135 - 60
+ : notebooks[0] && !selectionMode
+ ? 155
+ : 155 - 60,
+ }}>
+ {pinned && pinned.length > 0 ? (
+ <>
+ <FlatList
+ data={pinned}
+ keyExtractor={(item, index) => item.dateCreated.toString()}
+ renderItem={({item, index}) =>
+ item.type === 'notebook' ? (
+ <SelectionWrapper item={item}>
+ <NotebookItem
+ hideMore={params.hideMore}
customStyle={{
- backgroundColor: colors.shade,
- width: '100%',
- paddingHorizontal: '5%',
- paddingTop: 20,
- marginBottom: 10,
- marginTop: 20,
- borderBottomWidth: 0,
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
}}
- pinned={true}
- refresh={() => refresh()}
+ isMove={params.isMove}
+ onLongPress={() => {
+ changeSelectionMode();
+ }}
+ noteToMove={params.note}
item={item}
- numColumns={1}
+ pinned={true}
index={index}
+ colors={colors}
/>
- ) : null
- }
- />
- </>
- ) : null}
- </View>
- }
- ListEmptyComponent={
- pinned && pinned.length > 0 ? null : (
- <View
- style={{
- height: '80%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 0.8,
- }}>
- <NotebookPlaceHolder animation={slideRight} colors={colors} />
- <NotebookPlaceHolder animation={slideLeft} colors={colors} />
- <NotebookPlaceHolder animation={slideRight} colors={colors} />
-
- <Text
- style={{
- color: colors.icon,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- marginTop: 20,
- }}>
- Notebooks you add will appear here
- </Text>
- <Text
- style={{
- fontSize: SIZE.sm,
- color: colors.icon,
- marginTop: 20,
- }}>
- No Notebooks found
- </Text>
- </View>
- )
- }
- contentContainerStyle={{
- width: '100%',
- alignSelf: 'center',
- }}
- ListFooterComponent={
+ </SelectionWrapper>
+ ) : null
+ }
+ />
+ </>
+ ) : null}
+ </View>
+ }
+ ListEmptyComponent={
+ pinned && pinned.length > 0 ? null : (
<View
style={{
- height: 150,
+ height: '80%',
+ width: '100%',
alignItems: 'center',
+ alignSelf: 'center',
justifyContent: 'center',
+ opacity: 0.8,
}}>
+ <NotebookPlaceHolder animation={slideRight} colors={colors} />
+ <NotebookPlaceHolder animation={slideLeft} colors={colors} />
+ <NotebookPlaceHolder animation={slideRight} colors={colors} />
+
<Text
style={{
- color: colors.navbg,
- fontSize: SIZE.sm,
+ color: colors.icon,
+ fontSize: SIZE.md,
fontFamily: WEIGHT.regular,
+ marginTop: 20,
+ }}>
+ Notebooks you add will appear here
+ </Text>
+ <Text
+ style={{
+ fontSize: SIZE.sm,
+ color: colors.icon,
+ marginTop: 20,
}}>
- - End -
+ No Notebooks found
</Text>
</View>
- }
- data={notebooks}
- keyExtractor={(item, index) => item.dateCreated.toString()}
- renderItem={({item, index}) => (
+ )
+ }
+ contentContainerStyle={{
+ width: '100%',
+ alignSelf: 'center',
+ }}
+ ListFooterComponent={
+ <View
+ style={{
+ height: 150,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}>
+ <Text
+ style={{
+ color: colors.navbg,
+ fontSize: SIZE.sm,
+ fontFamily: WEIGHT.regular,
+ }}>
+ - End -
+ </Text>
+ </View>
+ }
+ data={notebooks}
+ keyExtractor={(item, index) => item.dateCreated.toString()}
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
<NotebookItem
hideMore={params.hideMore}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
isMove={params.isMove}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+
+ changeSelectionMode(!selectionMode);
+ }}
noteToMove={params.note}
item={item}
- numColumns={numColumns}
- refresh={() => refreshNotebooks()}
index={index}
- colors={colors}
/>
- )}
- />
- <TouchableOpacity
- activeOpacity={opacity}
- onPress={() => {
- setAddNotebook(true);
- }}
- style={{
- borderRadius: 5,
- width: w - 24,
- marginHorizontal: 12,
- paddingHorizontal: ph,
- paddingVertical: pv + 5,
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- marginBottom: 15,
- backgroundColor: colors.accent,
- }}>
- <Icon name="plus" color="white" size={SIZE.lg} />
- <Text
- style={{
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- color: 'white',
- }}>
- {' '}Create a new notebook
- </Text>
- </TouchableOpacity>
- </KeyboardAvoidingView>
- </AnimatedSafeAreaView>
+ </SelectionWrapper>
+ )}
+ />
+ </Container>
);
};
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 794b8db7b..875795906 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -16,44 +16,31 @@ import {NotebookItem} from '../../components/NotebookItem';
import {Dialog} from '../../components/Dialog';
import {ToastEvent, w} from '../../utils/utils';
import {TrashPlaceHolder} from '../../components/ListPlaceholders';
+import Container from '../../components/Container';
+import SelectionHeader from '../../components/SelectionHeader';
export const Trash = ({navigation}) => {
- const {colors} = useAppContext();
- const [trash, setTrash] = useState([]);
+ const {
+ colors,
+ trash,
+ updateDB,
+ selectionMode,
+ changeSelectionMode,
+ updateSelectionList,
+ } = useAppContext();
+
const [dialog, setDialog] = useState(false);
- useEffect(() => {
- let allTrash = db.getTrash();
- setTrash([...allTrash]);
- }, []);
return (
- <SafeAreaView
- style={{
- backgroundColor: colors.bg,
- height: '100%',
- }}>
- <Dialog
- title="Empty Trash"
- visible={dialog}
- close={() => {
- setDialog(false);
- }}
- icon="trash"
- paragraph="Clearing all trash cannot be undone."
- positiveText="Clear"
- negativeText="Cancel"
- positivePress={async () => {
- await db.clearTrash();
- let allTrash = db.getTrash();
- setTrash([...allTrash]);
- ToastEvent.show('Trash cleared', 'success', 1000, () => {}, '');
- setDialog(false);
- }}
- negativePress={() => {
- setDialog(false);
- }}
- />
- <Header colors={colors} heading="Trash" canGoBack={false} menu={true} />
+ <Container
+ bottomButtonOnPress={() => {
+ setDialog(true);
+ }}
+ bottomButtonText="Clear all trash">
+ <SelectionHeader />
+ {selectionMode ? null : (
+ <Header colors={colors} heading="Trash" canGoBack={false} menu={true} />
+ )}
<FlatList
keyExtractor={item => item.dateCreated.toString()}
@@ -96,42 +83,68 @@ export const Trash = ({navigation}) => {
</Text>
</View>
}
- renderItem={({item, index}) =>
- item.type === 'note' ? (
- <NoteItem item={item} index={index} isTrash={true} />
- ) : (
- <NotebookItem item={item} isTrash={true} index={index} />
- )
- }
+ renderItem={({item, index}) => (
+ <SelectionWrapper item={item}>
+ {item.type === 'note' ? (
+ <NoteItem
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+
+ changeSelectionMode(!selectionMode);
+ }}
+ item={item}
+ index={index}
+ isTrash={true}
+ />
+ ) : (
+ <NotebookItem
+ onLongPress={() => {
+ if (!selectionMode) {
+ updateSelectionList(item);
+ }
+
+ changeSelectionMode(!selectionMode);
+ }}
+ customStyle={{
+ width: selectionMode ? w - 74 : '100%',
+ marginHorizontal: 0,
+ }}
+ item={item}
+ isTrash={true}
+ index={index}
+ />
+ )}
+ </SelectionWrapper>
+ )}
/>
- <TouchableOpacity
- activeOpacity={opacity}
- onPress={() => {
- setDialog(true);
+
+ <Dialog
+ title="Empty Trash"
+ visible={dialog}
+ close={() => {
+ setDialog(false);
}}
- style={{
- borderRadius: 5,
- width: w - 24,
- marginHorizontal: 12,
- paddingHorizontal: ph,
- paddingVertical: pv + 5,
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- marginBottom: 20,
- backgroundColor: colors.accent,
- }}>
- <Icon name="trash" color="white" size={SIZE.lg} />
- <Text
- style={{
- fontSize: SIZE.md,
- fontFamily: WEIGHT.regular,
- color: 'white',
- }}>
- {' '}Clear all trash
- </Text>
- </TouchableOpacity>
- </SafeAreaView>
+ icon="trash"
+ paragraph="Clearing all trash cannot be undone."
+ positiveText="Clear"
+ negativeText="Cancel"
+ positivePress={async () => {
+ await db.clearTrash();
+ updateDB();
+ ToastEvent.show('Trash cleared', 'success', 1000, () => {}, '');
+ setDialog(false);
+ }}
+ negativePress={() => {
+ setDialog(false);
+ }}
+ />
+ </Container>
);
};