mobile: fix notebook move to trash

This commit is contained in:
Ammar Ahmed
2024-02-10 22:30:18 +05:00
committed by Abdullah Atta
parent 6ad8d7ba1b
commit a105c09841
3 changed files with 28 additions and 24 deletions

View File

@@ -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>

View File

@@ -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();
}); });

View File

@@ -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);