Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

Route mobile editor returns to memo list

yoma7a2ad9e9c92a
diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsx
index dfb3e63e..85b49235 100644
--- a/apps/web/src/components/WorkspaceApp.tsx
+++ b/apps/web/src/components/WorkspaceApp.tsx
@@ -27,7 +27,7 @@ import {
import { MemoListPane, MemoSelectionActionBar } from "./MemoListPane";
import { AppConfirmDialog, MemoDeleteConfirmDialog, NotebookNameDialog } from "./dialogs/ConfirmDialogs";
import { api } from "@/lib/api";
-import { openStandaloneMobileEditor } from "@/lib/mobile-editor";
+import { MOBILE_EDITOR_RETURN_PARAM, openStandaloneMobileEditor } from "@/lib/mobile-editor";
import { cn } from "@/lib/utils";
import { createExcerpt, docToText, type Notebook, type AuthUser, type MemoSummary, type MemoDetail } from "@edgeever/shared";
import type {
@@ -108,6 +108,7 @@ const TagsDialog = lazy(() => import("./dialogs/TagsDialog").then((module) => ({
const TemplatesDialog = lazy(() => import("./dialogs/TemplatesDialog").then((module) => ({ default: module.TemplatesDialog })));
const SETTINGS_PATH = "/settings";
+const getMobileEditorReturnMemoId = (search: string) => new URLSearchParams(search).get(MOBILE_EDITOR_RETURN_PARAM);
const emptySyncQueueSummary = (): SyncQueueSummary => ({
total: 0,
pending: 0,
@@ -737,7 +738,8 @@ export const WorkspaceApp = ({
const location = useLocation();
const navigate = useNavigate();
const isInitialSettingsRoute = location.pathname === SETTINGS_PATH;
- const [activePane, setActivePane] = useState<Pane>(() => (isInitialSettingsRoute ? "editor" : "memos"));
+ const isInitialMobileEditorReturn = Boolean(getMobileEditorReturnMemoId(location.search));
+ const [activePane, setActivePane] = useState<Pane>(() => (isInitialSettingsRoute && !isInitialMobileEditorReturn ? "editor" : "memos"));
const [memoView, setMemoView] = useState<MemoView>("notebook");
const [selectedNotebookId, setSelectedNotebookId] = useState<string | null>(null);
const [selectedMemoId, setSelectedMemoId] = useState<string | null>(null);
@@ -760,7 +762,7 @@ export const WorkspaceApp = ({
const [templatesOpen, setTemplatesOpen] = useState(false);
const [mobileNotebookPickerOpen, setMobileNotebookPickerOpen] = useState(false);
const [mobileBottomNavActive, setMobileBottomNavActive] = useState<MobileBottomNavItem>(() =>
- isInitialSettingsRoute ? "settings" : "home"
+ isInitialSettingsRoute && !isInitialMobileEditorReturn ? "settings" : "home"
);
const [mobileSearchFocusToken, setMobileSearchFocusToken] = useState(0);
const [noteSearchFocusToken, setNoteSearchFocusToken] = useState(0);
@@ -897,6 +899,25 @@ export const WorkspaceApp = ({
const clearPendingCreatedMemo = useCallback(() => {}, []);
+ useEffect(() => {
+ const returnedMemoId = getMobileEditorReturnMemoId(location.search);
+ if (!returnedMemoId) {
+ return;
+ }
+
+ skipNextHomeRouteSyncRef.current = false;
+ setRightView("editor");
+ setMobileBottomNavActive("home");
+ setActivePane("memos");
+ setSelectedMemoId(null);
+ setCreatedMemoEditId(null);
+ clearMemoSelection();
+
+ if (location.pathname !== "/" || location.search) {
+ navigate("/", { replace: true });
+ }
+ }, [clearMemoSelection, location.pathname, location.search, navigate]);
+
const replaceMemoSelection = useCallback((memoIds: string[]) => {
setSelectedMemoIds(new Set(memoIds));
setMemoSelectionMode(true);
diff --git a/apps/web/src/lib/mobile-editor.ts b/apps/web/src/lib/mobile-editor.ts
index 0e4c02da..1dba5f10 100644
--- a/apps/web/src/lib/mobile-editor.ts
+++ b/apps/web/src/lib/mobile-editor.ts
@@ -1,8 +1,17 @@
export const STANDALONE_MOBILE_EDITOR_PATH = "/mobile-edit.html";
+export const MOBILE_EDITOR_RETURN_PARAM = "mobileEditorReturn";
const STANDALONE_MOBILE_EDITOR_MEMO_KEY = "edgeever-standalone-mobile-editor-memo-id";
const STANDALONE_MOBILE_EDITOR_RETURN_KEY = "edgeever-standalone-mobile-editor-return-memo-id";
-export const getStandaloneMobileEditorHref = (memoId: string, returnTo = "/") => {
+export const getStandaloneMobileEditorReturnPath = (memoId: string) => {
+ const params = new URLSearchParams({
+ [MOBILE_EDITOR_RETURN_PARAM]: memoId,
+ });
+
+ return `/?${params.toString()}`;
+};
+
+export const getStandaloneMobileEditorHref = (memoId: string, returnTo = getStandaloneMobileEditorReturnPath(memoId)) => {
const params = new URLSearchParams({
memoId,
returnTo,
@@ -10,7 +19,7 @@ export const getStandaloneMobileEditorHref = (memoId: string, returnTo = "/") =>
return `${STANDALONE_MOBILE_EDITOR_PATH}#${params.toString()}`;
};
-export const openStandaloneMobileEditor = (memoId: string, returnTo = "/") => {
+export const openStandaloneMobileEditor = (memoId: string, returnTo = getStandaloneMobileEditorReturnPath(memoId)) => {
markStandaloneMobileEditorOpened(memoId);
window.location.href = getStandaloneMobileEditorHref(memoId, returnTo);
};