Skip to content

Commit

Permalink
mobile: tab history
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed May 14, 2024
1 parent 58845e5 commit 1e5d069
Show file tree
Hide file tree
Showing 26 changed files with 1,182 additions and 720 deletions.
8 changes: 1 addition & 7 deletions apps/mobile/app/components/sheets/editor-tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ const TabItemComponent = (props: {
}
props.close?.();
}}
onLongPress={() => {
useTabStore.getState().updateTab(props.tab.id, {
previewTab: false
});
}}
>
<View
style={{
Expand Down Expand Up @@ -154,8 +149,7 @@ const TabItemComponent = (props: {
color={props.tab.pinned ? colors.primary.accent : colors.primary.icon}
onPress={() => {
useTabStore.getState().updateTab(props.tab.id, {
pinned: !props.tab.pinned,
previewTab: false
pinned: !props.tab.pinned
});
}}
top={0}
Expand Down
10 changes: 4 additions & 6 deletions apps/mobile/app/components/sheets/link-note/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ import {
VirtualizedGrouping,
createInternalLink
} from "@notesnook/core";
import { NativeEvents } from "@notesnook/editor-mobile/src/utils/native-events";
import type { LinkAttributes } from "@notesnook/editor/dist/extensions/link";
import { useThemeColors } from "@notesnook/theme";
import React, { useEffect, useRef, useState } from "react";
import { TextInput, View } from "react-native";
import { FlatList } from "react-native-actions-sheet";
import { db } from "../../../common/database";
import { useDBItem } from "../../../hooks/use-db-item";
import { editorController } from "../../../screens/editor/tiptap/utils";
import { presentSheet } from "../../../services/event-manager";
import { SIZE } from "../../../utils/size";
import { Button } from "../../ui/button";
import Input from "../../ui/input";
import { Pressable } from "../../ui/pressable";
import Paragraph from "../../ui/typography/paragraph";
import type { LinkAttributes } from "@notesnook/editor/dist/extensions/link";
import {
EditorEvents,
editorController
} from "../../../screens/editor/tiptap/utils";

const ListNoteItem = ({
id,
Expand Down Expand Up @@ -193,7 +191,7 @@ export default function LinkNote(props: {
}
: undefined
);
editorController.current?.postMessage(EditorEvents.resolve, {
editorController.current?.postMessage(NativeEvents.resolve, {
data: {
href: link,
title: selectedNote.title
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"@trpc/react-query": "10.38.3",
"@trpc/server": "10.38.3",
"kysely": "^0.26.3",
"pathe": "1.1.2"
"pathe": "1.1.2",
"async-mutex": "^0.5.0"
},
"sideEffects": false
}
2 changes: 1 addition & 1 deletion apps/mobile/app/screens/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const useLockedNoteHandler = () => {
biometryAvailable: !!biometry,
biometryEnrolled: !!fingerprint
});
syncTabs();
syncTabs("biometry");
})();
}, [tab?.id]);

Expand Down
14 changes: 7 additions & 7 deletions apps/mobile/app/screens/editor/readonly-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import WebView from "react-native-webview";
import { useRef } from "react";
import { EDITOR_URI } from "./source";
import { EditorMessage } from "./tiptap/types";
import { EventTypes } from "./tiptap/editor-events";
import { EditorEvents } from "@notesnook/editor-mobile/src/utils/editor-events";
import { Attachment } from "@notesnook/editor";
import downloadAttachment from "../../common/filesystem/download-attachment";
import { EditorEvents } from "./tiptap/utils";
import { NativeEvents } from "@notesnook/editor-mobile/src/utils/native-events";
import { useThemeColors } from "@notesnook/theme";
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
import { db } from "../../common/database";
Expand Down Expand Up @@ -68,11 +68,11 @@ export function ReadonlyEditor(props: {
const data = event.nativeEvent.data;
const editorMessage = JSON.parse(data) as EditorMessage<any>;

if (editorMessage.type === EventTypes.logger) {
if (editorMessage.type === EditorEvents.logger) {
logger.info("[READONLY EDITOR LOG]", editorMessage.value);
}

if (editorMessage.type === EventTypes.readonlyEditorLoaded) {
if (editorMessage.type === EditorEvents.readonlyEditorLoaded) {
console.log("Readonly editor loaded.");
props.onLoad?.((content: { data: string; id: string }) => {
noteId.current = content.id;
Expand All @@ -84,7 +84,7 @@ export function ReadonlyEditor(props: {
);
setLoading(false);
});
} else if (editorMessage.type === EventTypes.getAttachmentData) {
} else if (editorMessage.type === EditorEvents.getAttachmentData) {
const attachment = (editorMessage.value as any).attachment as Attachment;

console.log("Getting attachment data:", attachment.hash, attachment.type);
Expand All @@ -103,7 +103,7 @@ export function ReadonlyEditor(props: {
);
editorRef.current?.postMessage(
JSON.stringify({
type: EditorEvents.attachmentData,
type: NativeEvents.attachmentData,
value: {
resolverId: (editorMessage.value as any).resolverId,
data
Expand All @@ -115,7 +115,7 @@ export function ReadonlyEditor(props: {
console.log("Error downloading attachment data");
editorRef.current?.postMessage(
JSON.stringify({
type: EditorEvents.attachmentData,
type: NativeEvents.attachmentData,
data: {
resolverId: (editorMessage.value as any).resolverId,
data: undefined
Expand Down
45 changes: 43 additions & 2 deletions apps/mobile/app/screens/editor/tiptap/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { sleep } from "../../../utils/time";
import { Settings } from "./types";
import { useTabStore } from "./use-tab-store";
import { getResponse, randId, textInput } from "./utils";
import { EditorSessionItem } from "./tab-history";

type Action = { job: string; id: string };

Expand Down Expand Up @@ -167,9 +168,10 @@ if (typeof statusBar !== "undefined") {
setLoading = async (loading?: boolean, tabId?: number) => {
await this.doAsync(`
const editorController = editorControllers[${
tabId || useTabStore.getState().currentTab
tabId === undefined ? useTabStore.getState().currentTab : tabId
}];
editorController.setLoading(${loading})
logger("info", editorController.setLoading);
`);
};

Expand Down Expand Up @@ -353,7 +355,46 @@ editor && editor.commands.insertImage({
response = editorControllers[${tabId}]?.scrollIntoView("${id}") || [];
`);
};
//todo add replace image function

newSession = async (sessionId: string, tabId: number, noteId: string) => {
return this.doAsync(`
globalThis.sessions.newSession("${sessionId}", ${tabId}, "${noteId}");
`);
};

getSession = async (id: string): Promise<EditorSessionItem | false> => {
return this.doAsync(`
response = globalThis.sessions.get("${id}");
`);
};

deleteSession = async (id: string) => {
return this.doAsync(`
globalThis.sessions.delete("${id}");
`);
};

deleteSessionsForTabId = async (tabId: number) => {
return this.doAsync(`
globalThis.sessions.deleteForTabId(${tabId});
`);
};

updateSession = async (
id: string,
session: {
tabId: number;
noteId: string;
scrollTop: number;
from: number;
to: number;
sessionId: string;
}
) => {
return this.doAsync(`
globalThis.sessions.updateSession("${id}", ${JSON.stringify(session)});
`);
};
}

export default Commands;
Loading

0 comments on commit 1e5d069

Please sign in to comment.