diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js index 1c3261e08..ee2e0ec1e 100644 --- a/apps/mobile/src/components/AddNotebookDialog/index.js +++ b/apps/mobile/src/components/AddNotebookDialog/index.js @@ -101,9 +101,8 @@ export const AddNotebookDialog = ({visible, close, toEdit = null}) => { title, description, topics, - timestamp: toEdit ? toEdit.dateCreated : null, + timestamp: toEdit && toEdit.dateCreated ? toEdit.dateCreated : null, }); - console.log(title, description, topics, toEdit.dateCreated); ToastEvent.show('New notebook added', 'success', 3000, () => {}, ''); setTopics(['']); diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js index a65a23a2b..0c15b154d 100644 --- a/apps/mobile/src/components/NotebookItem/index.js +++ b/apps/mobile/src/components/NotebookItem/index.js @@ -283,7 +283,6 @@ export const NotebookItem = ({ }} textStyle={{ color: colors.pri, - fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> @@ -319,24 +318,18 @@ export const NotebookItem = ({ Edit - - Pin - { hideMenu(); + db.pinItem(item.type, item.dateCreated); + refresh(); + ToastEvent.show( - 'Note added to favorites.', - 'success', + `Notebook ${item.pinned ? 'unpinned' : 'pinned'}`, + item.pinned ? 'error' : 'success', 3000, () => {}, - 'Ok', + '', ); }} textStyle={{ @@ -345,7 +338,31 @@ export const NotebookItem = ({ fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> - Favorite + {item.pinned ? 'Unpin' : 'Pin'} + + { + hideMenu(); + db.favoriteItem(item.type, item.dateCreated); + + refresh(); + ToastEvent.show( + `Notebook ${ + item.favorite ? 'removed' : 'added' + } to favorites.`, + item.favorite ? 'error' : 'success', + 3000, + () => {}, + '', + ); + }} + textStyle={{ + color: colors.pri, + + fontFamily: WEIGHT.regular, + fontSize: SIZE.sm, + }}> + {item.favorite ? 'Unfavorite' : 'Favorite'} item.dateCreated.toString()} @@ -352,7 +352,7 @@ export const NotesList = ({ ) : ( item.dateCreated.toString()} + //keyExtractor={(item, index) => item.dateCreated.toString()} ListFooterComponent={ } - ListEmptyComponent={ - - - {isFavorites ? ( - - ) : null} - - - - - - - - - - - {isFavorites ? ( - - ) : null} - - - - - - - - - - {isFavorites ? ( - - ) : null} - - - - - - - - - - - {emptyPlaceholderText} - - - No Notes found - - - } onScroll={event => { y = event.nativeEvent.contentOffset.y; onScroll(y); @@ -648,7 +410,12 @@ export const NotesList = ({ } renderItem={({item, index}) => ( - + refresh()} + numColumns={numColumns} + index={index} + /> )} /> ); diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js index 5e8d97c22..14cba7c92 100644 --- a/apps/mobile/src/views/Favorites/index.js +++ b/apps/mobile/src/views/Favorites/index.js @@ -1,5 +1,12 @@ import React, {useEffect, useState} from 'react'; -import {Dimensions, KeyboardAvoidingView} from 'react-native'; +import { + Dimensions, + KeyboardAvoidingView, + View, + Text, + FlatList, + Platform, +} from 'react-native'; import {Header} from '../../components/header'; import {AnimatedSafeAreaView} from '../Home'; @@ -7,7 +14,10 @@ import {useAppContext} from '../../provider/useAppContext'; import * as Animatable from 'react-native-animatable'; import {Search} from '../../components/SearchInput'; import {db} from '../../../App'; -import {NotesList} from '../../components/NotesList'; +import Icon from 'react-native-vector-icons/Feather'; +import {SIZE, WEIGHT} from '../../common/common'; +import NoteItem from '../../components/NoteItem'; +import {NotebookItem} from '../../components/NotebookItem'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; @@ -38,6 +48,29 @@ export const Favorites = ({navigation}) => { 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(() => { @@ -90,12 +123,114 @@ export const Favorites = ({navigation}) => { ) : null} - { - fetchFavs(); + item.dateCreated.toString()} + style={{ + width: '100%', + alignSelf: 'center', + height: '100%', }} - onScroll={y => { + contentContainerStyle={{ + height: '100%', + }} + ListHeaderComponent={ + + } + ListEmptyComponent={ + + + + + + + + + + + + + + Favorite notes & notebooks appear here. + + + Favorites are empty. + + + } + data={favs} + onScroll={event => { + let y = event.nativeEvent.contentOffset.y; if (buttonHide) return; if (y < 30) setHideHeader(false); if (y > offsetY) { @@ -111,11 +246,25 @@ export const Favorites = ({navigation}) => { } offsetY = y; }} - isFavorites={true} - isSearch={false} - emptyPlaceholderText="Your favorite notes will appear here" - notes={favs} - keyword={''} + renderItem={({item, index}) => + item.type === 'note' ? ( + { + fetchFavs(); + }} + index={index} + /> + ) : ( + { + fetchFavs(); + }} + index={index} + /> + ) + } /> diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js index 461cd5dca..39935be07 100755 --- a/apps/mobile/src/views/Home/index.js +++ b/apps/mobile/src/views/Home/index.js @@ -9,7 +9,7 @@ import { } from 'react-native'; import {COLOR_SCHEME, opacity, pv, br, SIZE, WEIGHT} from '../../common/common'; import {Search} from '../../components/SearchInput'; -import {w, h, SideMenuEvent, getElevation} from '../../utils/utils'; +import {w, h, SideMenuEvent, getElevation, ToastEvent} from '../../utils/utils'; import {Header} from '../../components/header'; import {NotesList} from '../../components/NotesList'; import {db} from '../../../App'; @@ -88,17 +88,18 @@ export const Home = ({navigation}) => { const onSubmitEditing = async () => { if (!text || text.length < 1) { setSearch(false); - if (allNotes) { - setNotes(allNotes); - } else { - fetchNotes(); - } + + fetchNotes(); } else { - setSearch(true); setKeyword(text); searchResults = await db.searchNotes(text); - if (searchResults) { - setNotes(searchResults); + console.log(searchResults, 'hello'); + if (searchResults && searchResults.length > 0) { + setNotes([...[]]); + setSearch(true); + setNotes([...searchResults]); + } else { + ToastEvent.show('No search results found', 'error', 3000, () => {}, ''); } } }; @@ -106,11 +107,7 @@ export const Home = ({navigation}) => { const onBlur = () => { if (text && text.length < 2) { setSearch(false); - if (allNotes) { - setNotes(allNotes); - } else { - fetchNotes(); - } + fetchNotes(); } }; @@ -121,11 +118,8 @@ export const Home = ({navigation}) => { const clearSearch = () => { searchResults = null; setSearch(false); - if (allNotes) { - setNotes(allNotes); - } else { - fetchNotes(); - } + + fetchNotes(); }; // Render diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js index 9771a7aea..4477b9ead 100644 --- a/apps/mobile/src/views/Trash/index.js +++ b/apps/mobile/src/views/Trash/index.js @@ -26,29 +26,6 @@ export const Trash = ({navigation}) => { setTrash([...allTrash]); }, []); - 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}], - }, - }; - const rotate = { 0: { transform: [{rotateZ: '0deg'}, {translateX: 0}, {translateY: 0}],