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/>.
*/
import React, { PropsWithChildren } from "react";
import { Platform, View, useWindowDimensions } from "react-native";
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
import { Dimensions, Platform, View, useWindowDimensions } from "react-native";
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
import useKeyboard from "../../hooks/use-keyboard";
export const Container = ({ children }: PropsWithChildren) => {
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 (
<View
@@ -31,9 +42,14 @@ export const Container = ({ children }: PropsWithChildren) => {
overflow: "hidden",
paddingTop: Platform.OS === "android" ? 0 : insets.top,
paddingBottom: Platform.OS === "android" ? 0 : insets.bottom,
height: dimensions.height,
height: height || "100%",
width: "100%"
}}
onLayout={(event) => {
if (!keyboard.keyboardShown) {
setHeight(event.nativeEvent.layout.height);
}
}}
>
{children}
</View>

View File

@@ -109,17 +109,6 @@ export const NotebookSheet = () => {
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 }) => (
<NotebookItem
items={notebooks}
@@ -154,9 +143,11 @@ export const NotebookSheet = () => {
if (ref.current?.isOpen()) {
ref.current?.snapToIndex(snapPoint);
} 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);
onRequestUpdate();
});

View File

@@ -63,14 +63,12 @@ async function deleteNotebook(id, deleteNotes) {
if (deleteNotes) {
const noteRelations = await db.relations.from(notebook, "note").get();
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();
for (const subnotebook of subnotebooks) {
await deleteNotebook(subnotebook.toId, deleteNotes);
}
await db.notebooks.remove(id);
await db.notebooks.moveToTrash(id);
if (parentId) {
eSendEvent(eOnNotebookUpdated, parentId);
}
@@ -98,7 +96,6 @@ export const deleteItems = async (items, type, context) => {
eSendEvent(eClearEditor);
} else if (type === "notebook") {
const result = await confirmDeleteAllNotes(ids, "notebook", context);
console.log(result);
if (!result.delete) return;
for (const id of ids) {
await deleteNotebook(id, result.deleteNotes);