Skip to content

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

add new sort bottom sheet & save sort val

ammarahm-ed9e01b4a74948
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 5397eee36..e905651b6 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -30,6 +30,7 @@ import {MMKV} from './src/utils/mmkv';
import Backup from './src/services/Backup';
import {setLoginMessage} from './src/services/Message';
import SplashScreen from 'react-native-splash-screen';
+import {SORT, sortSettings} from "./src/utils";
let firstLoad = true;
let note = null;
@@ -157,8 +158,10 @@ const App = () => {
if (!user) {
setLoginMessage(dispatch);
}
+
dispatch({type: Actions.ALL});
setInit(true);
+
backupData().then(r=> r)
setTimeout(() => {
@@ -208,6 +211,8 @@ const App = () => {
if (settings.fontScale) {
scale.fontScale = settings.fontScale;
}
+ sortSettings.sort = settings.sort;
+ sortSettings.sortOrder = settings.sortOrder;
dispatch({type: Actions.SETTINGS, settings: {...settings}});
updateSize();
diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.js
index 69313156b..53b281a70 100644
--- a/apps/mobile/src/components/DialogManager/index.js
+++ b/apps/mobile/src/components/DialogManager/index.js
@@ -44,6 +44,7 @@ import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates';
import {hexToRGBA} from "../../utils/ColorUtils";
import {DDS} from "../../services/DeviceDetection";
import ResultDialog from '../ResultDialog';
+import Index from "../SortDialog";
export class DialogManager extends Component {
constructor(props) {
@@ -107,7 +108,6 @@ export class DialogManager extends Component {
item: {},
});
} else {
- note = i;
this.setState({
item: i,
});
@@ -333,18 +333,12 @@ export class DialogManager extends Component {
}}
/>
</ActionSheet>
-
<Dialog
ref={(ref) => (this.simpleDialog = ref)}
item={item}
colors={colors}
template={simpleDialog}
/>
-
- <VaultDialog colors={colors} />
-
- <MoveNoteDialog colors={colors} />
-
<AddTopicDialog
ref={(ref) => (this.addTopicsDialog = ref)}
toEdit={item.type === 'topic' ? item : null}
@@ -364,22 +358,19 @@ export class DialogManager extends Component {
ref={(ref) => (this.premiumDialog = ref)}
colors={colors}
/>
-
<LoginDialog colors={colors} />
-
<MergeEditor />
-
<ExportDialog />
-
<RecoveryKeyDialog colors={colors} />
<PendingDialog colors={colors} />
-
<PremiumStatusDialog />
<ProgressDialog />
-
<RestoreDialog/>
-
<ResultDialog/>
+ <VaultDialog colors={colors} />
+ <MoveNoteDialog colors={colors} />
+ <Index colors={colors} />
+
</>
);
}
diff --git a/apps/mobile/src/components/Header/HeaderMenu.js b/apps/mobile/src/components/Header/HeaderMenu.js
index ab761210d..8c445317b 100644
--- a/apps/mobile/src/components/Header/HeaderMenu.js
+++ b/apps/mobile/src/components/Header/HeaderMenu.js
@@ -1,104 +1,38 @@
-import React, {createRef} from 'react';
-import Menu, {MenuDivider, MenuItem} from 'react-native-material-menu';
+import React from 'react';
import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
-import {ActionIcon} from '../ActionIcon';
import {SIZE, WEIGHT} from "../../utils/SizeUtils";
+import {Text, TouchableOpacity} from "react-native";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import {eSendEvent} from "../../services/EventManager";
+import {eOpenSortDialog} from "../../utils/Events";
-const menuRef = createRef();
-export const HeaderMenu = () => {
- const [state, dispatch] = useTracked();
- const {colors, headerVerticalMenu} = state;
-
- const styles = {
- text:{
- fontFamily: WEIGHT.regular,
- color: colors.pri,
- fontSize: SIZE.sm,
- },
- title:{
- fontFamily: WEIGHT.regular,
- color: colors.icon,
- fontSize: SIZE.sm ,
- },
- action:{
- justifyContent: 'center',
- alignItems: 'flex-end',
- height: 40,
- width: 40,
- marginLeft: 10,
- borderRadius: 100,
- backgroundColor: colors.bg,
- }
- }
- return headerVerticalMenu ? (
- <Menu
- ref={menuRef}
- animationDuration={200}
- style={{
- borderRadius: 5,
- backgroundColor: colors.bg,
- paddingBottom:10,
- }}
- button={
- <ActionIcon
- onPress={() => {
- menuRef.current?.show();
- }}
- name="dots-vertical"
- size={SIZE.xl}
- color={colors.pri}
- customStyle={styles.action}
- />
- }>
- <MenuItem
- textStyle={styles.title}>
- Sort by:
- </MenuItem>
- <MenuItem
+export const HeaderMenu = () => {
+ const [state,] = useTracked();
+ const {colors,settings} = state;
- textStyle={styles.text}
- onPress={() => {
- dispatch({type: Actions.NOTES, sort: null});
- menuRef.current?.hide();
- }}>
- Default
- </MenuItem>
- <MenuItem
- textStyle={styles.text}
+ return <TouchableOpacity
onPress={() => {
- dispatch({type: Actions.NOTES, sort: 'abc'});
- menuRef.current?.hide();
- }}>
- Alphabetical
- </MenuItem>
- <MenuItem
- textStyle={styles.text}
- onPress={() => {
- dispatch({type: Actions.NOTES, sort: 'year'});
- menuRef.current?.hide();
- }}>
- By year
- </MenuItem>
- <MenuItem
- textStyle={styles.text}
- onPress={() => {
- dispatch({type: Actions.NOTES, sort: 'month'});
- menuRef.current?.hide();
- }}>
- By month
- </MenuItem>
- <MenuItem
- textStyle={styles.text}
- onPress={() => {
- dispatch({type: Actions.NOTES, sort: 'week'});
- menuRef.current?.hide();
+ eSendEvent(eOpenSortDialog);
+ }}
+ activeOpacity={1}
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
}}>
- By week
- </MenuItem>
- </Menu>
- ) : null;
+ <Text
+ style={{
+ fontSize: SIZE.xs + 1,
+ fontFamily: WEIGHT.regular,
+ color: colors.icon,
+ marginRight: 5
+ }}>
+ {settings.sort.slice(0,1).toUpperCase() + settings.sort.slice(1,settings.sort.length)}
+ </Text>
+ <Icon color={colors.icon}
+ name={settings.sortOrder === "asc" ? "sort-ascending" : "sort-descending"}
+ size={SIZE.md}/>
+ </TouchableOpacity>
};
diff --git a/apps/mobile/src/components/Header/index.js b/apps/mobile/src/components/Header/index.js
index 7b3973e1c..bb897d1ea 100644
--- a/apps/mobile/src/components/Header/index.js
+++ b/apps/mobile/src/components/Header/index.js
@@ -114,7 +114,6 @@ export const Header = ({showSearch, root}) => {
/>
</Animatable.View>
- <HeaderMenu />
</View>
</View>
);
diff --git a/apps/mobile/src/components/Premium/PendingDialog.js b/apps/mobile/src/components/Premium/PendingDialog.js
index 4f674eb5b..7a3b872c4 100644
--- a/apps/mobile/src/components/Premium/PendingDialog.js
+++ b/apps/mobile/src/components/Premium/PendingDialog.js
@@ -53,9 +53,7 @@ class PendingDialog extends React.Component {
<ActionSheet
containerStyle={{
backgroundColor: colors.bg,
- width: '100%',
alignSelf: 'center',
- borderRadius: 10,
width: DDS.isTab? 500 : '100%',
borderRadius: 10,
marginBottom: DDS.isTab ? 50 : 0,
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 2d8f961b1..4d0885641 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -1,12 +1,5 @@
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';
@@ -18,377 +11,390 @@ import {PressableButton} from '../PressableButton';
import {COLORS_NOTE} from '../../utils/Colors';
import {SIZE, WEIGHT} from '../../utils/SizeUtils';
import {db} from '../../utils/DB';
+import {HeaderMenu} from "../Header/HeaderMenu";
const header = {
- type: 'MAIN_HEADER',
+ type: 'MAIN_HEADER',
};
const SimpleList = ({
- data,
- type,
- placeholder,
- RenderItem,
- focused,
- customRefresh,
- customRefreshing,
- refreshCallback,
-}) => {
- const [state, dispatch] = useTracked();
- const {colors, selectionMode, user, messageBoardState} = state;
- const searchResults = {...state.searchResults};
- const [refreshing, setRefreshing] = useState(false);
- const [dataProvider, setDataProvider] = useState(
- new DataProvider((r1, r2) => {
- return r1 !== r2;
- }),
- );
- const {width, fontScale} = useWindowDimensions();
+ data,
+ type,
+ placeholder,
+ RenderItem,
+ focused,
+ customRefresh,
+ customRefreshing,
+ refreshCallback,
+ }) => {
+ const [state, dispatch] = useTracked();
+ const {colors, selectionMode, user, messageBoardState} = state;
+ const searchResults = {...state.searchResults};
+ const [refreshing, setRefreshing] = useState(false);
+ const [dataProvider, setDataProvider] = useState(
+ new DataProvider((r1, r2) => {
+ return r1 !== r2;
+ }),
+ );
+ const {width, fontScale} = useWindowDimensions();
- const listData = data;
- const dataType = type;
- const _onScroll = (event) => {
- if (!event) return;
- let y = event.nativeEvent.contentOffset.y;
- eSendEvent(eScrollEvent, y);
- };
+ const listData = data;
+ const dataType = type;
+ const _onScroll = (event) => {
+ if (!event) return;
+ let y = event.nativeEvent.contentOffset.y;
+ eSendEvent(eScrollEvent, y);
+ };
- useEffect(() => {
- loadData();
- }, [listData]);
+ useEffect(() => {
+ loadData();
+ }, [listData]);
- const loadData = () => {
- let mainData =
- searchResults.type === type &&
- focused() &&
- searchResults.results.length > 0
- ? searchResults.results
- : listData;
+ const loadData = () => {
+ let mainData =
+ searchResults.type === type &&
+ focused() &&
+ searchResults.results.length > 0
+ ? searchResults.results
+ : listData;
- let d = [header, ...mainData];
- setDataProvider(dataProvider.cloneWithRows(d));
- };
+ let d = [header, ...mainData];
+ setDataProvider(dataProvider.cloneWithRows(d));
+ };
- const RenderSectionHeader = ({item}) => (
- <Text
- style={[
- {
- color: colors.accent,
- },
- styles.sectionHeader,
- ]}>
- {item.title}
- </Text>
- );
+ const RenderSectionHeader = ({item,index}) => (
+ <View
+ style={{
+ flexDirection: "row",
+ alignItems: "center",
+ width: "100%",
+ justifyContent: "space-between",
+ paddingHorizontal: 12,
+ marginTop: 10,
+ height: 25,
+ }}
+ >
- const _onRefresh = useCallback(async () => {
- if (Platform.OS === 'ios') {
- dispatch({
- type: Actions.SYNCING,
- syncing: true,
- });
- } else {
- setRefreshing(true);
- }
- try {
- let user = await db.user.get();
- dispatch({type: Actions.USER, user: user});
- await db.sync();
- ToastEvent.show('Sync Complete', 'success');
- } catch (e) {
- ToastEvent.show(
- 'You must login to sync.',
- 'error',
- 'global',
- 5000,
- () => {
- eSendEvent(eOpenLoginDialog);
- },
- 'Login',
- );
- } finally {
- if (Platform.OS === 'ios') {
- dispatch({
- type: Actions.SYNCING,
- syncing: false,
- });
- } else {
- setRefreshing(false);
- }
- if (refreshCallback) {
- refreshCallback();
- }
- }
- dispatch({type: Actions.ALL});
- }, []);
+ <Text
+ style={[
+ {
+ color: colors.accent,
+ },
+ styles.sectionHeader,
+ ]}>
+ {item.title}
+ </Text>
+ {
+ index === 1? <HeaderMenu/> : null
+ }
+ </View>
+ );
- const _ListEmptyComponent = (
- <View
- style={[
- {
- backgroundColor: colors.bg,
- },
- styles.emptyList,
- ]}>
- <>{placeholder}</>
- </View>
- );
+ const _onRefresh = useCallback(async () => {
+ if (Platform.OS === 'ios') {
+ dispatch({
+ type: Actions.SYNCING,
+ syncing: true,
+ });
+ } else {
+ setRefreshing(true);
+ }
+ try {
+ let user = await db.user.get();
+ dispatch({type: Actions.USER, user: user});
+ await db.sync();
+ ToastEvent.show('Sync Complete', 'success');
+ } catch (e) {
+ ToastEvent.show(
+ 'You must login to sync.',
+ 'error',
+ 'global',
+ 5000,
+ () => {
+ eSendEvent(eOpenLoginDialog);
+ },
+ 'Login',
+ );
+ } finally {
+ if (Platform.OS === 'ios') {
+ dispatch({
+ type: Actions.SYNCING,
+ syncing: false,
+ });
+ } else {
+ setRefreshing(false);
+ }
+ if (refreshCallback) {
+ refreshCallback();
+ }
+ }
+ dispatch({type: Actions.ALL});
+ }, []);
- const _layoutProvider = new LayoutProvider(
- (index) => {
- return dataProvider.getDataForIndex(index).type;
- },
- (type, dim) => {
- switch (type) {
- case 'note':
- dim.width = width;
- dim.height = 100 * fontScale;
- break;
- case 'notebook':
- dim.width = width;
- dim.height = 110 * fontScale;
- break;
- case 'trash':
- dim.width = width;
- dim.height = 110 * fontScale;
- break;
- case 'topic':
- dim.width = width;
- dim.height = 80 * fontScale;
- break;
- case 'tag':
- dim.width = width;
- dim.height = 80 * fontScale;
- break;
- case 'header':
- dim.width = width;
- dim.height = 30 * fontScale;
- break;
- case 'MAIN_HEADER':
- dim.width = width;
- dim.height =
- !messageBoardState.visible || !listData[0] || selectionMode
- ? 0
- : 40 * fontScale;
- break;
- default:
- dim.width = width;
- dim.height = 0;
- }
- },
- );
+ const _ListEmptyComponent = (
+ <View
+ style={[
+ {
+ backgroundColor: colors.bg,
+ },
+ styles.emptyList,
+ ]}>
+ <>{placeholder}</>
+ </View>
+ );
- const _renderRow = (type, data, index) => {
+ const _layoutProvider = new LayoutProvider(
+ (index) => {
+ return dataProvider.getDataForIndex(index).type;
+ },
+ (type, dim) => {
+ switch (type) {
+ case 'note':
+ dim.width = width;
+ dim.height = 100 * fontScale;
+ break;
+ case 'notebook':
+ dim.width = width;
+ dim.height = 110 * fontScale;
+ break;
+ case 'trash':
+ dim.width = width;
+ dim.height = 110 * fontScale;
+ break;
+ case 'topic':
+ dim.width = width;
+ dim.height = 80 * fontScale;
+ break;
+ case 'tag':
+ dim.width = width;
+ dim.height = 80 * fontScale;
+ break;
+ case 'header':
+ dim.width = width;
+ dim.height = 30 * fontScale;
+ break;
+ case 'MAIN_HEADER':
+ dim.width = width;
+ dim.height =
+ !messageBoardState.visible || !listData[0] || selectionMode
+ ? 0
+ : 40 * fontScale;
+ break;
+ default:
+ dim.width = width;
+ dim.height = 0;
+ }
+ },
+ );
- switch (type) {
- case 'note':
- return <RenderItem item={data} pinned={data.pinned} index={index} />;
- case 'notebook':
- return <RenderItem item={data} pinned={data.pinned} index={index} />;
- case 'MAIN_HEADER':
- return <ListHeaderComponent type={dataType} data={listData} />;
- case 'header':
- return <RenderSectionHeader item={data} />;
- default:
- return <RenderItem item={data} index={index} />;
- }
- };
+ const _renderRow = (type, data, index) => {
- const listStyle = useMemo(() => {
- return {
- height: '100%',
- backgroundColor: colors.bg,
- width: '100%',
- paddingTop:
- Platform.OS === 'ios'
- ? listData[0] && !selectionMode
- ? 130
- : 130 - 60
- : listData[0] && !selectionMode
- ? 155 - initialWindowMetrics?.insets?.top
- : (155 - initialWindowMetrics?.insets?.top) - 60,
+ switch (type) {
+ case 'note':
+ return <RenderItem item={data} pinned={data.pinned} index={index}/>;
+ case 'notebook':
+ return <RenderItem item={data} pinned={data.pinned} index={index}/>;
+ case 'MAIN_HEADER':
+ return <ListHeaderComponent type={dataType} index={index} data={listData}/>;
+ case 'header':
+ return <RenderSectionHeader item={data} index={index}/>;
+ default:
+ return <RenderItem item={data} index={index}/>;
+ }
};
- }, [selectionMode, listData, colors]);
- return !listData || listData.length === 0 || !dataProvider ? (
- _ListEmptyComponent
- ) : (
- <RecyclerListView
- layoutProvider={_layoutProvider}
- dataProvider={dataProvider}
- rowRenderer={_renderRow}
- onScroll={_onScroll}
- renderFooter={() => <View style={{height: 400}} />}
- scrollViewProps={{
- refreshControl: (
- <RefreshControl
- tintColor={colors.accent}
- colors={[colors.accent]}
- progressViewOffset={150}
- onRefresh={customRefresh ? customRefresh : _onRefresh}
- refreshing={customRefresh ? customRefreshing : refreshing}
- />
- ),
- contentContainerStyle: {
- width: '100%',
- alignSelf: 'center',
- minHeight: '100%',
- },
- }}
- style={listStyle}
- />
- );
+ const listStyle = useMemo(() => {
+ return {
+ height: '100%',
+ backgroundColor: colors.bg,
+ width: '100%',
+ paddingTop:
+ Platform.OS === 'ios'
+ ? listData[0] && !selectionMode
+ ? 130
+ : 130 - 60
+ : listData[0] && !selectionMode
+ ? 155 - initialWindowMetrics?.insets?.top
+ : (155 - initialWindowMetrics?.insets?.top) - 60,
+ };
+ }, [selectionMode, listData, colors]);
+
+ return !listData || listData.length === 0 || !dataProvider ? (
+ _ListEmptyComponent
+ ) : (
+ <RecyclerListView
+ layoutProvider={_layoutProvider}
+ dataProvider={dataProvider}
+ rowRenderer={_renderRow}
+ onScroll={_onScroll}
+ renderFooter={() => <View style={{height: 400}}/>}
+ scrollViewProps={{
+ refreshControl: (
+ <RefreshControl
+ tintColor={colors.accent}
+ colors={[colors.accent]}
+ progressViewOffset={150}
+ onRefresh={customRefresh ? customRefresh : _onRefresh}
+ refreshing={customRefresh ? customRefreshing : refreshing}
+ />
+ ),
+ contentContainerStyle: {
+ width: '100%',
+ alignSelf: 'center',
+ minHeight: '100%',
+ },
+ }}
+ style={listStyle}
+ />
+ );
};
export default SimpleList;
const SearchHeader = () => {
- const [state] = useTracked();
- const {colors} = state;
- const searchResults = {...state.searchResults};
+ const [state] = useTracked();
+ const {colors} = state;
+ const searchResults = {...state.searchResults};
- return (
- <View style={styles.searchHeader}>
- <Text
- style={{
- fontFamily: WEIGHT.bold,
- color: colors.accent,
- fontSize: SIZE.xs,
- }}>
- Showing Results for {searchResults.keyword}
- </Text>
- <Text
- onPress={() => {
- eSendEvent(eClearSearch);
- }}
- style={{
- fontFamily: WEIGHT.regular,
- color: colors.errorText,
- fontSize: SIZE.xs,
- }}>
- Clear
- </Text>
- </View>
- );
-};
-
-const MessageCard = ({data}) => {
- const [state] = useTracked();
- const {colors, selectionMode, currentScreen, messageBoardState} = state;
-
- return (
- <View>
- {!messageBoardState.visible || !data[0] || selectionMode ? null : (
- <PressableButton
- onPress={messageBoardState.onPress}
- color={
- COLORS_NOTE[currentScreen]
- ? COLORS_NOTE[currentScreen]
- : colors.shade
- }
- selectedColor={
- COLORS_NOTE[currentScreen]
- ? COLORS_NOTE[currentScreen]
- : colors.accent
- }
- alpha={!colors.night ? -0.02 : 0.1}
- opacity={0.12}
- customStyle={styles.loginCard}>
- <View
- style={{
- width: 25,
- backgroundColor: COLORS_NOTE[currentScreen]
- ? COLORS_NOTE[currentScreen]
- : colors.accent,
- height: 25,
- borderRadius: 100,
- alignItems: 'center',
- justifyContent: 'center',
- }}>
- <Icon
- style={styles.loginIcon}
- name={messageBoardState.icon}
- color="white"
- size={SIZE.xs}
- />
- </View>
- <View
- style={{
- marginLeft: 10,
- }}>
+ return (
+ <View style={styles.searchHeader}>
<Text
- style={{
- fontFamily: WEIGHT.regular,
- color: colors.icon,
- fontSize: SIZE.xxs - 1,
- }}>
- {messageBoardState.message}
+ style={{
+ fontFamily: WEIGHT.bold,
+ color: colors.accent,
+ fontSize: SIZE.xs,
+ }}>
+ Showing Results for {searchResults.keyword}
</Text>
<Text
- style={{
- color: COLORS_NOTE[currentScreen]
- ? COLORS_NOTE[currentScreen]
- : colors.accent,
- fontSize: SIZE.xxs,
- }}>
- {messageBoardState.actionText}
+ onPress={() => {
+ eSendEvent(eClearSearch);
+ }}
+ style={{
+ fontFamily: WEIGHT.regular,
+ color: colors.errorText,
+ fontSize: SIZE.xs,
+ }}>
+ Clear
</Text>
- </View>
- </PressableButton>
- )}
- </View>
- );
+ </View>
+ );
+};
+
+const MessageCard = ({data}) => {
+ const [state] = useTracked();
+ const {colors, selectionMode, currentScreen, messageBoardState} = state;
+
+ return (
+ <View>
+ {!messageBoardState.visible || !data[0] || selectionMode ? null : (
+ <PressableButton
+ onPress={messageBoardState.onPress}
+ color={
+ COLORS_NOTE[currentScreen]
+ ? COLORS_NOTE[currentScreen]
+ : colors.shade
+ }
+ selectedColor={
+ COLORS_NOTE[currentScreen]
+ ? COLORS_NOTE[currentScreen]
+ : colors.accent
+ }
+ alpha={!colors.night ? -0.02 : 0.1}
+ opacity={0.12}
+ customStyle={styles.loginCard}>
+ <View
+ style={{
+ width: 25,
+ backgroundColor: COLORS_NOTE[currentScreen]
+ ? COLORS_NOTE[currentScreen]
+ : colors.accent,
+ height: 25,
+ borderRadius: 100,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}>
+ <Icon
+ style={styles.loginIcon}
+ name={messageBoardState.icon}
+ color="white"
+ size={SIZE.xs}
+ />
+ </View>
+ <View
+ style={{
+ marginLeft: 10,
+ }}>
+ <Text
+ style={{
+ fontFamily: WEIGHT.regular,
+ color: colors.icon,
+ fontSize: SIZE.xxs - 1,
+ }}>
+ {messageBoardState.message}
+ </Text>
+ <Text
+ style={{
+ color: COLORS_NOTE[currentScreen]
+ ? COLORS_NOTE[currentScreen]
+ : colors.accent,
+ fontSize: SIZE.xxs,
+ }}>
+ {messageBoardState.actionText}
+ </Text>
+ </View>
+ </PressableButton>
+ )}
+ </View>
+ );
};
const ListHeaderComponent = ({type, data}) => {
- const [state] = useTracked();
- const searchResults = {...state.searchResults};
+ const [state] = useTracked();
+ const searchResults = {...state.searchResults};
- return searchResults.type === type && searchResults.results.length > 0 ? (
- <SearchHeader />
- ) : (
- <MessageCard type={type} data={data} />
- );
+ return searchResults.type === type && searchResults.results.length > 0 ? (
+ <SearchHeader/>
+ ) : (
+ <MessageCard type={type} data={data}/>
+ );
};
const styles = StyleSheet.create({
- loginCard: {
- width: '100%',
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'flex-start',
- paddingHorizontal: 12,
- alignSelf: 'center',
- height: 40,
- borderRadius: 0,
- position: 'relative',
- },
- loginIcon: {
- textAlign: 'center',
- textAlignVertical: 'center',
- },
- searchHeader: {
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'space-between',
- paddingHorizontal: 12,
- height: 40,
- },
- sectionHeader: {
- fontFamily: WEIGHT.bold,
- fontSize: SIZE.xs + 1,
- paddingHorizontal: 12,
- width: '100%',
- alignSelf: 'center',
- marginTop: 10,
- height: 25,
- textAlignVertical: 'center',
- },
- emptyList: {
- height: '100%',
- width: '100%',
- alignItems: 'center',
- alignSelf: 'center',
- justifyContent: 'center',
- opacity: 1,
- },
+ loginCard: {
+ width: '100%',
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'flex-start',
+ paddingHorizontal: 12,
+ alignSelf: 'center',
+ height: 40,
+ borderRadius: 0,
+ position: 'relative',
+ },
+ loginIcon: {
+ textAlign: 'center',
+ textAlignVertical: 'center',
+ },
+ searchHeader: {
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ paddingHorizontal: 12,
+ height: 40,
+ },
+ sectionHeader: {
+ fontFamily: WEIGHT.bold,
+ fontSize: SIZE.xs + 1,
+ alignSelf: 'center',
+ textAlignVertical: 'center',
+ },
+ emptyList: {
+ height: '100%',
+ width: '100%',
+ alignItems: 'center',
+ alignSelf: 'center',
+ justifyContent: 'center',
+ opacity: 1,
+ },
});
diff --git a/apps/mobile/src/components/SortDialog/index.js b/apps/mobile/src/components/SortDialog/index.js
new file mode 100644
index 000000000..189b4ef38
--- /dev/null
+++ b/apps/mobile/src/components/SortDialog/index.js
@@ -0,0 +1,175 @@
+import React, {createRef} from 'react';
+import {Text, TouchableOpacity, View} from 'react-native';
+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
+import {dWidth, setSetting, SORT, sortSettings} from '../../utils';
+import ActionSheet from '../ActionSheet';
+import {DDS} from "../../services/DeviceDetection";
+import {eCloseSortDialog, eOpenSortDialog} from "../../utils/Events";
+import {PressableButton} from "../PressableButton";
+import {SIZE, WEIGHT} from "../../utils/SizeUtils";
+import {defaultState} from "../../provider/DefaultState";
+import {MMKV} from "../../utils/MMKV";
+import {updateEvent} from "../DialogManager/Recievers";
+import {Actions} from "../../provider/Actions";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import Seperator from "../Seperator";
+
+
+
+const actionSheet = createRef();
+
+class Index extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ settings: defaultState.settings
+ }
+ }
+
+ async open() {
+ actionSheet.current?._setModalVisible(true);
+ await this.getSettings();
+ }
+
+ async getSettings() {
+ let settings = await MMKV.getItem("settings");
+ this.setState({
+ settings: JSON.parse(settings)
+ })
+ }
+
+ close() {
+ actionSheet.current?._setModalVisible(false);
+ }
+
+ async componentDidMount() {
+ eSubscribeEvent(eOpenSortDialog, this.open.bind(this));
+ eSubscribeEvent(eCloseSortDialog, this.close.bind(this));
+ }
+
+ componentWillUnmount() {
+ eUnSubscribeEvent(eOpenSortDialog, this.open);
+ eUnSubscribeEvent(eCloseSortDialog, this.close);
+ }
+
+ render() {
+ const {colors} = this.props;
+ return (
+ <ActionSheet
+ containerStyle={{
+ backgroundColor: colors.bg,
+ alignSelf: 'center',
+ width: DDS.isTab ? 500 : '100%',
+ borderRadius: 10,
+ marginBottom: DDS.isTab ? 50 : 0,
+ }}
+ extraScroll={DDS.isTab ? 50 : 0}
+ gestureEnabled={true}
+ footerAlwaysVisible={DDS.isTab}
+ footerHeight={DDS.isTab ? 20 : 10}
+ footerStyle={
+ DDS.isTab
+ ? {
+ borderRadius: 10,
+ backgroundColor: colors.bg,
+ }
+ : null
+ }
+ ref={actionSheet}
+ initialOffsetFromBottom={1}>
+ <View
+ style={{
+ width: DDS.isTab ? 500 : dWidth,
+ backgroundColor: colors.bg,
+ justifyContent: 'space-between',
+ paddingHorizontal: 12,
+ borderRadius: 10,
+ paddingTop: 10,
+ }}>
+ <View>
+ <View
+ style={{
+ flexDirection: "row",
+ alignItems: 'center',
+ justifyContent: 'space-between',
+
+ }}
+ >
+ <Text
+ style={{
+ fontSize: SIZE.xl,
+ fontFamily: WEIGHT.bold,
+ color: colors.heading,
+ alignSelf: 'center',
+ }}>
+ Sort by
+ </Text>
+
+ <TouchableOpacity
+ onPress={async () => {
+ let value = this.state.settings.sortOrder === "asc" ? "des" : "asc";
+ await setSetting(this.state.settings, 'sortOrder', value);
+ sortSettings.sortOrder = value;
+ await this.getSettings();
+ }}
+ activeOpacity={1}
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ }}>
+ <Text
+ style={{
+ fontSize: SIZE.sm,
+ fontFamily: WEIGHT.regular,
+ color: colors.icon,
+ marginRight: 5
+ }}>
+ {this.state.settings.sortOrder === "asc" ? "Ascending" : "Descending"}
+ </Text>
+ <Icon color={colors.icon}
+ name={this.state.settings.sortOrder === "asc" ? "sort-ascending" : "sort-descending"}
+ size={SIZE.md}/>
+ </TouchableOpacity>
+
+
+ </View>
+ <Seperator/>
+ {
+ Object.keys(SORT).map((item, index) => <PressableButton
+
+ color={this.state.settings.sort === item ? colors.shade : "transparent"}
+ onPress={async () => {
+ await setSetting(this.state.settings, 'sort', item);
+ await this.getSettings();
+ sortSettings.sort = item;
+ updateEvent({type: Actions.NOTES})
+ }}
+ selectedColor={this.state.settings.sort === item ? colors.accent : colors.nav}
+ alpha={!colors.night ? -0.02 : 0.02}
+ opacity={this.state.settings.sort === item ? 0.12 : 1}
+ customStyle={{
+ width: "100%",
+ height: 50
+ }}
+
+ >
+ <Text
+ style={{
+ fontFamily: WEIGHT.regular,
+ fontSize: SIZE.sm,
+ color: this.state.settings.sort === item ? colors.accent : colors.pri
+ }}
+ >
+ {item.slice(0, 1).toUpperCase() + item.slice(1, item.length)}
+ </Text>
+ </PressableButton>)
+ }
+ </View>
+
+ </View>
+ </ActionSheet>
+ );
+ }
+}
+
+export default Index;
diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.js
index 82dad3ce7..a814da7ed 100644
--- a/apps/mobile/src/provider/DefaultState.js
+++ b/apps/mobile/src/provider/DefaultState.js
@@ -25,7 +25,9 @@ export const defaultState = {
useSystemTheme:true,
reminder:'weekly',
encryptedBackups:false,
- homepage:'Home'
+ homepage:'Home',
+ sort:"default",
+ sortOrder:"des"
},
currentScreen: 'home',
colors: {
diff --git a/apps/mobile/src/provider/Reducer.js b/apps/mobile/src/provider/Reducer.js
index 2477340ec..14a084c45 100644
--- a/apps/mobile/src/provider/Reducer.js
+++ b/apps/mobile/src/provider/Reducer.js
@@ -1,7 +1,7 @@
import { eSendEvent } from '../services/EventManager';
import { eCloseSideMenu, eOpenSideMenu } from '../utils/Events';
import storage from '../utils/storage';
-import { history} from '../utils/index';
+import {history, SORT, sortSettings} from '../utils/index';
import { Actions } from './Actions';
import {db} from "../utils/DB";
@@ -9,9 +9,10 @@ export const reducer = (state, action) => {
switch (action.type) {
case Actions.ALL: {
+
return {
...state,
- notes: db.notes.group(),
+ notes: db.notes.group(SORT[sortSettings.sort]),
notebooks: db.notebooks.all,
trash: db.trash.all,
tags: db.tags.all,
@@ -43,16 +44,10 @@ export const reducer = (state, action) => {
};
}
case Actions.NOTES:
- let notes;
- if (action.sort) {
- notes = db.notes.group(action.sort);
- } else {
- notes = db.notes.group();
- }
return {
...state,
- notes: notes,
+ notes: db.notes.group(SORT[sortSettings.sort]),
loading: false,
};
case Actions.THEME: {
diff --git a/apps/mobile/src/utils/Events.js b/apps/mobile/src/utils/Events.js
index 3c4993c60..c36ff7fca 100644
--- a/apps/mobile/src/utils/Events.js
+++ b/apps/mobile/src/utils/Events.js
@@ -113,4 +113,7 @@ export const eOnNoteEdited = '555';
export const eUpdateSearchState = '556';
export const eOpenResultDialog = '557';
-export const eCloseResultDialog = '558';
\ No newline at end of file
+export const eCloseResultDialog = '558';
+
+export const eOpenSortDialog = '559';
+export const eCloseSortDialog = '560';
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index fe9bdd65c..290a5cbcb 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -4,6 +4,7 @@ import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
import {MMKV} from "./MMKV";
import RNFetchBlob from 'rn-fetch-blob';
+import {defaultState} from "../provider/DefaultState";
export async function setSetting(settings, name, value) {
let s = {...settings};
@@ -26,6 +27,19 @@ export const getElevation = (elevation) => {
};
};
+export const sortSettings = {
+ sort:defaultState.settings.sort,
+ sortOrder: defaultState.settings.sortOrder
+}
+
+export const SORT = {
+ default: null,
+ alphabetical: 'abc',
+ year: 'year',
+ week: 'week',
+ month: 'month'
+}
+
export const editing = {
currentlyEditing: false,
isFullscreen: false,
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index d432795ee..b07d0f0c0 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -155,7 +155,6 @@ export const _onMessage = async (evt) => {
let message = evt.nativeEvent.data;
clearTimeout(timer);
timer = null;
- console.log('new message from editor')
if (message === 'loaded') {
} else if (message !== '' && message !== 'loaded') {
onChange(message);
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 878e5e5e1..6feccf755 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -13,17 +13,13 @@ import {
} from '../../utils/Events';
import {openEditorAnimation} from '../../utils/Animations';
import {DDS} from '../../services/DeviceDetection';
+import {sortSettings} from "../../utils";
export const Home = ({navigation}) => {
const [state, dispatch] = useTracked();
const {notes} = state;
const onFocus = useCallback(() => {
- dispatch({
- type: Actions.HEADER_VERTICAL_MENU,
- state: notes.length > 0,
- });
-
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
@@ -46,6 +42,7 @@ export const Home = ({navigation}) => {
color: null,
});
eSendEvent(eScrollEvent, 0);
+ console.log(sortSettings);
dispatch({type: Actions.COLORS});
dispatch({type: Actions.NOTES});
}, [notes]);