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
feat: implement actionSheet
ammarahm-ed80d1e4b6bb57
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex 73ee16b21..a4225eb05 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -5,8 +5,19 @@ import {TouchableOpacity,Dimensions,ScrollView,+ TextInput,+ FlatList,+ Modal,} from 'react-native';-import {COLOR_SCHEME, SIZE, br, ph, pv, WEIGHT} from '../../common/common';+import {+ COLOR_SCHEME,+ SIZE,+ br,+ ph,+ pv,+ WEIGHT,+ opacity,+} from '../../common/common';import Icon from 'react-native-vector-icons/Feather';import {@@ -22,6 +33,7 @@ import {VaultDialog} from '../VaultDialog';import {db} from '../../../App';import {DDS} from '../../../App';import {useAppContext} from '../../provider/useAppContext';+import ActionSheet from '../ActionSheet';const w = Dimensions.get('window').width;const h = Dimensions.get('window').height;@@ -34,8 +46,8 @@ const NoteItem = props => {const item = props.item;let show = null;-let setMenuRef = {};+ let willRefresh = false;const onMenuHide = () => {if (show) {@@ -107,6 +119,7 @@ const NoteItem = props => {openedToUnlock={unlock}visible={vaultDialog}/>+{props.pinned ? (<Viewstyle={{@@ -199,14 +212,14 @@ const NoteItem = props => {justifyContent: 'center',alignItems: 'center',}}>- {['red', 'green'].map(item => (+ {item.colors.map(item => (<Viewstyle={{width: SIZE.xs,height: SIZE.xs,borderRadius: 100,backgroundColor: item,- marginRight: -5.5,+ marginRight: -4.5,}}></View>))}</View>@@ -278,6 +291,20 @@ const NoteItem = props => {alignItems: 'center',paddingRight: ph,}}>+ <TouchableOpacity+ style={{+ width: w * 0.05,+ justifyContent: 'center',+ minHeight: 70,+ alignItems: 'center',+ }}+ onPress={() => {+ ActionSheet._setModalVisible();+ }}>+ <Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />+ </TouchableOpacity>++ {/*<Menustyle={{borderRadius: 5,@@ -438,9 +465,491 @@ const NoteItem = props => {</>)}</Menu>++ */}++ <ActionSheet+ customStyles={{+ backgroundColor: colors.bg,+ }}+ onClose={() => {+ onMenuHide();+ if (willRefresh) {+ props.refresh();+ }+ }}+ children={+ <ActionSheetComponent+ item={item}+ setWillRefresh={value => {+ willRefresh = true;+ }}+ close={value => {+ if (value) {+ show = value;+ }++ ActionSheet._setModalVisible();+ }}+ />+ }+ /></View></View>);};export default NoteItem;++let tagsInputRef;++const ActionSheetComponent = ({+ close = () => {},+ item = {},+ setWillRefresh = value => {},+}) => {+ const {colors} = useAppContext();+ const [focused, setFocused] = useState(false);+ const [note, setNote] = useState(item ? item : {});++ let tagToAdd = null;+ let backPressCount = 0;++ const _onSubmit = () => {+ if (!tagToAdd || tagToAdd === '#') return;++ let tag = tagToAdd;+ if (tag[0] !== '#') {+ tag = '#' + tag;+ }+ if (tag.includes(' ')) {+ tag = tag.replace(' ', '_');+ }+ let oldProps = {...note};+ oldProps.tags.push(tag);+ tagsInputRef.setNativeProps({+ text: '#',+ });+ db.addNote({+ dateCreated: note.dateCreated,+ content: note.content,+ title: note.title,+ tags: oldProps.tags,+ });+ setNote({...db.getNote(note.dateCreated)});+ tagToAdd = '';+ setTimeout(() => {+ //tagsInputRef.focus();+ }, 300);+ };++ const _onKeyPress = event => {+ if (event.nativeEvent.key === 'Backspace') {+ if (backPressCount === 0 && !tagToAdd) {+ backPressCount = 1;++ return;+ }+ if (backPressCount === 1 && !tagToAdd) {+ backPressCount = 0;++ let tagInputValue = note.tags[note.tags.length - 1];+ let oldProps = {...note};+ if (oldProps.tags.length === 1) return;++ oldProps.tags.splice(oldProps.tags.length - 1);++ db.addNote({+ dateCreated: note.dateCreated,+ content: note.content,+ title: note.title,+ tags: oldProps.tags,+ });+ setNote({...db.getNote(note.dateCreated)});+ tagsInputRef.setNativeProps({+ text: tagInputValue,+ });++ setTimeout(() => {+ tagsInputRef.focus();+ }, 300);+ }+ }+ };++ return (+ <View>+ <View+ style={{+ width: w - 24,+ justifyContent: 'space-around',+ alignItems: 'center',+ marginHorizontal: 12,+ paddingVertical: 10,+ flexDirection: 'row',+ borderBottomWidth: 1,+ borderBottomColor: colors.nav,+ }}>+ <TouchableOpacity+ onPress={() => {+ close();+ NavigationService.push('Folders', {+ note: note,+ title: 'Choose a notebook',+ isMove: true,+ hideMore: true,+ canGoBack: true,+ });+ }}+ style={{+ alignItems: 'center',+ }}>+ <Icon+ style={{+ width: 50,+ height: 50,+ borderRadius: 100,+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+ textAlignVertical: 'center',+ marginBottom: 5,+ }}+ name="arrow-right"+ size={SIZE.lg}+ color={colors.accent}+ />++ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ }}>+ Move to+ </Text>+ </TouchableOpacity>+ <TouchableOpacity+ onPress={() => {+ close();+ }}+ style={{+ alignItems: 'center',+ }}>+ <Icon+ style={{+ width: 50,+ height: 50,+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+ textAlignVertical: 'center',+ marginBottom: 5,+ }}+ name="share-2"+ size={SIZE.lg}+ color={colors.accent}+ />+ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ }}>+ Share+ </Text>+ </TouchableOpacity>+ <TouchableOpacity+ onPress={() => {+ close();+ }}+ style={{+ alignItems: 'center',+ }}>+ <Icon+ style={{+ width: 50,+ height: 50,+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+ textAlignVertical: 'center',+ marginBottom: 5,+ }}+ name="external-link"+ size={SIZE.lg}+ color={colors.accent}+ />++ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ }}>+ Export+ </Text>+ </TouchableOpacity>+ <TouchableOpacity+ onPress={() => {+ close('delete');+ }}+ style={{+ alignItems: 'center',+ }}>+ <Icon+ style={{+ width: 50,+ height: 50,+ borderRadius: 100,+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+ textAlignVertical: 'center',++ marginBottom: 5,+ }}+ name="trash"+ size={SIZE.lg}+ color={colors.accent}+ />++ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ }}>+ Delete+ </Text>+ </TouchableOpacity>+ </View>+ <View+ style={{+ flexDirection: 'row',+ flexWrap: 'wrap',+ paddingHorizontal: 12,+ width: '100%',+ marginVertical: 10,+ alignItems: 'center',+ justifyContent: 'space-between',+ }}>+ {['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map(+ color => (+ <TouchableOpacity+ onPress={() => {+ let noteColors = note.colors;++ if (noteColors.includes(color)) {+ noteColors.splice(color, 1);+ } else {+ noteColors.push(color);+ }++ db.addNote({+ dateCreated: note.dateCreated,+ colors: noteColors,+ content: note.content,+ title: note.title,+ });+ setNote({...db.getNote(note.dateCreated)});+ setWillRefresh(true);+ }}+ style={{+ flexDirection: 'row',+ justifyContent: 'flex-start',+ alignItems: 'center',+ borderColor: colors.nav,+ }}>+ <View+ style={{+ width: (w - 12) / 10,+ height: (w - 12) / 10,+ backgroundColor: color,+ borderRadius: 100,+ justifyContent: 'center',+ alignItems: 'center',+ }}>+ {note.colors.includes(color) ? (+ <Icon name="check" color="white" size={SIZE.lg} />+ ) : null}+ </View>+ </TouchableOpacity>+ ),+ )}+ </View>++ <View+ style={{+ flexDirection: 'row',+ flexWrap: 'wrap',+ marginHorizontal: 12,+ marginBottom: 0,+ borderRadius: 5,+ borderWidth: 1.5,+ borderColor: focused ? colors.accent : colors.nav,+ }}>+ {note.tags.map(tag => (+ <TouchableOpacity+ style={{+ flexDirection: 'row',+ justifyContent: 'flex-start',+ alignItems: 'center',+ margin: 1,+ paddingHorizontal: 5,+ paddingVertical: 2.5,+ }}>+ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.sm,+ color: colors.pri,+ }}>+ <Text+ style={{+ color: colors.accent,+ }}>+ {tag.slice(0, 1)}+ </Text>+ {tag.slice(1)}+ </Text>+ </TouchableOpacity>+ ))}+ <TextInput+ style={{+ backgroundColor: 'transparent',+ minWidth: 100,+ fontFamily: WEIGHT.regular,+ color: colors.pri,+ paddingHorizontal: 5,+ paddingVertical: 1.5,+ margin: 1,+ }}+ blurOnSubmit={false}+ ref={ref => (tagsInputRef = ref)}+ placeholderTextColor={colors.icon}+ onFocus={() => {+ setFocused(true);+ }}+ selectionColor={colors.accent}+ onBlur={() => {+ setFocused(false);+ }}+ placeholder="#hashtag"+ onChangeText={value => {+ tagToAdd = value;+ if (tagToAdd.length > 0) backPressCount = 0;+ }}+ onSubmitEditing={_onSubmit}+ onKeyPress={_onKeyPress}+ />+ </View>++ <FlatList+ style={{+ marginTop: 10,+ }}+ data={[+ {+ name: 'Pin',+ icon: 'tag',+ func: () => {+ db.pinItem(note.type, note.dateCreated);+ setNote({...db.getNote(note.dateCreated)});+ setWillRefresh(true);+ },+ close: false,+ check: true,+ on: note.pinned,+ },++ {+ name: 'Favorite',+ icon: 'star',+ func: () => {+ db.favoriteItem(note.type, note.dateCreated);+ setNote({...db.getNote(note.dateCreated)});+ setWillRefresh(true);+ },+ close: false,+ check: true,+ on: note.favorite,+ },+ {+ name: 'Add to Vault',+ icon: 'lock',+ func: () => {+ note.locked ? close('unlock') : close('lock');+ },+ close: true,+ check: true,+ on: note.locked,+ },+ ]}+ keyExtractor={(item, index) => item.name}+ renderItem={({item, index}) => (+ <TouchableOpacity+ activeOpacity={opacity}+ onPress={() => {+ item.func();+ }}+ style={{+ width: '100%',+ alignSelf: 'center',+ flexDirection: 'row',+ justifyContent: 'space-between',+ alignItems: 'flex-end',+ paddingHorizontal: 12,+ paddingVertical: pv + 5,+ paddingTop: index === 0 ? 5 : pv + 5,+ }}>+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ }}>+ <Icon+ style={{+ width: 30,+ }}+ name={item.icon}+ color={colors.pri}+ size={SIZE.md}+ />+ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.sm,+ color: colors.pri,+ }}>+ {item.name}+ </Text>+ </View>+ {item.switch ? (+ <Icon+ size={SIZE.lg + 2}+ color={item.on ? colors.accent : colors.icon}+ name={item.on ? 'toggle-right' : 'toggle-left'}+ />+ ) : (+ undefined+ )}+ {item.check ? (+ <TouchableOpacity+ style={{+ borderWidth: 2,+ borderColor: item.on ? colors.accent : colors.icon,+ width: 23,+ height: 23,+ justifyContent: 'center',+ alignItems: 'center',+ borderRadius: 100,+ paddingTop: 3,+ }}>+ {item.on ? (+ <Icon size={SIZE.sm - 2} color={colors.accent} name="check" />+ ) : null}+ </TouchableOpacity>+ ) : null}+ </TouchableOpacity>+ )}+ />+ </View>+ );+};