Skip to content

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

move multiple notes from one notebook to another

ammarahm-edb689975a3a40
diff --git a/apps/mobile/src/components/launcher/index.js b/apps/mobile/src/components/launcher/index.js
index 97aa56332..a3280a589 100644
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@ -38,325 +38,328 @@ import Paragraph from '../ui/typography/paragraph';
import { Walkthrough } from '../walkthroughs';
import NewFeature from '../sheets/new-feature/index';
-const Launcher = () => {
- const colors = useThemeStore(state => state.colors);
- const setNotes = useNoteStore(state => state.setNotes);
- const setFavorites = useFavoriteStore(state => state.setFavorites);
- const setLoading = useNoteStore(state => state.setLoading);
- const loading = useNoteStore(state => state.loading);
- const user = useUserStore(state => state.user);
- const verifyUser = useUserStore(state => state.verifyUser);
- const setVerifyUser = useUserStore(state => state.setVerifyUser);
- const deviceMode = useSettingStore(state => state.deviceMode);
- const passwordInputRef = useRef();
- const password = useRef();
- const [requireIntro, setRequireIntro] = useState({
- updated: false,
- value: false
- });
- const dbInitCompleted = useRef(false);
-
- const loadNotes = async () => {
- if (verifyUser) {
- return;
- }
- await restoreEditorState();
- await db.notes.init();
- setNotes();
- setFavorites();
- setLoading(false);
- Walkthrough.init();
- };
-
- const init = async () => {
- if (!dbInitCompleted.current) {
- await db.init();
- initialize();
- useUserStore.getState().setUser(await db.user.getUser());
- dbInitCompleted.current = true;
- }
-
- if (!verifyUser) {
- loadNotes();
- }
- };
+const Launcher = React.memo(
+ () => {
+ const colors = useThemeStore(state => state.colors);
+ const setNotes = useNoteStore(state => state.setNotes);
+ const setFavorites = useFavoriteStore(state => state.setFavorites);
+ const setLoading = useNoteStore(state => state.setLoading);
+ const loading = useNoteStore(state => state.loading);
+ const user = useUserStore(state => state.user);
+ const verifyUser = useUserStore(state => state.verifyUser);
+ const setVerifyUser = useUserStore(state => state.setVerifyUser);
+ const deviceMode = useSettingStore(state => state.deviceMode);
+ const passwordInputRef = useRef();
+ const password = useRef();
+ const [requireIntro, setRequireIntro] = useState({
+ updated: false,
+ value: false
+ });
+ const dbInitCompleted = useRef(false);
- const hideSplashScreen = async () => {
- await sleep(requireIntro.value ? 500 : 0);
- await RNBootSplash.hide({ fade: true });
- setTimeout(async () => {
- if (Platform.OS === 'android') {
- NativeModules.RNBars.setStatusBarStyle(!colors.night ? 'light-content' : 'dark-content');
- await sleep(5);
- NativeModules.RNBars.setStatusBarStyle(colors.night ? 'light-content' : 'dark-content');
- } else {
- StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
+ const loadNotes = async () => {
+ if (verifyUser) {
+ return;
}
- }, 500);
- };
-
- useEffect(() => {
- if (requireIntro.updated) {
- hideSplashScreen();
- }
- }, [requireIntro, verifyUser]);
+ await restoreEditorState();
+ await db.notes.init();
+ setNotes();
+ setFavorites();
+ setLoading(false);
+ Walkthrough.init();
+ };
- useEffect(() => {
- let introCompleted = SettingsService.get().introCompleted;
- setRequireIntro({
- updated: true,
- value: !introCompleted
- });
- }, []);
+ const init = async () => {
+ if (!dbInitCompleted.current) {
+ await db.init();
+ initialize();
+ useUserStore.getState().setUser(await db.user.getUser());
+ dbInitCompleted.current = true;
+ }
- useEffect(() => {
- if (!loading) {
- doAppLoadActions();
- }
- return () => {
- dbInitCompleted.current = false;
+ if (!verifyUser) {
+ loadNotes();
+ }
};
- }, [loading]);
-
- const doAppLoadActions = async () => {
- await sleep(500);
- if (SettingsService.get().sessionExpired) {
- eSendEvent('session_expired');
- return;
- }
- if (NewFeature.present()) return;
- if (await checkAppUpdateAvailable()) return;
- if (await checkForRateAppRequest()) return;
- if (await checkNeedsBackup()) return;
- if (await PremiumService.getRemainingTrialDaysStatus()) return;
- await useMessageStore.getState().setAnnouncement();
- if (!requireIntro?.value) {
- useMessageStore.subscribe(state => {
- let dialogs = state.dialogs;
- if (dialogs.length > 0) {
- eSendEvent(eOpenAnnouncementDialog, dialogs[0]);
+ const hideSplashScreen = async () => {
+ await sleep(requireIntro.value ? 500 : 0);
+ await RNBootSplash.hide({ fade: true });
+ setTimeout(async () => {
+ if (Platform.OS === 'android') {
+ NativeModules.RNBars.setStatusBarStyle(!colors.night ? 'light-content' : 'dark-content');
+ await sleep(5);
+ NativeModules.RNBars.setStatusBarStyle(colors.night ? 'light-content' : 'dark-content');
+ } else {
+ StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
}
- });
- }
- };
+ }, 500);
+ };
- const checkAppUpdateAvailable = async () => {
- try {
- const version = await checkVersion();
- if (!version.needsUpdate) return false;
- presentSheet({
- component: ref => <Update version={version} fwdRef={ref} />
+ useEffect(() => {
+ if (requireIntro.updated) {
+ hideSplashScreen();
+ }
+ }, [requireIntro, verifyUser]);
+
+ useEffect(() => {
+ let introCompleted = SettingsService.get().introCompleted;
+ setRequireIntro({
+ updated: true,
+ value: !introCompleted
});
+ }, []);
- return true;
- } catch (e) {
- return false;
- }
- };
+ useEffect(() => {
+ if (!loading) {
+ doAppLoadActions();
+ }
+ return () => {
+ dbInitCompleted.current = false;
+ };
+ }, [loading]);
- const restoreEditorState = async () => {
- let appState = await MMKV.getItem('appState');
- if (appState) {
- appState = JSON.parse(appState);
- if (
- appState.note &&
- !appState.note.locked &&
- !appState.movedAway &&
- Date.now() < appState.timestamp + 3600000
- ) {
- editing.isRestoringState = true;
- editing.currentlyEditing = true;
- editing.movedAway = false;
- if (!DDS.isTab) {
- tabBarRef.current?.goToPage(1);
- }
- eSendEvent('loadingNote', appState.note);
+ const doAppLoadActions = async () => {
+ await sleep(500);
+ if (SettingsService.get().sessionExpired) {
+ eSendEvent('session_expired');
+ return;
}
- }
- };
- const checkForRateAppRequest = async () => {
- let rateApp = SettingsService.get().rateApp;
- if (rateApp && rateApp < Date.now() && !useMessageStore.getState().message.visible) {
- setRateAppMessage();
- return true;
- }
- return false;
- };
+ if (NewFeature.present()) return;
+ if (await checkAppUpdateAvailable()) return;
+ if (await checkForRateAppRequest()) return;
+ if (await checkNeedsBackup()) return;
+ if (await PremiumService.getRemainingTrialDaysStatus()) return;
+ await useMessageStore.getState().setAnnouncement();
+ if (!requireIntro?.value) {
+ useMessageStore.subscribe(state => {
+ let dialogs = state.dialogs;
+ if (dialogs.length > 0) {
+ eSendEvent(eOpenAnnouncementDialog, dialogs[0]);
+ }
+ });
+ }
+ };
- const checkNeedsBackup = async () => {
- let { nextBackupRequestTime, reminder } = SettingsService.get();
- if (reminder === 'off' || !reminder) {
- if (nextBackupRequestTime < Date.now()) {
+ const checkAppUpdateAvailable = async () => {
+ try {
+ const version = await checkVersion();
+ if (!version.needsUpdate) return false;
presentSheet({
- title: 'Backup & restore',
- paragraph: 'Please enable automatic backups to keep your data safe',
- component: <SettingsBackupAndRestore isSheet={true} />
+ component: ref => <Update version={version} fwdRef={ref} />
});
return true;
+ } catch (e) {
+ return false;
}
- }
- return false;
- };
+ };
- const onUnlockBiometrics = async () => {
- if (!(await BiometricService.isBiometryAvailable())) {
- ToastEvent.show({
- heading: 'Biometrics unavailable',
- message: 'Try unlocking the app with your account password'
- });
- return;
- }
- let verified = await BiometricService.validateUser('Unlock to access your notes', '');
- if (verified) {
- setVerifyUser(false);
- password.current = null;
- }
- };
+ const restoreEditorState = async () => {
+ let appState = await MMKV.getItem('appState');
+ if (appState) {
+ appState = JSON.parse(appState);
+ if (
+ appState.note &&
+ !appState.note.locked &&
+ !appState.movedAway &&
+ Date.now() < appState.timestamp + 3600000
+ ) {
+ editing.isRestoringState = true;
+ editing.currentlyEditing = true;
+ editing.movedAway = false;
+ if (!DDS.isTab) {
+ tabBarRef.current?.goToPage(1);
+ }
+ eSendEvent('loadingNote', appState.note);
+ }
+ }
+ };
+
+ const checkForRateAppRequest = async () => {
+ let rateApp = SettingsService.get().rateApp;
+ if (rateApp && rateApp < Date.now() && !useMessageStore.getState().message.visible) {
+ setRateAppMessage();
+ return true;
+ }
+ return false;
+ };
- useEffect(() => {
- if (verifyUser) {
- onUnlockBiometrics();
- }
- init();
- }, [verifyUser]);
+ const checkNeedsBackup = async () => {
+ let { nextBackupRequestTime, reminder } = SettingsService.get();
+ if (reminder === 'off' || !reminder) {
+ if (nextBackupRequestTime < Date.now()) {
+ presentSheet({
+ title: 'Backup & restore',
+ paragraph: 'Please enable automatic backups to keep your data safe',
+ component: <SettingsBackupAndRestore isSheet={true} />
+ });
- const onSubmit = async () => {
- if (!password.current) return;
- try {
- let verified = await db.user.verifyPassword(password.current);
+ return true;
+ }
+ }
+ return false;
+ };
+
+ const onUnlockBiometrics = async () => {
+ if (!(await BiometricService.isBiometryAvailable())) {
+ ToastEvent.show({
+ heading: 'Biometrics unavailable',
+ message: 'Try unlocking the app with your account password'
+ });
+ return;
+ }
+ let verified = await BiometricService.validateUser('Unlock to access your notes', '');
if (verified) {
setVerifyUser(false);
password.current = null;
}
- } catch (e) {}
- };
+ };
- return verifyUser ? (
- <View
- style={{
- backgroundColor: colors.bg,
- width: '100%',
- height: '100%',
- position: 'absolute',
- zIndex: 999
- }}
- >
- <View
- style={{
- height: 250,
- overflow: 'hidden'
- }}
- >
- <SvgView src={SVG(colors.night ? 'white' : 'black')} height={700} />
- </View>
+ useEffect(() => {
+ if (verifyUser) {
+ onUnlockBiometrics();
+ }
+ init();
+ }, [verifyUser]);
+ const onSubmit = async () => {
+ if (!password.current) return;
+ try {
+ let verified = await db.user.verifyPassword(password.current);
+ if (verified) {
+ setVerifyUser(false);
+ password.current = null;
+ }
+ } catch (e) {}
+ };
+
+ return verifyUser ? (
<View
style={{
- flex: 1,
- justifyContent: 'center',
- width: deviceMode !== 'mobile' ? '50%' : Platform.OS == 'ios' ? '95%' : '100%',
- paddingHorizontal: 12,
- marginBottom: 30,
- marginTop: 15
+ backgroundColor: colors.bg,
+ width: '100%',
+ height: '100%',
+ position: 'absolute',
+ zIndex: 999
}}
>
- <IconButton
- name="fingerprint"
- size={100}
- customStyle={{
- width: 100,
- height: 100,
- marginBottom: 20,
- marginTop: user ? 0 : 50
- }}
- onPress={onUnlockBiometrics}
- color={colors.border}
- />
- <Heading
- color={colors.heading}
+ <View
style={{
- alignSelf: 'center',
- textAlign: 'center'
+ height: 250,
+ overflow: 'hidden'
}}
>
- Unlock to access your notes
- </Heading>
+ <SvgView src={SVG(colors.night ? 'white' : 'black')} height={700} />
+ </View>
- <Paragraph
- style={{
- alignSelf: 'center',
- textAlign: 'center',
- fontSize: SIZE.md,
- maxWidth: '90%'
- }}
- >
- Please verify it's you
- </Paragraph>
- <Seperator />
<View
style={{
- width: '100%',
- padding: 12,
- backgroundColor: colors.bg,
- flexGrow: 1
+ flex: 1,
+ justifyContent: 'center',
+ width: deviceMode !== 'mobile' ? '50%' : Platform.OS == 'ios' ? '95%' : '100%',
+ paddingHorizontal: 12,
+ marginBottom: 30,
+ marginTop: 15
}}
>
- {user ? (
- <>
- <Input
- fwdRef={passwordInputRef}
- secureTextEntry
- placeholder="Enter account password"
- onChangeText={v => (password.current = v)}
- onSubmit={onSubmit}
- />
- </>
- ) : null}
+ <IconButton
+ name="fingerprint"
+ size={100}
+ customStyle={{
+ width: 100,
+ height: 100,
+ marginBottom: 20,
+ marginTop: user ? 0 : 50
+ }}
+ onPress={onUnlockBiometrics}
+ color={colors.border}
+ />
+ <Heading
+ color={colors.heading}
+ style={{
+ alignSelf: 'center',
+ textAlign: 'center'
+ }}
+ >
+ Unlock to access your notes
+ </Heading>
+ <Paragraph
+ style={{
+ alignSelf: 'center',
+ textAlign: 'center',
+ fontSize: SIZE.md,
+ maxWidth: '90%'
+ }}
+ >
+ Please verify it's you
+ </Paragraph>
+ <Seperator />
<View
style={{
- marginTop: user ? 50 : 25
+ width: '100%',
+ padding: 12,
+ backgroundColor: colors.bg,
+ flexGrow: 1
}}
>
{user ? (
<>
- <Button
- title="Continue"
- type="accent"
- onPress={onSubmit}
- width={250}
- height={45}
- style={{
- borderRadius: 150,
- marginBottom: 10
- }}
- fontSize={SIZE.md}
+ <Input
+ fwdRef={passwordInputRef}
+ secureTextEntry
+ placeholder="Enter account password"
+ onChangeText={v => (password.current = v)}
+ onSubmit={onSubmit}
/>
</>
) : null}
- <Button
- title="Unlock with Biometrics"
- width={250}
- height={45}
+ <View
style={{
- borderRadius: 100
+ marginTop: user ? 50 : 25
}}
- onPress={onUnlockBiometrics}
- icon={'fingerprint'}
- type={user ? 'grayAccent' : 'accent'}
- fontSize={SIZE.md}
- />
+ >
+ {user ? (
+ <>
+ <Button
+ title="Continue"
+ type="accent"
+ onPress={onSubmit}
+ width={250}
+ height={45}
+ style={{
+ borderRadius: 150,
+ marginBottom: 10
+ }}
+ fontSize={SIZE.md}
+ />
+ </>
+ ) : null}
+
+ <Button
+ title="Unlock with Biometrics"
+ width={250}
+ height={45}
+ style={{
+ borderRadius: 100
+ }}
+ onPress={onUnlockBiometrics}
+ icon={'fingerprint'}
+ type={user ? 'grayAccent' : 'accent'}
+ fontSize={SIZE.md}
+ />
+ </View>
</View>
</View>
</View>
- </View>
- ) : requireIntro.value && !loading ? (
- <Intro />
- ) : null;
-};
+ ) : requireIntro.value && !loading ? (
+ <Intro />
+ ) : null;
+ },
+ () => true
+);
export default Launcher;
diff --git a/apps/mobile/src/components/selectionheader/index.js b/apps/mobile/src/components/selectionheader/index.js
index c2ef85d18..9fa49ba37 100644
--- a/apps/mobile/src/components/selectionheader/index.js
+++ b/apps/mobile/src/components/selectionheader/index.js
@@ -159,10 +159,7 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
size={SIZE.xl}
/> */}
- {screen === 'Trash' ||
- screen === 'Notebooks' ||
- screen === 'Notebook' ||
- type === 'topic' ? null : (
+ {screen === 'Trash' || screen === 'Notebooks' || screen === 'Notebook' ? null : (
<IconButton
onPress={async () => {
//setSelectionMode(false);
diff --git a/apps/mobile/src/components/sheets/addto/index.js b/apps/mobile/src/components/sheets/addto/index.js
index 4a836e6d0..c0e8047f7 100644
--- a/apps/mobile/src/components/sheets/addto/index.js
+++ b/apps/mobile/src/components/sheets/addto/index.js
@@ -2,20 +2,20 @@ import React, { createRef, useEffect, useState } from 'react';
import { Keyboard, TouchableOpacity, View } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import { notesnook } from '../../../../e2e/test.ids';
-import { useThemeStore } from '../../../stores/theme';
-import { useNotebookStore, useSelectionStore } from '../../../stores/stores';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
+import { useNotebookStore, useSelectionStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/theme';
import { getTotalNotes } from '../../../utils';
import { db } from '../../../utils/database';
import { eOpenMoveNoteDialog } from '../../../utils/events';
import layoutmanager from '../../../utils/layout-manager';
import { SIZE } from '../../../utils/size';
-import { IconButton } from '../../ui/icon-button';
-import { Button } from '../../ui/button';
import { Dialog } from '../../dialog';
import DialogHeader from '../../dialog/dialog-header';
import { presentDialog } from '../../dialog/functions';
+import { Button } from '../../ui/button';
+import { IconButton } from '../../ui/icon-button';
import Input from '../../ui/input';
import { PressableButton } from '../../ui/pressable';
import SheetWrapper from '../../ui/sheet';
@@ -58,20 +58,16 @@ const AddToNotebookSheet = () => {
]);
};
- const update = note => {
- setNote(note);
- };
-
return !visible ? null : (
<SheetWrapper fwdRef={actionSheetRef} onClose={_onClose}>
- <MoveNoteComponent close={close} note={note} setNote={update} />
+ <MoveNoteComponent note={note} />
</SheetWrapper>
);
};
export default AddToNotebookSheet;
-const MoveNoteComponent = ({ close, note, setNote }) => {
+const MoveNoteComponent = ({ note }) => {
const colors = useThemeStore(state => state.colors);
const notebooks = useNotebookStore(state => state.notebooks.filter(n => n?.type === 'notebook'));
@@ -121,47 +117,28 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
};
const handlePress = async (item, index) => {
- if (note && item.notes.indexOf(note.id) > -1) {
- await db.notebooks.notebook(item.notebookId).topics.topic(item.id).delete(note.id);
-
- if (note && note.id) {
- setNote({ ...db.notes.note(note.id).data });
- requestAnimationFrame(() => {
- //layoutmanager.withSpringAnimation(500);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
- });
- }
- setNotebooks();
- updateNoteExists();
+ let noteIds = selectedItemsList.length > 0 ? selectedItemsList.map(n => n.id) : [note?.id];
- return;
+ if (getCount(item)) {
+ await db.notebooks
+ .notebook(item.notebookId)
+ .topics.topic(item.id)
+ .delete(...noteIds);
+ } else {
+ await db.notes.move(
+ {
+ topic: item.id,
+ id: item.notebookId
+ },
+ ...noteIds
+ );
}
- let noteIds = [];
- selectedItemsList.forEach(i => noteIds.push(i.id));
-
- await db.notes.move(
- {
- topic: item.id,
- id: item.notebookId
- },
- ...noteIds
- );
- if (note && note.id) {
- setNote({ ...db.notes.note(note.id).data });
- requestAnimationFrame(() => {
- //layoutmanager.withSpringAnimation(500);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
- });
- }
+ Navigation.setRoutesToUpdate([
+ Navigation.routeNames.NotesPage,
+ Navigation.routeNames.Favorites,
+ Navigation.routeNames.Notes
+ ]);
setNotebooks();
updateNoteExists();
};
@@ -171,18 +148,29 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
}, []);
const updateNoteExists = () => {
- if (!note?.id) return;
+ if (!note?.id && selectedItemsList?.length === 0) return;
+
+ let notes = selectedItemsList.length > 0 ? selectedItemsList.map(n => n.id) : [note?.id];
+ console.log(notes);
let ids = [];
let notebooks = db.notebooks.all;
for (let i = 0; i < notebooks.length; i++) {
if (notebooks[i].topics) {
for (let t = 0; t < notebooks[i].topics.length; t++) {
- if (notebooks[i].topics[t].notes.indexOf(note.id) > -1) {
- ids.push(notebooks[i].id);
+ let topic = notebooks[i].topics[t];
+ for (let id of notes) {
+ if (topic.notes.indexOf(id) > -1) {
+ console.log('found', ids.indexOf(notebooks[i].id));
+ if (ids.indexOf(notebooks[i].id) === -1) {
+ ids.push(notebooks[i].id);
+ }
+ if (ids.indexOf(topic.id) === -1) ids.push(topic.id);
+ }
}
}
}
}
+ console.log('ids: ', ids);
setNoteExists(ids);
};
@@ -200,6 +188,20 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
});
};
+ const getCount = topic => {
+ if (!topic) return;
+ let notes = selectedItemsList.length > 0 ? selectedItemsList.map(n => n.id) : [note?.id];
+ let count = 0;
+ for (let id of notes) {
+ if (topic.notes.indexOf(id) > -1) {
+ count++;
+ }
+ }
+ return count > 0 && notes.length > 0
+ ? `${count} of ${notes.length} selected notes exist in this topic. (Tap to remove)`
+ : null;
+ };
+
return (
<>
<Dialog context="move_note" />
@@ -367,7 +369,7 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
onPress={() => handlePress(item, index)}
type="gray"
customStyle={{
- height: 50,
+ minHeight: 50,
borderTopWidth: index === 0 ? 0 : 1,
borderTopColor: index === 0 ? null : colors.nav,
width: '100%',
@@ -375,7 +377,8 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
alignItems: 'center',
flexDirection: 'row',
paddingHorizontal: 12,
- justifyContent: 'space-between'
+ justifyContent: 'space-between',
+ paddingVertical: 12
}}
>
<View>
@@ -383,8 +386,23 @@ const MoveNoteComponent = ({ close, note, setNote }) => {
<Paragraph color={colors.icon} size={SIZE.xs}>
{item.notes.length + ' notes'}
</Paragraph>
+ {getCount(item) ? (
+ <View
+ style={{
+ backgroundColor: colors.nav,
+ borderRadius: 5,
+ paddingHorizontal: 5,
+ paddingVertical: 2,
+ marginTop: 5
+ }}
+ >
+ <Paragraph color={colors.icon} size={SIZE.xs}>
+ {getCount(item)}
+ </Paragraph>
+ </View>
+ ) : null}
</View>
- {note && item.notes.indexOf(note.id) > -1 ? (
+ {noteExists.indexOf(item.id) > -1 ? (
<Button
onPress={() => handlePress(item, index)}
icon="check"