mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-18 20:49:36 +01:00
mobile: fix notebook move to trash
This commit is contained in:
committed by
Abdullah Atta
parent
6ad8d7ba1b
commit
a105c09841
@@ -17,13 +17,24 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { PropsWithChildren } from "react";
|
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
|
||||||
import { Platform, View, useWindowDimensions } from "react-native";
|
import { Dimensions, Platform, View, useWindowDimensions } from "react-native";
|
||||||
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
|
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
|
||||||
|
import useKeyboard from "../../hooks/use-keyboard";
|
||||||
|
|
||||||
export const Container = ({ children }: PropsWithChildren) => {
|
export const Container = ({ children }: PropsWithChildren) => {
|
||||||
const insets = useGlobalSafeAreaInsets();
|
const insets = useGlobalSafeAreaInsets();
|
||||||
const dimensions = useWindowDimensions();
|
const keyboard = useKeyboard();
|
||||||
|
const [height, setHeight] = useState(0);
|
||||||
|
const windowHeightRef = useRef(Dimensions.get("window").height);
|
||||||
|
const { height: windowHeight } = useWindowDimensions();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (windowHeight !== windowHeightRef.current) {
|
||||||
|
setHeight(0);
|
||||||
|
windowHeightRef.current = windowHeight;
|
||||||
|
}
|
||||||
|
}, [windowHeight]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
@@ -31,9 +42,14 @@ export const Container = ({ children }: PropsWithChildren) => {
|
|||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
paddingTop: Platform.OS === "android" ? 0 : insets.top,
|
paddingTop: Platform.OS === "android" ? 0 : insets.top,
|
||||||
paddingBottom: Platform.OS === "android" ? 0 : insets.bottom,
|
paddingBottom: Platform.OS === "android" ? 0 : insets.bottom,
|
||||||
height: dimensions.height,
|
height: height || "100%",
|
||||||
width: "100%"
|
width: "100%"
|
||||||
}}
|
}}
|
||||||
|
onLayout={(event) => {
|
||||||
|
if (!keyboard.keyboardShown) {
|
||||||
|
setHeight(event.nativeEvent.layout.height);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -109,17 +109,6 @@ export const NotebookSheet = () => {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
const PLACEHOLDER_DATA = {
|
|
||||||
heading: "Notebooks",
|
|
||||||
paragraph: "You have not added any notebooks yet.",
|
|
||||||
button: "Add a notebook",
|
|
||||||
action: () => {
|
|
||||||
if (!notebook) return;
|
|
||||||
AddNotebookSheet.present(undefined, notebook);
|
|
||||||
},
|
|
||||||
loading: "Loading notebook topics"
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNotebook = ({ index }: { item: boolean; index: number }) => (
|
const renderNotebook = ({ index }: { item: boolean; index: number }) => (
|
||||||
<NotebookItem
|
<NotebookItem
|
||||||
items={notebooks}
|
items={notebooks}
|
||||||
@@ -154,9 +143,11 @@ export const NotebookSheet = () => {
|
|||||||
if (ref.current?.isOpen()) {
|
if (ref.current?.isOpen()) {
|
||||||
ref.current?.snapToIndex(snapPoint);
|
ref.current?.snapToIndex(snapPoint);
|
||||||
} else {
|
} else {
|
||||||
ref.current?.show(snapPoint);
|
setTimeout(() => {
|
||||||
|
ref.current?.show(snapPoint);
|
||||||
|
}, 150);
|
||||||
}
|
}
|
||||||
console.log("NotebookSheet.useEffect.canShow", focusedRouteId);
|
console.log("NotebookSheet.useEffect.didShow", focusedRouteId);
|
||||||
setRoot(nextRoot);
|
setRoot(nextRoot);
|
||||||
onRequestUpdate();
|
onRequestUpdate();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,14 +63,12 @@ async function deleteNotebook(id, deleteNotes) {
|
|||||||
if (deleteNotes) {
|
if (deleteNotes) {
|
||||||
const noteRelations = await db.relations.from(notebook, "note").get();
|
const noteRelations = await db.relations.from(notebook, "note").get();
|
||||||
if (noteRelations?.length) {
|
if (noteRelations?.length) {
|
||||||
await db.notes.delete(...noteRelations.map((relation) => relation.toId));
|
await db.notes.moveToTrash(
|
||||||
|
...noteRelations.map((relation) => relation.toId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const subnotebooks = await db.relations.from(notebook, "notebook").get();
|
await db.notebooks.moveToTrash(id);
|
||||||
for (const subnotebook of subnotebooks) {
|
|
||||||
await deleteNotebook(subnotebook.toId, deleteNotes);
|
|
||||||
}
|
|
||||||
await db.notebooks.remove(id);
|
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
eSendEvent(eOnNotebookUpdated, parentId);
|
eSendEvent(eOnNotebookUpdated, parentId);
|
||||||
}
|
}
|
||||||
@@ -98,7 +96,6 @@ export const deleteItems = async (items, type, context) => {
|
|||||||
eSendEvent(eClearEditor);
|
eSendEvent(eClearEditor);
|
||||||
} else if (type === "notebook") {
|
} else if (type === "notebook") {
|
||||||
const result = await confirmDeleteAllNotes(ids, "notebook", context);
|
const result = await confirmDeleteAllNotes(ids, "notebook", context);
|
||||||
console.log(result);
|
|
||||||
if (!result.delete) return;
|
if (!result.delete) return;
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
await deleteNotebook(id, result.deleteNotes);
|
await deleteNotebook(id, result.deleteNotes);
|
||||||
|
|||||||
Reference in New Issue
Block a user