A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
refactor sort dialog
ammarahm-ed79ed2a5db737
diff --git a/apps/mobile/src/components/GeneralSheet/index.js b/apps/mobile/src/components/GeneralSheet/index.jsindex b55749f08..dc4aa43e1 100644--- a/apps/mobile/src/components/GeneralSheet/index.js+++ b/apps/mobile/src/components/GeneralSheet/index.js@@ -11,7 +11,6 @@ import {Button} from '../Button';import Heading from '../Typography/Heading';import Paragraph from '../Typography/Paragraph';-const GeneralSheet = ({context}) => {const [state] = useTracked();const {colors} = state;@@ -62,7 +61,13 @@ const GeneralSheet = ({context}) => {style={{justifyContent: 'center',alignItems: 'center',- marginBottom: 10,+ marginBottom:+ dialogData.noProgress &&+ dialogData.noIcon &&+ !dialogData.title &&+ !dialogData.paragraph+ ? 0+ : 10,paddingHorizontal: 12}}>{!dialogData?.noProgress && !dialogData.component ? (@@ -84,7 +89,9 @@ const GeneralSheet = ({context}) => {) : null}</View>- {typeof dialogData.component === "function" ? dialogData.component(actionSheetRef):dialogData.component}+ {typeof dialogData.component === 'function'+ ? dialogData.component(actionSheetRef)+ : dialogData.component}{dialogData?.learnMore ? (<Paragraph@@ -100,7 +107,7 @@ const GeneralSheet = ({context}) => {<Viewstyle={{paddingHorizontal: 12,- marginBottom:dialogData.valueArray ? 12 : 0+ marginBottom: dialogData.valueArray ? 12 : 0}}>{dialogData.valueArray &&dialogData.valueArray.map(v => (@@ -140,7 +147,7 @@ const GeneralSheet = ({context}) => {) : null}{dialogData?.actionsArray &&- dialogData?.actionsArray.map((item,index) => (+ dialogData?.actionsArray.map((item, index) => (<ButtononPress={item.action}key={item.accentText}diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.jsindex 2aafa5788..0b41082db 100644--- a/apps/mobile/src/components/SimpleList/index.js+++ b/apps/mobile/src/components/SimpleList/index.js@@ -93,6 +93,7 @@ const SimpleList = ({color={headerProps.color}title={headerProps.heading}type={screen === 'Notes' ? 'home' : type}+ screen={screen}/>),[]@@ -179,12 +180,6 @@ const SimpleList = ({</>}/>-- <SortDialog- screen={screen}- type={screen === 'Notes' ? 'home' : type}- colors={colors}- /><JumpToDialogscreen={screen}data={listData}diff --git a/apps/mobile/src/components/SimpleList/sectionheader.js b/apps/mobile/src/components/SimpleList/sectionheader.jsindex bdca40bbc..b6809e955 100644--- a/apps/mobile/src/components/SimpleList/sectionheader.js+++ b/apps/mobile/src/components/SimpleList/sectionheader.js@@ -5,19 +5,21 @@ import {useSettingStore} from '../../provider/stores';import {eSendEvent,eSubscribeEvent,- eUnSubscribeEvent+ eUnSubscribeEvent,+ presentSheet} from '../../services/EventManager';import SettingsService from '../../services/SettingsService';-import {GROUP, SORT} from '../../utils';+import {GROUP} from '../../utils';import {COLORS_NOTE} from '../../utils/Colors';import {db} from '../../utils/database';-import {eOpenJumpToDialog, eOpenSortDialog} from '../../utils/Events';+import {eOpenJumpToDialog} from '../../utils/Events';import {SIZE} from '../../utils/SizeUtils';import {ActionIcon} from '../ActionIcon';import {Button} from '../Button';+import Sort from '../SortDialog';import Heading from '../Typography/Heading';-export const SectionHeader = ({item, index, type, title,color}) => {+export const SectionHeader = ({item, index, type, color, screen}) => {const [state] = useTracked();const {colors} = state;const {fontScale} = useWindowDimensions();@@ -73,7 +75,7 @@ export const SectionHeader = ({item, index, type, title,color}) => {justifyContent: 'center'}}><Heading- color={COLORS_NOTE[color?.toLowerCase()] || colors.accent }+ color={COLORS_NOTE[color?.toLowerCase()] || colors.accent}size={SIZE.sm}style={{minWidth: 60,@@ -93,7 +95,11 @@ export const SectionHeader = ({item, index, type, title,color}) => {<><ButtononPress={() => {- eSendEvent(eOpenSortDialog, type);+ presentSheet({+ noProgress: true,+ noIcon: true,+ component: <Sort screen={screen} type={type} />+ });}}title={groupBy}icon={diff --git a/apps/mobile/src/components/SortDialog/index.js b/apps/mobile/src/components/SortDialog/index.jsindex 44eef5163..dfb81a986 100644--- a/apps/mobile/src/components/SortDialog/index.js+++ b/apps/mobile/src/components/SortDialog/index.js@@ -1,256 +1,200 @@-import React, {createRef} from 'react';+import React, {useState} from 'react';import {View} from 'react-native';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import {- eSendEvent,- eSubscribeEvent,- eUnSubscribeEvent-} from '../../services/EventManager';+import {useTracked} from '../../provider';+import {eSendEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';import {GROUP, SORT} from '../../utils';import {db} from '../../utils/database';-import {eCloseSortDialog, eOpenSortDialog} from '../../utils/Events';import {SIZE} from '../../utils/SizeUtils';-import {sleep} from '../../utils/TimeUtils';-import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';import {Button} from '../Button';-import {PressableButton} from '../PressableButton';import Seperator from '../Seperator';import Heading from '../Typography/Heading';-import Paragraph from '../Typography/Paragraph';-class SortDialog extends React.Component {- constructor(props) {- super(props);- this.state = {- groupOptions: null,- visible: false- };- this.actionSheet = createRef();- }-- async open(type) {- if (type !== this.props.type) return;- this.setState(- {- visible: true,- groupOptions: db.settings.getGroupOptions(this.props.type)- },- async () => {- console.log(this.state.groupOptions);- this.actionSheet.current?.setModalVisible(true);- }- );- }-- async close() {- this.actionSheet.current?.setModalVisible(false);- await sleep(100);- this.setState({- visible: false- });- }+const Sort = ({type, screen}) => {+ const [state] = useTracked();+ const colors = state.colors;+ const [groupOptions, setGroupOptions] = useState(+ db.settings.getGroupOptions(type)+ );- async componentDidMount() {- eSubscribeEvent(eOpenSortDialog, this.open.bind(this));- eSubscribeEvent(eCloseSortDialog, this.close.bind(this));- }-- componentWillUnmount() {- eUnSubscribeEvent(eOpenSortDialog, this.open);- eUnSubscribeEvent(eCloseSortDialog, this.close);- }-- updateGroupOptions = async _groupOptions => {- await db.settings.setGroupOptions(this.props.type, _groupOptions);- this.setState({- groupOptions: _groupOptions- });+ const updateGroupOptions = async _groupOptions => {+ await db.settings.setGroupOptions(type, _groupOptions);+ setGroupOptions(_groupOptions);setTimeout(() => {- Navigation.setRoutesToUpdate([this.props.screen]);+ Navigation.setRoutesToUpdate([screen]);eSendEvent('groupOptionsUpdate');}, 1);};- render() {- const {colors} = this.props;- const {groupOptions, visible} = this.state;-- if (!visible) return null;+ const setOrderBy = async () => {+ let _groupOptions = {+ ...groupOptions,+ sortDirection: groupOptions.sortDirection === 'asc' ? 'desc' : 'asc'+ };+ await updateGroupOptions(_groupOptions);+ };- return (- <ActionSheetWrapper fwdRef={this.actionSheet}>- <View+ return (+ <View+ style={{+ width: '100%',+ backgroundColor: colors.bg,+ justifyContent: 'space-between',+ borderRadius: 10,+ paddingTop: 10+ }}>+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ justifyContent: 'space-between',+ paddingHorizontal: 12+ }}>+ <Heading+ size={SIZE.xl}style={{- width: '100%',- backgroundColor: colors.bg,- justifyContent: 'space-between',- borderRadius: 10,- paddingTop: 10+ alignSelf: 'center'}}>- <View- style={{- flexDirection: 'row',- alignItems: 'center',- justifyContent: 'space-between',- paddingHorizontal: 12- }}>- <Heading- size={SIZE.xl}- style={{- alignSelf: 'center'- }}>- Sort & Group- </Heading>+ Sort by+ </Heading>++ <Button+ title={+ groupOptions.sortDirection === 'asc'+ ? groupOptions.groupBy === 'abc'+ ? 'A - Z'+ : 'Old - New'+ : groupOptions.groupBy === 'abc'+ ? 'Z - A'+ : 'New - Old'+ }+ icon={+ groupOptions.sortDirection === 'asc'+ ? 'sort-ascending'+ : 'sort-descending'+ }+ height={25}+ iconPosition="right"+ fontSize={SIZE.sm - 1}+ type="transparent"+ style={{+ borderRadius: 100+ }}+ onPress={setOrderBy}+ />+ </View>++ <Seperator />+ <View+ style={{+ flexDirection: 'row',+ justifyContent: 'flex-start',+ flexWrap: 'wrap',+ borderBottomWidth: 1,+ borderBottomColor: colors.nav,+ marginBottom: 12,+ paddingHorizontal: 12,+ paddingBottom: 12,+ alignItems: 'center'+ }}>+ {groupOptions.groupBy === 'abc' ? (+ <Button+ type={'grayBg'}+ title="Title"+ height={45}+ iconPosition="left"+ icon={'check'}+ buttonType={{text: colors.accent}}+ fontSize={SIZE.sm}+ iconSize={SIZE.md}+ />+ ) : (+ Object.keys(SORT).map((item, index) => (<Button- title={- groupOptions.sortDirection === 'asc'- ? groupOptions.groupBy === 'abc'- ? 'A - Z'- : 'Oldest - Newest'- : groupOptions.groupBy === 'abc'- ? 'Z - A'- : 'Newest - Oldest'- }- icon={- groupOptions.sortDirection === 'asc'- ? 'sort-ascending'- : 'sort-descending'- }- height={25}+ key={item}+ type={groupOptions.sortBy === item ? 'grayBg' : 'gray'}+ title={SORT[item]}+ height={45}iconPosition="left"- fontSize={SIZE.sm - 1}- type="grayBg"+ icon={groupOptions.sortBy === item ? 'check' : null}style={{- borderRadius: 100+ marginRight: 10+ }}+ buttonType={{+ text: groupOptions.sortBy === item ? colors.accent : colors.icon}}+ fontSize={SIZE.sm}onPress={async () => {let _groupOptions = {...groupOptions,- sortDirection:- groupOptions.sortDirection === 'asc' ? 'desc' : 'asc'+ sortBy: type === 'trash' ? 'dateDeleted' : item};- await this.updateGroupOptions(_groupOptions);+ await updateGroupOptions(_groupOptions);}}+ iconSize={SIZE.md}/>- </View>+ ))+ )}+ </View>- <Seperator />- <View- style={{- flexDirection: 'row',- justifyContent: 'space-around',- borderBottomWidth: 1,- borderBottomColor: colors.nav,- marginBottom: 12,- paddingHorizontal: 12- }}>- {this.state.groupOptions.groupBy === 'abc' ? (- <Paragraph- style={{- height: 40- }}- color={colors.icon}>- No sort options available.- </Paragraph>- ) : (- Object.keys(SORT).map((item, index) => (- <Button- key={item}- type={groupOptions.sortBy === item ? 'transparent' : 'gray'}- title={SORT[item]}- height={40}- iconPosition="left"- icon={- groupOptions.sortBy === item- ? 'check-circle-outline'- : 'checkbox-blank-circle-outline'- }- textStyle={{- color: colors.pri- }}- fontSize={SIZE.sm}- style={{- backgroundColor: 'transparent'- }}- onPress={async () => {- let _groupOptions = {- ...groupOptions,- sortBy: this.props.type === 'trash' ? 'dateDeleted' : item- };- await this.updateGroupOptions(_groupOptions);- }}- iconSize={SIZE.lg}- />- ))- )}- </View>- <View- style={{- paddingHorizontal: 0,- borderRadius: 0- }}>- {Object.keys(GROUP).map((item, index) => (- <PressableButton- key={item}- testID={'btn-' + item}- type={- groupOptions.groupBy === GROUP[item] ? 'transparent' : 'gray'- }- onPress={async () => {- let _groupOptions = {- ...groupOptions,- groupBy: GROUP[item]- };+ <Heading+ style={{+ marginLeft: 12+ }}+ size={SIZE.lg}>+ Group by+ </Heading>- if (item === 'alphabetical') {- _groupOptions.sortBy = 'title';- _groupOptions.sortDirection = 'asc';- } else {- if (this.state.groupOptions.sortBy === 'title') {- _groupOptions.sortBy = 'dateEdited';- }- }+ <Seperator />- this.updateGroupOptions(_groupOptions);- }}- customStyle={{- width: '100%',- height: 50,- justifyContent: 'space-between',- flexDirection: 'row',- alignItems: 'center',- borderRadius: 5,- paddingHorizontal: 12,- marginBottom: 10- }}>- <Paragraph- size={SIZE.sm}- style={{- fontFamily:- groupOptions.groupBy === GROUP[item]- ? 'OpenSans-SemiBold'- : 'OpenSans-Regular'- }}- color={- groupOptions.groupBy === GROUP[item]- ? colors.accent- : colors.pri- }>- {item.slice(0, 1).toUpperCase() + item.slice(1, item.length)}- </Paragraph>+ <View+ style={{+ paddingHorizontal: 0,+ borderRadius: 0,+ flexDirection: 'row',+ flexWrap: 'wrap',+ paddingHorizontal: 12+ }}>+ {Object.keys(GROUP).map((item, index) => (+ <Button+ key={item}+ testID={'btn-' + item}+ type={groupOptions.groupBy === GROUP[item] ? 'grayBg' : 'gray'}+ buttonType={{+ text:+ groupOptions.groupBy === GROUP[item]+ ? colors.accent+ : colors.icon+ }}+ onPress={async () => {+ let _groupOptions = {+ ...groupOptions,+ groupBy: GROUP[item]+ };- {groupOptions.groupBy === GROUP[item] ? (- <Icon color={colors.accent} name="check" size={SIZE.lg} />- ) : null}- </PressableButton>- ))}- </View>- </View>- </ActionSheetWrapper>- );- }-}+ if (item === 'abc') {+ _groupOptions.sortBy = 'title';+ _groupOptions.sortDirection = 'asc';+ } else {+ if (groupOptions.sortBy === 'title') {+ _groupOptions.sortBy = 'dateEdited';+ }+ }+ updateGroupOptions(_groupOptions);+ }}+ icon={groupOptions.groupBy === GROUP[item] ? 'check' : null}+ title={item.slice(0, 1).toUpperCase() + item.slice(1, item.length)}+ style={{+ paddingHorizontal: 12,+ marginBottom: 10,+ marginRight: 10+ }}+ />+ ))}+ </View>+ </View>+ );+};-export default SortDialog;+export default Sort;diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.jsindex 81e907fde..68cf6d4e5 100755--- a/apps/mobile/src/utils/index.js+++ b/apps/mobile/src/utils/index.js@@ -80,7 +80,7 @@ export const sortSettings = {export const GROUP = {default: 'default',- alphabetical: 'abc',+ abc: 'abc',year: 'year',week: 'week',month: 'month'