Skip to content

Commit

Permalink
mobile: multi-tab support
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed May 15, 2024
1 parent 1e5d069 commit df82c6f
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 135 deletions.
9 changes: 4 additions & 5 deletions apps/mobile/app/components/attachments/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,17 @@ const Actions = ({
relations
.map((relation) => relation.fromId)
.forEach(async (id) => {
const tab = useTabStore.getState().getTabForNote(id);
if (tab !== undefined) {
const isFocused = useTabStore.getState().currentTab === tab;
useTabStore.getState().forEachNoteTab(id, async (tab) => {
const isFocused = useTabStore.getState().currentTab === tab.id;
if (isFocused) {
eSendEvent(eOnLoadNote, {
item: await db.notes.note(id),
forced: true
});
} else {
editorController.current.commands.setLoading(true, tab);
editorController.current.commands.setLoading(true, tab.id);
}
}
});
});
close?.();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app/components/properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const Properties = ({ close = () => {}, item, buttons = [] }) => {
close();
eSendEvent(eOnLoadNote, {
item: item,
presistTab: true
newTab: true
});
if (!DDS.isTab) {
tabBarRef.current?.goToPage(1);
Expand Down
16 changes: 6 additions & 10 deletions apps/mobile/app/hooks/use-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-disable no-inner-declarations */
import { createInternalLink } from "@notesnook/core";
import { VAULT_ERRORS } from "@notesnook/core/dist/api/vault";
import {
Color,
Expand All @@ -39,8 +40,10 @@ import NoteHistory from "../components/note-history";
import { AddNotebookSheet } from "../components/sheets/add-notebook";
import MoveNoteSheet from "../components/sheets/add-to";
import ExportNotesSheet from "../components/sheets/export-notes";
import { MoveNotebookSheet } from "../components/sheets/move-notebook";
import { MoveNotes } from "../components/sheets/move-notes/movenote";
import PublishNoteSheet from "../components/sheets/publish-note";
import { ReferencesList } from "../components/sheets/references";
import { RelationsList } from "../components/sheets/relations-list/index";
import ReminderSheet from "../components/sheets/reminder";
import { useSideBarDraggingStore } from "../components/side-menu/dragging-store";
Expand All @@ -60,14 +63,10 @@ import { useRelationStore } from "../stores/use-relation-store";
import { useSelectionStore } from "../stores/use-selection-store";
import { useTagStore } from "../stores/use-tag-store";
import { useUserStore } from "../stores/use-user-store";
import Errors from "../utils/errors";
import { eOpenLoginDialog, eUpdateNoteInEditor } from "../utils/events";
import { deleteItems } from "../utils/functions";
import { convertNoteToText } from "../utils/note-to-text";
import { sleep } from "../utils/time";
import { ReferencesList } from "../components/sheets/references";
import { createInternalLink } from "@notesnook/core";
import { MoveNotebookSheet } from "../components/sheets/move-notebook";

export const useActions = ({
close,
Expand Down Expand Up @@ -542,14 +541,11 @@ export const useActions = ({
const toggleReadyOnlyMode = async () => {
const currentReadOnly = (item as Note).readonly;
await db.notes.readonly(!currentReadOnly, item?.id);

if (useTabStore.getState().hasTabForNote(item.id)) {
const tabId = useTabStore.getState().getTabForNote(item.id);
if (!tabId) return;
useTabStore.getState().updateTab(tabId, {
useTabStore.getState().forEachNoteTab(item.id, (tab) => {
useTabStore.getState().updateTab(tab.id, {
readonly: !currentReadOnly
});
}
});
Navigation.queueRoutesForUpdate();
close();
};
Expand Down
17 changes: 9 additions & 8 deletions apps/mobile/app/screens/editor/tiptap/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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";
import { EditorSessionItem } from "@notesnook/common/dist/utils/editor-sessions";

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

Expand Down Expand Up @@ -217,11 +217,11 @@ if (typeof statusBar !== "undefined") {

setTags = async (note: Note | null | undefined) => {
if (!note) return;
const tabId = useTabStore.getState().getTabForNote(note.id);

const tags = await db.relations.to(note, "tag").resolve();
await this.doAsync(
`
useTabStore.getState().forEachNoteTab(note.id, async (tab) => {
const tabId = tab.id;
const tags = await db.relations.to(note, "tag").resolve();
await this.doAsync(
`
const tags = editorTags[${tabId}];
if (tags && tags.current) {
tags.current.setTags(${JSON.stringify(
Expand All @@ -234,8 +234,9 @@ if (typeof statusBar !== "undefined") {
)});
}
`,
"setTags"
);
"setTags"
);
});
};

clearTags = async (tabId: number) => {
Expand Down
13 changes: 11 additions & 2 deletions apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,18 @@ export const useEditorEvents = (
editorMessage.value
);

const { hasContent, isLoading, needsRefresh } = editorMessage.value;

eSendEvent(eEditorTabFocused, editorMessage.tabId);

if (needsRefresh) {
useTabStore.getState().updateTab(editorMessage.tabId, {
needsRefresh: false
});
}

if (
(!editorMessage.value || editor.currentLoadingNoteId.current) &&
(isLoading || !hasContent || needsRefresh) &&
editorMessage.noteId
) {
if (!useSettingStore.getState().isAppLoading) {
Expand All @@ -619,7 +627,8 @@ export const useEditorEvents = (
eSendEvent(eOnLoadNote, {
item: note,
forced: true,
tabId: editorMessage.tabId
tabId: editorMessage.tabId,
refresh: hasContent && needsRefresh ? needsRefresh : false
});
}
} else {
Expand Down
Loading

0 comments on commit df82c6f

Please sign in to comment.