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 selection wrapper
ammarahm-ed1ee084524da3
diff --git a/apps/mobile/src/components/SelectionWrapper/actionstrip.js b/apps/mobile/src/components/SelectionWrapper/actionstrip.jsindex ac4b2666e..c8bd7564c 100644--- a/apps/mobile/src/components/SelectionWrapper/actionstrip.js+++ b/apps/mobile/src/components/SelectionWrapper/actionstrip.js@@ -47,13 +47,19 @@ export const ActionStrip = ({note, setActionStrip}) => {if (note.type === 'note') {if (db.notes.pinned.length === 3 && !note.pinned) {- ToastEvent.show('You cannot pin more than 3 notes', 'error');+ ToastEvent.show({+ heading: 'Cannot pin more than 3 notes',+ type: 'error',+ });return;}await db.notes.note(note.id).pin();} else {if (db.notebooks.pinned.length === 3 && !note.pinned) {- ToastEvent.show('You cannot pin more than 3 notebooks', 'error');+ ToastEvent.show({+ heading: 'Cannot pin more than 3 notebooks',+ type: 'error',+ });return;}await db.notebooks.notebook(note.id).pin();@@ -89,7 +95,10 @@ export const ActionStrip = ({note, setActionStrip}) => {try {if (isPinnedToMenu) {await db.settings.unpin(note.id);- ToastEvent.show('Shortcut removed from menu', 'success');+ ToastEvent.show({+ heading: 'Shortcut removed from menu',+ type: 'success',+ });} else {if (note.type === 'topic') {await db.settings.pin(note.type, {@@ -99,8 +108,10 @@ export const ActionStrip = ({note, setActionStrip}) => {} else {await db.settings.pin(note.type, {id: note.id});}-- ToastEvent.show('Shortcut added to menu', 'success');+ ToastEvent.show({+ heading: 'Shortcut added to menu',+ type: 'success',+ });}setIsPinnedToMenu(db.settings.isPinned(note.id));dispatch({type: Actions.MENU_PINS});@@ -121,15 +132,18 @@ export const ActionStrip = ({note, setActionStrip}) => {novault: true,locked: true,item: note,- title:'Copy note',- description:"Unlock note to copy to clipboard."+ title: 'Copy note',+ description: 'Unlock note to copy to clipboard.',});} else {let delta = await db.notes.note(note.id).content();let text = toTXT(delta);text = `${note.title}\n \n ${text}`;Clipboard.setString(text);- ToastEvent.show('Note copied to clipboard', 'success');+ ToastEvent.show({+ heading: 'Note copied to clipboard',+ type: 'success',+ });}setActionStrip(false);},@@ -147,10 +161,14 @@ export const ActionStrip = ({note, setActionStrip}) => {Navigation.routeNames.Trash,]);- ToastEvent.show(- item.type === 'note' ? 'Note restored' : 'Notebook restored',- 'success',- );+ ToastEvent.show({+ heading:+ item.type === 'note'+ ? 'Note restored from trash'+ : 'Notebook restored from trash',+ type: 'success',+ });+setActionStrip(false);},visible: note.type === 'trash',diff --git a/apps/mobile/src/components/SelectionWrapper/index.js b/apps/mobile/src/components/SelectionWrapper/index.jsindex c096094c6..d90dbfbaf 100644--- a/apps/mobile/src/components/SelectionWrapper/index.js+++ b/apps/mobile/src/components/SelectionWrapper/index.js@@ -3,10 +3,12 @@ import {TouchableOpacity, View} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {useTracked} from '../../provider';import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';+import { history } from '../../utils';import {SIZE} from '../../utils/SizeUtils';import {PressableButton} from '../PressableButton';import {ActionStrip} from './action-strip';import {Filler} from './back-fill';+import { SelectionIcon } from './selection';const SelectionWrapper = ({children,@@ -18,33 +20,13 @@ const SelectionWrapper = ({testID,}) => {const [state, dispatch] = useTracked();- const {colors, selectionMode, selectedItemsList} = state;- const [selected, setSelected] = useState(false);+ const {colors} = state;const [actionStrip, setActionStrip] = useState(false);- useEffect(() => {- if (selectionMode) {- setActionStrip(false);- let exists = selectedItemsList.filter(- (o) => o.dateCreated === item.dateCreated,- );-- if (exists[0]) {- if (!selected) {- setSelected(true);- }- } else {- if (selected) {- setSelected(false);- }- }- }- }, [selectedItemsList,item.id]);-- const onLong = () => {- if (selectionMode) return;- if (item.type === 'topic' && item.title === 'General') return;+ const _onLongPress = () => {+ if (history.selectedItemsList.length > 0 ) return;+ if (item.type === 'topic' && item.title === 'General') return;setActionStrip(!actionStrip);};@@ -74,7 +56,7 @@ const SelectionWrapper = ({<PressableButtoncustomColor="transparent"testID={testID}- onLongPress={onLong}+ onLongPress={_onLongPress}onPress={_onPress}customSelectedColor={colors.nav}customAlpha={!colors.night ? -0.02 : 0.02}@@ -87,54 +69,14 @@ const SelectionWrapper = ({borderRadius: 0,overflow: 'hidden',paddingHorizontal: 12,- marginTop:- index === 0 && !selectionMode- ? 15- : index === 0 && selectionMode- ? 30- : 0,+ marginTop:0,}}>{actionStrip && (<ActionStrip note={item} setActionStrip={setActionStrip} />)}{item.type === 'note' && <Filler background={background} item={item} />}-- {selectionMode && (- <View- style={{- display: 'flex',- opacity: 1,- width: '10%',- height: 70,- justifyContent: 'center',- alignItems: 'center',- paddingRight: 8,- }}>- {item.type !== 'topic' ||- (item.type === 'topic' && item.title !== 'General') ? (- <TouchableOpacity- activeOpacity={1}- onPress={onLongPress}- style={{- justifyContent: 'center',- alignItems: 'center',- height: 70,- }}>- <Icon- size={SIZE.lg}- color={selected ? colors.accent : colors.icon}- name={- selected- ? 'check-circle-outline'- : 'checkbox-blank-circle-outline'- }- />- </TouchableOpacity>- ) : null}- </View>- )}-+ <SelectionIcon setActionStrip={setActionStrip} item={item} onLongPress={onLongPress} />{children}</PressableButton>);diff --git a/apps/mobile/src/components/SelectionWrapper/selection.js b/apps/mobile/src/components/SelectionWrapper/selection.jsnew file mode 100644index 000000000..145ff1b3f--- /dev/null+++ b/apps/mobile/src/components/SelectionWrapper/selection.js@@ -0,0 +1,78 @@+import React, {useEffect, useState} from 'react';+import {TouchableOpacity, View} from 'react-native';+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';+import {useTracked} from '../../provider';+import {Actions} from '../../provider/Actions';+import {SIZE} from '../../utils/SizeUtils';++export const SelectionIcon = ({setActionStrip, item}) => {+ const [state, dispatch] = useTracked();+ const {colors, selectionMode, selectedItemsList} = state;+ const [selected, setSelected] = useState(false);+++ useEffect(() => {+ if (selectionMode) {++ setActionStrip(false);+ let exists = selectedItemsList.filter(+ (o) => o.dateCreated === item.dateCreated,+ );++ if (exists[0]) {+ if (!selected) {+ setSelected(true);+ }+ } else {+ if (selected) {+ setSelected(false);+ }+ }+ }+ }, [selectedItemsList, item.id]);++ onPress = () => {+ if (item.title === 'General' && item.type === 'topic') return;+ dispatch({+ type: Actions.SELECTED_ITEMS,+ item: item,+ });+ };++ return (+ selectionMode && (+ <View+ style={{+ display: 'flex',+ opacity: 1,+ width: "10%",+ height: 70,+ justifyContent: 'center',+ alignItems: 'center',+ paddingRight: 8,+ }}>+ {item.type !== 'topic' ||+ (item.type === 'topic' && item.title !== 'General') ? (+ <TouchableOpacity+ activeOpacity={1}+ onPress={onPress}+ style={{+ justifyContent: 'center',+ alignItems: 'center',+ height: 70,+ }}>+ <Icon+ size={SIZE.lg}+ color={selected ? colors.accent : colors.icon}+ name={+ selected+ ? 'check-circle-outline'+ : 'checkbox-blank-circle-outline'+ }+ />+ </TouchableOpacity>+ ) : null}+ </View>+ )+ );+};