refactor(web): drop the memo origin scope

The "all" / "preserve" origin scope existed to decide whether returning
from a memo detail should clear the remembered Space. With the Space now
part of the origin URL itself, nothing branches on it any more; it was only
computed, serialized into router state as fromScope, and threaded through
props as parentScope.

Router state is now just { from }, createMemoNavigationState takes one
argument, and resolveMemoDetailOrigin / resolveMemoParentPage return the
origin page as a string. The archived-memo fallback to /archived stays.
This commit is contained in:
johnnyjoygh 2026-09-07 09:33:47 +08:00
parent af008b2153
commit 9da3765b19
29 changed files with 63 additions and 226 deletions

View file

@ -270,7 +270,6 @@ const MemoDetailSidebarContent = () => {
memo={memoDetail.memo} memo={memoDetail.memo}
parentMemo={memoDetail.parentMemo} parentMemo={memoDetail.parentMemo}
parentPage={memoDetail.from} parentPage={memoDetail.from}
parentScope={memoDetail.fromScope}
hasExplicitOrigin={memoDetail.hasExplicitOrigin} hasExplicitOrigin={memoDetail.hasExplicitOrigin}
commentCount={memoDetail.commentCount} commentCount={memoDetail.commentCount}
forceReadonly={memoDetail.readonly} forceReadonly={memoDetail.readonly}

View file

@ -63,7 +63,7 @@ export const AttachmentSourceChip = ({
return ( return (
<Link <Link
to={`/${memoName}`} to={`/${memoName}`}
state={createMemoNavigationState(`${location.pathname}${location.search}`, "preserve")} state={createMemoNavigationState(`${location.pathname}${location.search}`)}
className="inline-flex max-w-full items-center truncate rounded-full border border-border/60 bg-muted/30 px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-muted/50" className="inline-flex max-w-full items-center truncate rounded-full border border-border/60 bg-muted/30 px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-muted/50"
> >
<span className="truncate">{t("attachment-library.labels.memo")}</span> <span className="truncate">{t("attachment-library.labels.memo")}</span>

View file

@ -3,7 +3,6 @@ import { type ComponentType, forwardRef, useCallback, useImperativeHandle, useRe
import { loadMemoEditor } from "@/components/MemoEditor/loader"; import { loadMemoEditor } from "@/components/MemoEditor/loader";
import type { MemoEditorProps } from "@/components/MemoEditor/types"; import type { MemoEditorProps } from "@/components/MemoEditor/types";
import MemoView from "@/components/MemoView"; import MemoView from "@/components/MemoView";
import type { MemoOriginScope } from "@/components/MemoView/navigation";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import useCurrentUser from "@/hooks/useCurrentUser"; import useCurrentUser from "@/hooks/useCurrentUser";
import { MEMO_COMMENTS_ANCHOR_ID } from "@/lib/memo-comments"; import { MEMO_COMMENTS_ANCHOR_ID } from "@/lib/memo-comments";
@ -17,7 +16,6 @@ interface Props {
comments: Memo[]; comments: Memo[];
commentCount?: number; commentCount?: number;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
hasMoreComments?: boolean; hasMoreComments?: boolean;
isFetchingMoreComments?: boolean; isFetchingMoreComments?: boolean;
onLoadMoreComments?: () => void; onLoadMoreComments?: () => void;
@ -29,19 +27,7 @@ export interface MemoCommentSectionHandle {
} }
const MemoCommentSection = forwardRef<MemoCommentSectionHandle, Props>( const MemoCommentSection = forwardRef<MemoCommentSectionHandle, Props>(
( ({ memo, comments, commentCount = comments.length, parentPage, hasMoreComments, isFetchingMoreComments, onLoadMoreComments }, ref) => {
{
memo,
comments,
commentCount = comments.length,
parentPage,
parentScope,
hasMoreComments,
isFetchingMoreComments,
onLoadMoreComments,
},
ref,
) => {
const t = useTranslate(); const t = useTranslate();
const currentUser = useCurrentUser(); const currentUser = useCurrentUser();
const [showEditor, setShowEditor] = useState(false); const [showEditor, setShowEditor] = useState(false);
@ -154,7 +140,7 @@ const MemoCommentSection = forwardRef<MemoCommentSectionHandle, Props>(
)} )}
{comments.map((comment) => ( {comments.map((comment) => (
<div className="w-full" key={comment.name} id={extractMemoIdFromName(comment.name)}> <div className="w-full" key={comment.name} id={extractMemoIdFromName(comment.name)}>
<MemoView memo={comment} parentPage={parentPage} parentScope={parentScope} showCreator showSpace compact /> <MemoView memo={comment} parentPage={parentPage} showCreator showSpace compact />
</div> </div>
))} ))}
{hasMoreComments && ( {hasMoreComments && (

View file

@ -7,7 +7,6 @@ import { isMentionElement, isTagElement, isTaskListItemElement } from "@/types/m
import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb"; import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb";
import { lazyWithReload } from "@/utils/lazy"; import { lazyWithReload } from "@/utils/lazy";
import { resolveManagedAttachmentImageSource } from "@/utils/managed-attachment"; import { resolveManagedAttachmentImageSource } from "@/utils/managed-attachment";
import type { MemoOriginScope } from "../MemoView/navigation";
import { CodeBlock } from "./CodeBlock"; import { CodeBlock } from "./CodeBlock";
import { MarkdownRenderContext, rootMarkdownRenderContext } from "./MarkdownRenderContext"; import { MarkdownRenderContext, rootMarkdownRenderContext } from "./MarkdownRenderContext";
import { Mention } from "./Mention"; import { Mention } from "./Mention";
@ -26,7 +25,6 @@ export interface MemoMarkdownRendererProps {
memoName?: string; memoName?: string;
/** Collection page that opened the memo detail. */ /** Collection page that opened the memo detail. */
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
/** Whether the memo is rendered as a collapsed feed card. */ /** Whether the memo is rendered as a collapsed feed card. */
compact?: boolean; compact?: boolean;
} }
@ -67,7 +65,6 @@ export const MemoMarkdownRendererCore = ({
resolvedMentionUsernames, resolvedMentionUsernames,
memoName, memoName,
parentPage, parentPage,
parentScope,
compact, compact,
mathRemarkPlugins = [], mathRemarkPlugins = [],
mathRehypePlugins = [], mathRehypePlugins = [],
@ -134,7 +131,7 @@ export const MemoMarkdownRendererCore = ({
// than opening a new tab; everything else is treated as an external link. // than opening a new tab; everything else is treated as an external link.
if (typeof href === "string" && href.startsWith("#")) { if (typeof href === "string" && href.startsWith("#")) {
return ( return (
<AnchorLink href={href} memoName={memoName} parentPage={parentPage} parentScope={parentScope} compact={compact} {...props}> <AnchorLink href={href} memoName={memoName} parentPage={parentPage} compact={compact} {...props}>
{children} {children}
</AnchorLink> </AnchorLink>
); );
@ -195,7 +192,6 @@ export const MemoMarkdownRenderer = memo(
previous.attachments === next.attachments && previous.attachments === next.attachments &&
previous.memoName === next.memoName && previous.memoName === next.memoName &&
previous.parentPage === next.parentPage && previous.parentPage === next.parentPage &&
previous.parentScope === next.parentScope &&
previous.compact === next.compact && previous.compact === next.compact &&
haveEqualResolvedMentions(previous.resolvedMentionUsernames, next.resolvedMentionUsernames), haveEqualResolvedMentions(previous.resolvedMentionUsernames, next.resolvedMentionUsernames),
); );

View file

@ -40,7 +40,6 @@ const MemoContent = (props: MemoContentProps) => {
resolvedMentionUsernames={resolvedMentionUsernames} resolvedMentionUsernames={resolvedMentionUsernames}
memoName={props.memoName} memoName={props.memoName}
parentPage={props.parentPage} parentPage={props.parentPage}
parentScope={props.parentScope}
compact={Boolean(props.compact)} compact={Boolean(props.compact)}
/> />
</div> </div>

View file

@ -2,7 +2,7 @@ import { Link } from "react-router-dom";
import { markdownStyles } from "@/lib/markdownStyles"; import { markdownStyles } from "@/lib/markdownStyles";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { findAnchorTarget } from "@/utils/markdown-manipulation"; import { findAnchorTarget } from "@/utils/markdown-manipulation";
import { createMemoNavigationState, type MemoOriginScope } from "../../MemoView/navigation"; import { createMemoNavigationState } from "../../MemoView/navigation";
import type { ReactMarkdownProps } from "./types"; import type { ReactMarkdownProps } from "./types";
interface AnchorLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>, ReactMarkdownProps { interface AnchorLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>, ReactMarkdownProps {
@ -11,7 +11,6 @@ interface AnchorLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>,
memoName?: string; memoName?: string;
/** Collection page that rendered the enclosing memo. */ /** Collection page that rendered the enclosing memo. */
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
/** Whether the memo is rendered as a collapsed feed card. */ /** Whether the memo is rendered as a collapsed feed card. */
compact?: boolean; compact?: boolean;
children: React.ReactNode; children: React.ReactNode;
@ -26,17 +25,7 @@ interface AnchorLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>,
* below the fold, so we fall back to navigating to the memo detail page (with the hash), where * below the fold, so we fall back to navigating to the memo detail page (with the hash), where
* MemoDetail scrolls the target into view. * MemoDetail scrolls the target into view.
*/ */
export const AnchorLink = ({ export const AnchorLink = ({ href, memoName, parentPage, compact, children, className, node: _node, ...props }: AnchorLinkProps) => {
href,
memoName,
parentPage,
parentScope,
compact,
children,
className,
node: _node,
...props
}: AnchorLinkProps) => {
const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => { const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
if (compact) return; // Let the link navigate to the detail page. if (compact) return; // Let the link navigate to the detail page.
const id = decodeURIComponent(href.slice(1)); const id = decodeURIComponent(href.slice(1));
@ -57,7 +46,7 @@ export const AnchorLink = ({
return ( return (
<Link <Link
to={`/${memoName}${href}`} to={`/${memoName}${href}`}
state={parentPage && parentScope ? createMemoNavigationState(parentPage, parentScope) : undefined} state={parentPage ? createMemoNavigationState(parentPage) : undefined}
onClick={handleClick} onClick={handleClick}
className={classes} className={classes}
{...props} {...props}

View file

@ -1,6 +1,5 @@
import type React from "react"; import type React from "react";
import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb"; import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb";
import type { MemoOriginScope } from "../MemoView/navigation";
export interface MemoContentProps { export interface MemoContentProps {
content: string; content: string;
@ -10,7 +9,6 @@ export interface MemoContentProps {
memoName?: string; memoName?: string;
/** Collection page that rendered the memo, preserved when an inline link opens its detail page. */ /** Collection page that rendered the memo, preserved when an inline link opens its detail page. */
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
/** The card renders collapsed (ClampedSection), so footnote links navigate instead of scrolling. */ /** The card renders collapsed (ClampedSection), so footnote links navigate instead of scrolling. */
compact?: boolean; compact?: boolean;
className?: string; className?: string;

View file

@ -19,7 +19,7 @@ import SidebarSection, { SIDEBAR_SECTION_STACK_CLASSES } from "@/components/AppS
import { extractHeadings } from "@/components/MemoContent/pipeline"; import { extractHeadings } from "@/components/MemoContent/pipeline";
import { getRelationBuckets, getRelationMemo } from "@/components/MemoMetadata/Relation/relationHelpers"; import { getRelationBuckets, getRelationMemo } from "@/components/MemoMetadata/Relation/relationHelpers";
import { useResolvedRelationMemos } from "@/components/MemoMetadata/Relation/useResolvedRelationMemos"; import { useResolvedRelationMemos } from "@/components/MemoMetadata/Relation/useResolvedRelationMemos";
import { createMemoNavigationState, type MemoOriginScope } from "@/components/MemoView/navigation"; import { createMemoNavigationState } from "@/components/MemoView/navigation";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { useInstance } from "@/contexts/InstanceContext"; import { useInstance } from "@/contexts/InstanceContext";
import { useOverflowTitle } from "@/hooks"; import { useOverflowTitle } from "@/hooks";
@ -37,7 +37,6 @@ interface Props {
memo: Memo; memo: Memo;
parentMemo?: Memo; parentMemo?: Memo;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
hasExplicitOrigin?: boolean; hasExplicitOrigin?: boolean;
commentCount?: number; commentCount?: number;
className?: string; className?: string;
@ -54,13 +53,11 @@ const BacklinkRow = ({
relation, relation,
snippet, snippet,
parentPage, parentPage,
parentScope,
referencedByLabel, referencedByLabel,
}: { }: {
relation: MemoRelation; relation: MemoRelation;
snippet: string; snippet: string;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
referencedByLabel: string; referencedByLabel: string;
}) => { }) => {
const { ref, title } = useOverflowTitle<HTMLSpanElement>(snippet); const { ref, title } = useOverflowTitle<HTMLSpanElement>(snippet);
@ -74,7 +71,7 @@ const BacklinkRow = ({
aria-label={`${referencedByLabel}: ${snippet}`} aria-label={`${referencedByLabel}: ${snippet}`}
className={cn(SIDEBAR_ROW_CLASSES, "text-muted-foreground hover:bg-sidebar-accent/65 hover:text-foreground")} className={cn(SIDEBAR_ROW_CLASSES, "text-muted-foreground hover:bg-sidebar-accent/65 hover:text-foreground")}
to={`/${relatedMemo.name}`} to={`/${relatedMemo.name}`}
state={parentPage && parentScope ? createMemoNavigationState(parentPage, parentScope) : undefined} state={parentPage ? createMemoNavigationState(parentPage) : undefined}
title={title} title={title}
viewTransition viewTransition
> >
@ -90,7 +87,6 @@ const MemoDetailSidebar = ({
memo, memo,
parentMemo, parentMemo,
parentPage, parentPage,
parentScope,
hasExplicitOrigin = false, hasExplicitOrigin = false,
commentCount, commentCount,
className, className,
@ -219,7 +215,7 @@ const MemoDetailSidebar = ({
aria-label={`${t("memo.parent-memo")}: ${parentSnippet}`} aria-label={`${t("memo.parent-memo")}: ${parentSnippet}`}
className={cn(SIDEBAR_ROW_CLASSES, "text-muted-foreground hover:bg-sidebar-accent/65 hover:text-foreground")} className={cn(SIDEBAR_ROW_CLASSES, "text-muted-foreground hover:bg-sidebar-accent/65 hover:text-foreground")}
to={`/${parentMemo.name}`} to={`/${parentMemo.name}`}
state={parentPage && parentScope ? createMemoNavigationState(parentPage, parentScope) : undefined} state={parentPage ? createMemoNavigationState(parentPage) : undefined}
title={parentSnippet} title={parentSnippet}
viewTransition viewTransition
> >
@ -235,7 +231,6 @@ const MemoDetailSidebar = ({
relation={relation} relation={relation}
snippet={backlinkSnippet(relation)} snippet={backlinkSnippet(relation)}
parentPage={parentPage} parentPage={parentPage}
parentScope={parentScope}
referencedByLabel={t("common.referenced-by")} referencedByLabel={t("common.referenced-by")}
/> />
); );

View file

@ -1,21 +1,20 @@
import MemoSnippetLink from "@/components/MemoView/components/MemoSnippetLink"; import MemoSnippetLink from "@/components/MemoView/components/MemoSnippetLink";
import { createMemoNavigationState, type MemoOriginScope } from "@/components/MemoView/navigation"; import { createMemoNavigationState } from "@/components/MemoView/navigation";
import type { MemoRelation_Memo } from "@/types/proto/api/v1/memo_service_pb"; import type { MemoRelation_Memo } from "@/types/proto/api/v1/memo_service_pb";
interface RelationCardProps { interface RelationCardProps {
memo: MemoRelation_Memo; memo: MemoRelation_Memo;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
className?: string; className?: string;
} }
const RelationCard = ({ memo, parentPage, parentScope, className }: RelationCardProps) => { const RelationCard = ({ memo, parentPage, className }: RelationCardProps) => {
return ( return (
<MemoSnippetLink <MemoSnippetLink
name={memo.name} name={memo.name}
snippet={memo.snippet} snippet={memo.snippet}
to={`/${memo.name}`} to={`/${memo.name}`}
state={parentPage && parentScope ? createMemoNavigationState(parentPage, parentScope) : undefined} state={parentPage ? createMemoNavigationState(parentPage) : undefined}
className={className} className={className}
/> />
); );

View file

@ -1,7 +1,6 @@
import { LinkIcon, MilestoneIcon } from "lucide-react"; import { LinkIcon, MilestoneIcon } from "lucide-react";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import MetadataSection from "@/components/MemoMetadata/MetadataSection"; import MetadataSection from "@/components/MemoMetadata/MetadataSection";
import type { MemoOriginScope } from "@/components/MemoView/navigation";
import { useNearViewport } from "@/hooks/useNearViewport"; import { useNearViewport } from "@/hooks/useNearViewport";
import type { MemoRelation } from "@/types/proto/api/v1/memo_service_pb"; import type { MemoRelation } from "@/types/proto/api/v1/memo_service_pb";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
@ -13,11 +12,10 @@ interface RelationListViewProps {
relations: MemoRelation[]; relations: MemoRelation[];
currentMemoName?: string; currentMemoName?: string;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
className?: string; className?: string;
} }
function RelationListView({ relations, currentMemoName, parentPage, parentScope, className }: RelationListViewProps) { function RelationListView({ relations, currentMemoName, parentPage, className }: RelationListViewProps) {
const t = useTranslate(); const t = useTranslate();
const [activeTab, setActiveTab] = useState<"referencing" | "referenced">("referencing"); const [activeTab, setActiveTab] = useState<"referencing" | "referenced">("referencing");
const { ref: viewportRef, isNearViewport } = useNearViewport<HTMLDivElement>(); const { ref: viewportRef, isNearViewport } = useNearViewport<HTMLDivElement>();
@ -81,12 +79,7 @@ function RelationListView({ relations, currentMemoName, parentPage, parentScope,
return null; return null;
} }
return ( return (
<RelationCard <RelationCard key={getRelationMemoName(relation, direction)} memo={resolvedMemos[memo.name] ?? memo} parentPage={parentPage} />
key={getRelationMemoName(relation, direction)}
memo={resolvedMemos[memo.name] ?? memo}
parentPage={parentPage}
parentScope={parentScope}
/>
); );
})} })}
</MetadataSection> </MetadataSection>

View file

@ -29,7 +29,6 @@ const STUB_CONTEXT: MemoViewContextValue = {
creator: undefined, creator: undefined,
currentUser: undefined, currentUser: undefined,
parentPage: "/", parentPage: "/",
parentScope: "all",
cardWidth: 0, cardWidth: 0,
isArchived: false, isArchived: false,
readonly: true, readonly: true,

View file

@ -25,7 +25,7 @@ import { MemoBody, MemoCommentListView, MemoHeader } from "./components";
import { MEMO_CARD_BASE_CLASSES } from "./constants"; import { MEMO_CARD_BASE_CLASSES } from "./constants";
import { useImagePreview } from "./hooks"; import { useImagePreview } from "./hooks";
import { computeCommentAmount, MemoViewContext } from "./MemoViewContext"; import { computeCommentAmount, MemoViewContext } from "./MemoViewContext";
import { isMemoDetailPath, resolveMemoOrigin } from "./navigation"; import { isMemoDetailPath, resolveMemoParentPage } from "./navigation";
import type { MemoViewHandle, MemoViewProps } from "./types"; import type { MemoViewHandle, MemoViewProps } from "./types";
const MemoShareImageDialog = lazyWithReload(() => import("../MemoActionMenu/MemoShareImageDialog")); const MemoShareImageDialog = lazyWithReload(() => import("../MemoActionMenu/MemoShareImageDialog"));
@ -36,7 +36,6 @@ const MemoView = forwardRef<MemoViewHandle, MemoViewProps>((props, ref) => {
memo: memoData, memo: memoData,
className, className,
parentPage: parentPageProp, parentPage: parentPageProp,
parentScope: parentScopeProp,
compact, compact,
timeDisplay, timeDisplay,
showCreator, showCreator,
@ -55,9 +54,8 @@ const MemoView = forwardRef<MemoViewHandle, MemoViewProps>((props, ref) => {
const isArchived = memoData.state === State.ARCHIVED; const isArchived = memoData.state === State.ARCHIVED;
const readonly = memoData.creator !== currentUser?.name && !isSuperUser(currentUser); const readonly = memoData.creator !== currentUser?.name && !isSuperUser(currentUser);
const location = useLocation(); const location = useLocation();
const { parentPage, parentScope } = resolveMemoOrigin({ const parentPage = resolveMemoParentPage({
explicitParentPage: parentPageProp, explicitParentPage: parentPageProp,
explicitParentScope: parentScopeProp,
pathname: location.pathname, pathname: location.pathname,
search: location.search, search: location.search,
memoName: memoData.name, memoName: memoData.name,
@ -135,7 +133,6 @@ const MemoView = forwardRef<MemoViewHandle, MemoViewProps>((props, ref) => {
creator, creator,
currentUser, currentUser,
parentPage, parentPage,
parentScope,
cardWidth, cardWidth,
isArchived, isArchived,
readonly, readonly,
@ -150,7 +147,6 @@ const MemoView = forwardRef<MemoViewHandle, MemoViewProps>((props, ref) => {
creator, creator,
currentUser, currentUser,
parentPage, parentPage,
parentScope,
cardWidth, cardWidth,
isArchived, isArchived,
readonly, readonly,

View file

@ -7,14 +7,13 @@ import { MemoRelation_Type } from "@/types/proto/api/v1/memo_service_pb";
import type { User } from "@/types/proto/api/v1/user_service_pb"; import type { User } from "@/types/proto/api/v1/user_service_pb";
import type { PreviewMediaItem } from "@/utils/media-item"; import type { PreviewMediaItem } from "@/utils/media-item";
import { RELATIVE_TIME_THRESHOLD_MS } from "./constants"; import { RELATIVE_TIME_THRESHOLD_MS } from "./constants";
import { isMemoDetailPath, type MemoOriginScope } from "./navigation"; import { isMemoDetailPath } from "./navigation";
export interface MemoViewContextValue { export interface MemoViewContextValue {
memo: Memo; memo: Memo;
creator: User | undefined; creator: User | undefined;
currentUser: User | undefined; currentUser: User | undefined;
parentPage: string; parentPage: string;
parentScope: MemoOriginScope;
cardWidth: number; cardWidth: number;
isArchived: boolean; isArchived: boolean;
readonly: boolean; readonly: boolean;

View file

@ -32,8 +32,7 @@ const BlurOverlay: React.FC<{ onClick?: () => void }> = ({ onClick }) => {
}; };
const MemoBody: React.FC<MemoBodyProps> = ({ compact }) => { const MemoBody: React.FC<MemoBodyProps> = ({ compact }) => {
const { memo, parentPage, parentScope, showBlurredContent, blurred, readonly, openEditor, openPreview, toggleBlurVisibility } = const { memo, parentPage, showBlurredContent, blurred, readonly, openEditor, openPreview, toggleBlurVisibility } = useMemoViewContext();
useMemoViewContext();
const { handleMemoContentClick, handleMemoContentDoubleClick } = useMemoHandlers({ readonly, openEditor, openPreview }); const { handleMemoContentClick, handleMemoContentDoubleClick } = useMemoHandlers({ readonly, openEditor, openPreview });
@ -58,7 +57,6 @@ const MemoBody: React.FC<MemoBodyProps> = ({ compact }) => {
<MemoContent <MemoContent
memoName={memo.name} memoName={memo.name}
parentPage={parentPage} parentPage={parentPage}
parentScope={parentScope}
content={memo.content} content={memo.content}
attachments={memo.attachments} attachments={memo.attachments}
onClick={handleMemoContentClick} onClick={handleMemoContentClick}
@ -66,7 +64,7 @@ const MemoBody: React.FC<MemoBodyProps> = ({ compact }) => {
compact={Boolean(compact)} compact={Boolean(compact)}
/> />
<AttachmentListView attachments={attachmentOnlyItems} onImagePreview={openPreview} /> <AttachmentListView attachments={attachmentOnlyItems} onImagePreview={openPreview} />
<RelationListView relations={referencedMemos} currentMemoName={memo.name} parentPage={parentPage} parentScope={parentScope} /> <RelationListView relations={referencedMemos} currentMemoName={memo.name} parentPage={parentPage} />
{memo.location && <LocationDisplayView location={memo.location} />} {memo.location && <LocationDisplayView location={memo.location} />}
</ClampedSection> </ClampedSection>
<MemoReactionListView memo={memo} reactions={memo.reactions} /> <MemoReactionListView memo={memo} reactions={memo.reactions} />

View file

@ -10,7 +10,7 @@ import { useMemoViewContext, useMemoViewDerived } from "../MemoViewContext";
import { createMemoNavigationState } from "../navigation"; import { createMemoNavigationState } from "../navigation";
const MemoCommentListView: React.FC = () => { const MemoCommentListView: React.FC = () => {
const { memo, parentPage, parentScope } = useMemoViewContext(); const { memo, parentPage } = useMemoViewContext();
const { isInMemoDetailPage, commentAmount } = useMemoViewDerived(); const { isInMemoDetailPage, commentAmount } = useMemoViewDerived();
const { ref: viewportRef, isNearViewport } = useNearViewport<HTMLDivElement>(); const { ref: viewportRef, isNearViewport } = useNearViewport<HTMLDivElement>();
@ -32,7 +32,7 @@ const MemoCommentListView: React.FC = () => {
<span className="text-xs text-muted-foreground">Comments{commentAmount > 1 ? ` (${commentAmount})` : ""}</span> <span className="text-xs text-muted-foreground">Comments{commentAmount > 1 ? ` (${commentAmount})` : ""}</span>
<Link <Link
to={`/${memo.name}#${MEMO_COMMENTS_ANCHOR_ID}`} to={`/${memo.name}#${MEMO_COMMENTS_ANCHOR_ID}`}
state={createMemoNavigationState(parentPage, parentScope)} state={createMemoNavigationState(parentPage)}
className="flex items-center gap-0.5 text-xs text-muted-foreground/80 hover:underline underline-offset-2 transition-colors" className="flex items-center gap-0.5 text-xs text-muted-foreground/80 hover:underline underline-offset-2 transition-colors"
> >
View all View all
@ -46,7 +46,7 @@ const MemoCommentListView: React.FC = () => {
<Link <Link
key={comment.name} key={comment.name}
to={`/${memo.name}#${uid}`} to={`/${memo.name}#${uid}`}
state={createMemoNavigationState(parentPage, parentScope)} state={createMemoNavigationState(parentPage)}
viewTransition viewTransition
className="rounded-md bg-muted/40 px-2 py-1 transition-colors hover:bg-muted/60" className="rounded-md bg-muted/40 px-2 py-1 transition-colors hover:bg-muted/60"
> >

View file

@ -29,15 +29,15 @@ const MemoHeader: React.FC<MemoHeaderProps> = ({ timeDisplay = "relative", showC
const t = useTranslate(); const t = useTranslate();
const [reactionSelectorOpen, setReactionSelectorOpen] = useState(false); const [reactionSelectorOpen, setReactionSelectorOpen] = useState(false);
const { memo, creator, currentUser, parentPage, parentScope, isArchived, readonly, openEditor } = useMemoViewContext(); const { memo, creator, currentUser, parentPage, isArchived, readonly, openEditor } = useMemoViewContext();
const { createTime, updateTime, displayTime: memoDisplayTime, isDisplayingUpdatedTime, relativeTimeFormat } = useMemoViewDerived(); const { createTime, updateTime, displayTime: memoDisplayTime, isDisplayingUpdatedTime, relativeTimeFormat } = useMemoViewDerived();
const { newMemoName } = useNewMemo(); const { newMemoName } = useNewMemo();
const visibilityOption = getVisibilityOption(memo.visibility); const visibilityOption = getVisibilityOption(memo.visibility);
const navigateTo = useNavigateTo(); const navigateTo = useNavigateTo();
const handleGotoMemoDetailPage = useCallback(() => { const handleGotoMemoDetailPage = useCallback(() => {
navigateTo(`/${memo.name}`, { state: createMemoNavigationState(parentPage, parentScope) }); navigateTo(`/${memo.name}`, { state: createMemoNavigationState(parentPage) });
}, [memo.name, parentPage, parentScope, navigateTo]); }, [memo.name, parentPage, navigateTo]);
const { unpinMemo } = useMemoActions(memo); const { unpinMemo } = useMemoActions(memo);

View file

@ -1,11 +1,8 @@
import { getProfileUsername, isMemoScopeRoute } from "@/lib/memo-views"; import { getProfileUsername } from "@/lib/memo-views";
import { ROUTES, resolveCollectionRoute } from "@/router/routes"; import { ROUTES } from "@/router/routes";
export type MemoOriginScope = "all" | "preserve";
export interface MemoNavigationState { export interface MemoNavigationState {
from: string; from: string;
fromScope: MemoOriginScope;
} }
interface ResolveMemoDetailOriginOptions { interface ResolveMemoDetailOriginOptions {
@ -14,7 +11,6 @@ interface ResolveMemoDetailOriginOptions {
interface ResolveMemoParentPageOptions { interface ResolveMemoParentPageOptions {
explicitParentPage?: string; explicitParentPage?: string;
explicitParentScope?: MemoOriginScope;
pathname: string; pathname: string;
search: string; search: string;
memoName: string; memoName: string;
@ -40,32 +36,13 @@ export const isMemoResourcePath = (pathname: string): boolean => {
return memoID.length > 0 && !memoID.includes("/"); return memoID.length > 0 && !memoID.includes("/");
}; };
/** Whether this origin represents a collection whose complete URL should be preserved. */ export const createMemoNavigationState = (from: string): MemoNavigationState => ({ from });
export const isMemoCollectionOrigin = (page: string): boolean => {
const pathname = page.split(/[?#]/, 1)[0] || ROUTES.HOME;
return isMemoScopeRoute(pathname) || resolveCollectionRoute(pathname).isCollection;
};
export const createMemoNavigationState = (from: string, fromScope: MemoOriginScope): MemoNavigationState => ({ from, fromScope }); /** Reads the origin page out of router state; without one, a detail returns to its collection. */
export const resolveMemoDetailOrigin = (state: unknown, options: ResolveMemoDetailOriginOptions = {}): string => {
/** Reads router state while remaining compatible with older `{ from }` links. */ const value = state && typeof state === "object" ? (state as { from?: unknown }) : undefined;
export const resolveMemoDetailOrigin = (
state: unknown,
options: ResolveMemoDetailOriginOptions = {},
): { parentPage: string; parentScope: MemoOriginScope } => {
const value = state && typeof state === "object" ? (state as { from?: unknown; fromScope?: unknown }) : undefined;
const explicitParentPage = typeof value?.from === "string" ? value.from : undefined; const explicitParentPage = typeof value?.from === "string" ? value.from : undefined;
const hasExplicitParent = explicitParentPage !== undefined; return explicitParentPage || (options.memoArchived ? ROUTES.ARCHIVED : ROUTES.HOME);
const parentPage = explicitParentPage || (options.memoArchived ? ROUTES.ARCHIVED : ROUTES.HOME);
const parentScope =
value?.fromScope === "all" || value?.fromScope === "preserve"
? value.fromScope
: hasExplicitParent && isMemoCollectionOrigin(parentPage)
? "preserve"
: options.memoArchived
? "preserve"
: "all";
return { parentPage, parentScope };
}; };
/** Whether the current route is the canonical detail page for this memo. */ /** Whether the current route is the canonical detail page for this memo. */
@ -79,33 +56,12 @@ export const isMemoDetailPath = (pathname: string, memoName: string): boolean =>
* Captures the list page that opened a memo so canonical detail routes can * Captures the list page that opened a memo so canonical detail routes can
* return to the real collection lens instead of assuming Home. * return to the real collection lens instead of assuming Home.
*/ */
export const resolveMemoOrigin = ({ export const resolveMemoParentPage = ({ explicitParentPage, pathname, search, memoName }: ResolveMemoParentPageOptions): string => {
explicitParentPage, if (explicitParentPage !== undefined) return explicitParentPage || ROUTES.HOME;
explicitParentScope, if (isMemoDetailPath(pathname, memoName)) return ROUTES.HOME;
pathname, return `${pathname}${search}`;
search,
memoName,
}: ResolveMemoParentPageOptions): { parentPage: string; parentScope: MemoOriginScope } => {
if (explicitParentPage !== undefined) {
const parentPage = explicitParentPage || ROUTES.HOME;
return {
parentPage,
parentScope: explicitParentScope ?? (isMemoCollectionOrigin(parentPage) ? "preserve" : "all"),
};
}
if (isMemoDetailPath(pathname, memoName)) {
return { parentPage: ROUTES.HOME, parentScope: "all" };
}
return {
parentPage: `${pathname}${search}`,
parentScope: isMemoCollectionOrigin(pathname) ? "preserve" : "all",
};
}; };
export const resolveMemoParentPage = (options: ResolveMemoParentPageOptions): string => resolveMemoOrigin(options).parentPage;
/** Replaces only the memo filter while preserving the rest of the origin query. */ /** Replaces only the memo filter while preserving the rest of the origin query. */
export const withMemoFilter = (page: string, filter: string): string => { export const withMemoFilter = (page: string, filter: string): string => {
const [pathAndSearch] = page.split("#", 1); const [pathAndSearch] = page.split("#", 1);

View file

@ -1,5 +1,4 @@
import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb";
import type { MemoOriginScope } from "./navigation";
/** How the header names the memo's time: relative to now, or just the clock time for lists that already name the day. */ /** How the header names the memo's time: relative to now, or just the clock time for lists that already name the day. */
export type MemoTimeDisplay = "relative" | "time"; export type MemoTimeDisplay = "relative" | "time";
@ -14,7 +13,6 @@ export interface MemoViewProps {
showSpace?: boolean; showSpace?: boolean;
className?: string; className?: string;
parentPage?: string; parentPage?: string;
parentScope?: MemoOriginScope;
shareImageDialogOpen?: boolean; shareImageDialogOpen?: boolean;
onShareImageDialogOpenChange?: (open: boolean) => void; onShareImageDialogOpenChange?: (open: boolean) => void;
} }

View file

@ -157,7 +157,7 @@ const UserMemoMap = ({ creator, className }: Props) => {
</div> </div>
<Link <Link
to={`/memos/${memo.name.split("/").pop()}`} to={`/memos/${memo.name.split("/").pop()}`}
state={createMemoNavigationState(parentPage, "all")} state={createMemoNavigationState(parentPage)}
className="inline-flex items-center gap-1 rounded-full border border-border bg-background px-2.5 py-1 text-[11px] font-medium text-foreground transition-all hover:border-primary/40 hover:text-primary" className="inline-flex items-center gap-1 rounded-full border border-border bg-background px-2.5 py-1 text-[11px] font-medium text-foreground transition-all hover:border-primary/40 hover:text-primary"
> >
Open Open

View file

@ -1,6 +1,5 @@
import { createContext, type ReactNode, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react"; import { createContext, type ReactNode, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import type { MemoOriginScope } from "@/components/MemoView/navigation";
import type { PrimaryMemoScope } from "@/lib/memo-views"; import type { PrimaryMemoScope } from "@/lib/memo-views";
import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb";
@ -11,7 +10,6 @@ export interface MemoDetailSidebarDescriptor {
memo: Memo; memo: Memo;
parentMemo?: Memo; parentMemo?: Memo;
from?: string; from?: string;
fromScope?: MemoOriginScope;
hasExplicitOrigin?: boolean; hasExplicitOrigin?: boolean;
commentCount?: number; commentCount?: number;
readonly?: boolean; readonly?: boolean;

View file

@ -41,8 +41,6 @@ export const isCalendarRoute = (pathname: string): boolean => {
/** /**
* Routes that render a memo collection the sidebar can narrow: the scope routes, a user * Routes that render a memo collection the sidebar can narrow: the scope routes, a user
* profile and the calendar. Views, calendar days and tags apply in place on all of them. * profile and the calendar. Views, calendar days and tags apply in place on all of them.
* This is a different question from `isMemoCollectionOrigin` (MemoView/navigation.ts),
* which asks whether a memo origin is a collection whose full URL is worth returning to.
*/ */
export const isMemoCollectionRoute = (pathname: string): boolean => export const isMemoCollectionRoute = (pathname: string): boolean =>
isMemoScopeRoute(pathname) || getProfileUsername(pathname) !== undefined || isCalendarRoute(pathname); isMemoScopeRoute(pathname) || getProfileUsername(pathname) !== undefined || isCalendarRoute(pathname);

View file

@ -6,7 +6,7 @@ import MemoCommentSection, { type MemoCommentSectionHandle } from "@/components/
import { MentionResolutionProvider } from "@/components/MemoContent/MentionResolutionContext"; import { MentionResolutionProvider } from "@/components/MemoContent/MentionResolutionContext";
import MemoView, { type MemoViewHandle } from "@/components/MemoView"; import MemoView, { type MemoViewHandle } from "@/components/MemoView";
import { computeCommentAmount } from "@/components/MemoView/MemoViewContext"; import { computeCommentAmount } from "@/components/MemoView/MemoViewContext";
import { createMemoNavigationState, type MemoOriginScope, resolveMemoDetailOrigin } from "@/components/MemoView/navigation"; import { createMemoNavigationState, resolveMemoDetailOrigin } from "@/components/MemoView/navigation";
import { useAppSidebar } from "@/contexts/AppSidebarContext"; import { useAppSidebar } from "@/contexts/AppSidebarContext";
import { useAuth } from "@/contexts/AuthContext"; import { useAuth } from "@/contexts/AuthContext";
import { useInstance } from "@/contexts/InstanceContext"; import { useInstance } from "@/contexts/InstanceContext";
@ -25,7 +25,6 @@ const MemoSidebarRegistration = ({
memo, memo,
parentMemo, parentMemo,
from, from,
fromScope,
hasExplicitOrigin, hasExplicitOrigin,
commentCount, commentCount,
readonly, readonly,
@ -37,7 +36,6 @@ const MemoSidebarRegistration = ({
memo: Memo; memo: Memo;
parentMemo?: Memo; parentMemo?: Memo;
from: string; from: string;
fromScope: MemoOriginScope;
hasExplicitOrigin: boolean; hasExplicitOrigin: boolean;
commentCount?: number; commentCount?: number;
readonly: boolean; readonly: boolean;
@ -53,7 +51,6 @@ const MemoSidebarRegistration = ({
memo, memo,
parentMemo, parentMemo,
from, from,
fromScope,
hasExplicitOrigin, hasExplicitOrigin,
commentCount, commentCount,
readonly, readonly,
@ -65,7 +62,6 @@ const MemoSidebarRegistration = ({
}, [ }, [
commentCount, commentCount,
from, from,
fromScope,
hasExplicitOrigin, hasExplicitOrigin,
memo, memo,
onCommentCreate, onCommentCreate,
@ -113,8 +109,7 @@ const MemoDetail = () => {
const hasExplicitOrigin = const hasExplicitOrigin =
!!locationState && typeof locationState === "object" && typeof (locationState as { from?: unknown }).from === "string"; !!locationState && typeof locationState === "object" && typeof (locationState as { from?: unknown }).from === "string";
const resolvedOrigin = resolveMemoDetailOrigin(locationState, { memoArchived: memo?.state === State.ARCHIVED }); const resolvedOrigin = resolveMemoDetailOrigin(locationState, { memoArchived: memo?.state === State.ARCHIVED });
const parentPage = !hasExplicitOrigin && !currentUser && memo?.state !== State.ARCHIVED ? ROUTES.EXPLORE : resolvedOrigin.parentPage; const parentPage = !hasExplicitOrigin && !currentUser && memo?.state !== State.ARCHIVED ? ROUTES.EXPLORE : resolvedOrigin;
const parentScope = resolvedOrigin.parentScope;
const memoName = memo?.name ?? memoNameFromParams; const memoName = memo?.name ?? memoNameFromParams;
const displayMemo = useReactMemo(() => { const displayMemo = useReactMemo(() => {
if (!memo) return undefined; if (!memo) return undefined;
@ -197,7 +192,6 @@ const MemoDetail = () => {
memo={displayMemo} memo={displayMemo}
parentMemo={parentMemo} parentMemo={parentMemo}
from={parentPage} from={parentPage}
fromScope={parentScope}
hasExplicitOrigin={hasExplicitOrigin} hasExplicitOrigin={hasExplicitOrigin}
commentCount={isShareMode ? undefined : commentCount} commentCount={isShareMode ? undefined : commentCount}
readonly={isShareMode} readonly={isShareMode}
@ -213,7 +207,7 @@ const MemoDetail = () => {
<Link <Link
className="px-3 py-1 border border-border rounded-lg max-w-xs w-auto text-sm flex flex-row justify-start items-center flex-nowrap text-muted-foreground hover:shadow hover:opacity-80" className="px-3 py-1 border border-border rounded-lg max-w-xs w-auto text-sm flex flex-row justify-start items-center flex-nowrap text-muted-foreground hover:shadow hover:opacity-80"
to={`/${parentMemo.name}`} to={`/${parentMemo.name}`}
state={createMemoNavigationState(parentPage, parentScope)} state={createMemoNavigationState(parentPage)}
viewTransition viewTransition
> >
<ArrowUpLeftFromCircleIcon className="w-4 h-auto shrink-0 opacity-60 mr-2" /> <ArrowUpLeftFromCircleIcon className="w-4 h-auto shrink-0 opacity-60 mr-2" />
@ -227,7 +221,6 @@ const MemoDetail = () => {
memo={displayMemo} memo={displayMemo}
compact={false} compact={false}
parentPage={parentPage} parentPage={parentPage}
parentScope={parentScope}
shareImageDialogOpen={shareImageDialogOpen} shareImageDialogOpen={shareImageDialogOpen}
showCreator showCreator
showVisibility showVisibility
@ -242,7 +235,6 @@ const MemoDetail = () => {
comments={comments} comments={comments}
commentCount={commentCount} commentCount={commentCount}
parentPage={parentPage} parentPage={parentPage}
parentScope={parentScope}
hasMoreComments={hasNextComments} hasMoreComments={hasNextComments}
isFetchingMoreComments={isFetchingNextComments} isFetchingMoreComments={isFetchingNextComments}
onLoadMoreComments={fetchNextComments} onLoadMoreComments={fetchNextComments}

View file

@ -67,9 +67,7 @@ describe("<AttachmentMediaGrid>", () => {
fireEvent.click(memoLink); fireEvent.click(memoLink);
expect(onPreview).not.toHaveBeenCalled(); expect(onPreview).not.toHaveBeenCalled();
expect(screen.getByTestId("location-state")).toHaveTextContent( expect(screen.getByTestId("location-state")).toHaveTextContent('{"from":"/spaces/product/attachments?filter=tagSearch%3Awork"}');
'{"from":"/spaces/product/attachments?filter=tagSearch%3Awork","fromScope":"preserve"}',
);
}); });
it("keeps video duration inside the existing play badge", () => { it("keeps video duration inside the existing play badge", () => {

View file

@ -24,7 +24,6 @@ const renderFootnote = (compact = false, parentPage?: string) =>
resolvedMentionUsernames={new Set()} resolvedMentionUsernames={new Set()}
memoName="memos/abc123" memoName="memos/abc123"
parentPage={parentPage} parentPage={parentPage}
parentScope={parentPage ? "preserve" : undefined}
compact={compact} compact={compact}
/> />
</div> </div>

View file

@ -83,7 +83,6 @@ describe("MemoDetailSidebar", () => {
memo={memo} memo={memo}
parentMemo={parentMemo} parentMemo={parentMemo}
parentPage="/explore?filter=tagSearch%3Awork" parentPage="/explore?filter=tagSearch%3Awork"
parentScope="preserve"
hasExplicitOrigin hasExplicitOrigin
commentCount={3} commentCount={3}
onEdit={onEdit} onEdit={onEdit}
@ -144,9 +143,7 @@ describe("MemoDetailSidebar", () => {
relations: [createIncomingReference("memos/public")], relations: [createIncomingReference("memos/public")],
}); });
renderSidebar( renderSidebar(<MemoDetailSidebar memo={memo} parentPage="/explore" commentCount={1} onEdit={vi.fn()} onCommentCreate={vi.fn()} />);
<MemoDetailSidebar memo={memo} parentPage="/explore" parentScope="all" commentCount={1} onEdit={vi.fn()} onCommentCreate={vi.fn()} />,
);
expect(screen.queryByRole("button", { name: "common.edit" })).not.toBeInTheDocument(); expect(screen.queryByRole("button", { name: "common.edit" })).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "memo.comment.write-a-comment" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "memo.comment.write-a-comment" })).toBeInTheDocument();
@ -163,9 +160,7 @@ describe("MemoDetailSidebar", () => {
content: "Body", content: "Body",
}); });
renderSidebar( renderSidebar(<MemoDetailSidebar memo={memo} parentPage="/" commentCount={0} onEdit={vi.fn()} onCommentCreate={vi.fn()} />);
<MemoDetailSidebar memo={memo} parentPage="/" parentScope="all" commentCount={0} onEdit={vi.fn()} onCommentCreate={vi.fn()} />,
);
expect(screen.getByRole("link", { name: "memo.go-to:common.home" })).toHaveAttribute("href", "/"); expect(screen.getByRole("link", { name: "memo.go-to:common.home" })).toHaveAttribute("href", "/");
expect(screen.queryByText("memo.on-this-memo")).not.toBeInTheDocument(); expect(screen.queryByText("memo.on-this-memo")).not.toBeInTheDocument();
@ -187,7 +182,7 @@ describe("MemoDetailSidebar", () => {
content: "Body", content: "Body",
}); });
renderSidebar(<MemoDetailSidebar memo={memo} parentPage="/" parentScope="all" commentCount={0} />); renderSidebar(<MemoDetailSidebar memo={memo} parentPage="/" commentCount={0} />);
fireEvent.click(screen.getByRole("button", { name: "common.share" })); fireEvent.click(screen.getByRole("button", { name: "common.share" }));
expect(await screen.findByRole("menuitem", { name: "memo.copy-link" })).toBeInTheDocument(); expect(await screen.findByRole("menuitem", { name: "memo.copy-link" })).toBeInTheDocument();
@ -202,16 +197,7 @@ describe("MemoDetailSidebar", () => {
content: "Archived body", content: "Archived body",
}); });
renderSidebar( renderSidebar(<MemoDetailSidebar memo={memo} parentPage="/archived" commentCount={2} onEdit={vi.fn()} onCommentCreate={vi.fn()} />);
<MemoDetailSidebar
memo={memo}
parentPage="/archived"
parentScope="preserve"
commentCount={2}
onEdit={vi.fn()}
onCommentCreate={vi.fn()}
/>,
);
expect(screen.getByRole("link", { name: "memo.go-to:common.archived" })).toBeInTheDocument(); expect(screen.getByRole("link", { name: "memo.go-to:common.archived" })).toBeInTheDocument();
expect(screen.getByRole("link", { name: /memo.comment.self/ })).toHaveTextContent("2"); expect(screen.getByRole("link", { name: /memo.comment.self/ })).toHaveTextContent("2");
@ -237,7 +223,6 @@ describe("MemoDetailSidebar", () => {
memo={memo} memo={memo}
parentMemo={parentMemo} parentMemo={parentMemo}
parentPage="/explore" parentPage="/explore"
parentScope="all"
hasExplicitOrigin hasExplicitOrigin
commentCount={4} commentCount={4}
forceReadonly forceReadonly

View file

@ -81,7 +81,7 @@ describe("MemoFilterProvider", () => {
); );
render(<RouterProvider router={router} />); render(<RouterProvider router={router} />);
fireEvent.click(screen.getByRole("button", { name: "Select Tasks" })); fireEvent.click(screen.getByRole("button", { name: "Select Tasks" }));
const state = { from: origin, fromScope: "preserve" }; const state = { from: origin };
await act(() => router.navigate("/memos/1", { state })); await act(() => router.navigate("/memos/1", { state }));
await waitFor(() => expect(screen.getByTestId("filters")).toHaveTextContent("[]")); await waitFor(() => expect(screen.getByTestId("filters")).toHaveTextContent("[]"));
expect(router.state.location.search).toBe(""); expect(router.state.location.search).toBe("");

View file

@ -62,7 +62,6 @@ vi.mock("@/components/MemoView/MemoViewContext", () => ({
creator: state.creator, creator: state.creator,
currentUser: state.currentUser, currentUser: state.currentUser,
parentPage: "/explore?filter=tagSearch%3Awork", parentPage: "/explore?filter=tagSearch%3Awork",
parentScope: "preserve",
isArchived: false, isArchived: false,
readonly: false, readonly: false,
openEditor: vi.fn(), openEditor: vi.fn(),
@ -142,9 +141,7 @@ describe("MemoHeader navigation", () => {
expect(timestamp).toHaveFocus(); expect(timestamp).toHaveFocus();
fireEvent.click(timestamp); fireEvent.click(timestamp);
expect(screen.getByTestId("location")).toHaveTextContent( expect(screen.getByTestId("location")).toHaveTextContent('/memos/123|{"from":"/explore?filter=tagSearch%3Awork"}');
'/memos/123|{"from":"/explore?filter=tagSearch%3Awork","fromScope":"preserve"}',
);
}); });
it.each([false, true])("keeps the Space pill beside the timestamp when showCreator=%s", (showCreator) => { it.each([false, true])("keeps the Space pill beside the timestamp when showCreator=%s", (showCreator) => {

View file

@ -1,11 +1,9 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { import {
createMemoNavigationState, createMemoNavigationState,
isMemoCollectionOrigin,
isMemoDetailPath, isMemoDetailPath,
isMemoResourcePath, isMemoResourcePath,
resolveMemoDetailOrigin, resolveMemoDetailOrigin,
resolveMemoOrigin,
resolveMemoParentPage, resolveMemoParentPage,
withMemoFilter, withMemoFilter,
} from "@/components/MemoView/navigation"; } from "@/components/MemoView/navigation";
@ -32,53 +30,25 @@ describe("memo view navigation", () => {
).toBe("/explore?filter=contentSearch%3Aroadmap"); ).toBe("/explore?filter=contentSearch%3Aroadmap");
}); });
it("marks collection cards as preserving the remembered scope", () => { it("keeps a Profile map origin intact", () => {
expect(resolveMemoOrigin({ pathname: "/explore", search: "?filter=tagSearch%3Awork", memoName: "memos/123" })).toEqual({ expect(resolveMemoParentPage({ pathname: "/u/alice", search: "?view=map", memoName: "memos/123" })).toBe("/u/alice?view=map");
parentPage: "/explore?filter=tagSearch%3Awork",
parentScope: "preserve",
});
}); });
it("marks Profile cards as global without losing their Profile origin", () => { it("uses Home for direct and shared resource entries", () => {
expect(resolveMemoOrigin({ pathname: "/u/alice", search: "?view=map", memoName: "memos/123" })).toEqual({ expect(resolveMemoDetailOrigin(undefined)).toBe("/");
parentPage: "/u/alice?view=map", expect(resolveMemoDetailOrigin({ unrelated: true })).toBe("/");
parentScope: "all",
});
}); });
it("uses an All Home origin for direct and shared resource entries", () => { it("uses the user archive for a direct entry to an archived memo", () => {
expect(resolveMemoDetailOrigin(undefined)).toEqual({ parentPage: "/", parentScope: "all" }); expect(resolveMemoDetailOrigin(undefined, { memoArchived: true })).toBe("/archived");
expect(resolveMemoDetailOrigin({ unrelated: true })).toEqual({ parentPage: "/", parentScope: "all" });
});
it("uses a user-level Archived origin without changing the remembered Space", () => {
expect(resolveMemoDetailOrigin(undefined, { memoArchived: true })).toEqual({ parentPage: "/archived", parentScope: "preserve" });
}); });
it("keeps an explicit origin ahead of the archived fallback", () => { it("keeps an explicit origin ahead of the archived fallback", () => {
expect(resolveMemoDetailOrigin(createMemoNavigationState("/u/alice", "all"), { memoArchived: true })).toEqual({ expect(resolveMemoDetailOrigin(createMemoNavigationState("/u/alice"), { memoArchived: true })).toBe("/u/alice");
parentPage: "/u/alice",
parentScope: "all",
});
}); });
it("round-trips an explicit origin policy through router state", () => { it("round-trips an explicit origin through router state", () => {
const state = createMemoNavigationState("/", "preserve"); expect(resolveMemoDetailOrigin(createMemoNavigationState("/explore?filter=tagSearch%3Awork"))).toBe("/explore?filter=tagSearch%3Awork");
expect(resolveMemoDetailOrigin(state)).toEqual({ parentPage: "/", parentScope: "preserve" });
});
it("infers policy for legacy from-only router state", () => {
expect(resolveMemoDetailOrigin({ from: "/archived" })).toEqual({ parentPage: "/archived", parentScope: "preserve" });
expect(resolveMemoDetailOrigin({ from: "/u/alice" })).toEqual({ parentPage: "/u/alice", parentScope: "all" });
});
it.each([
"/",
"/explore?filter=tagSearch%3Awork",
"/archived",
"/attachments",
])("recognizes %s as a remembered collection origin", (page) => {
expect(isMemoCollectionOrigin(page)).toBe(true);
}); });
it.each([ it.each([

View file

@ -5,7 +5,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { resolveQuickFindSubmission } from "@/components/AppSidebar/QuickFindDialog"; import { resolveQuickFindSubmission } from "@/components/AppSidebar/QuickFindDialog";
import { getRouteActionPolicy, getSidebarRouteKind } from "@/components/AppSidebar/routes"; import { getRouteActionPolicy, getSidebarRouteKind } from "@/components/AppSidebar/routes";
import { CalendarHeader } from "@/components/CalendarView/CalendarHeader"; import { CalendarHeader } from "@/components/CalendarView/CalendarHeader";
import { resolveMemoDetailOrigin, resolveMemoOrigin } from "@/components/MemoView/navigation"; import { resolveMemoDetailOrigin, resolveMemoParentPage } from "@/components/MemoView/navigation";
import Calendar from "@/pages/Calendar"; import Calendar from "@/pages/Calendar";
import { buildCollectionPath, getSpaceSwitchPath, resolveCollectionRoute } from "@/router/routes"; import { buildCollectionPath, getSpaceSwitchPath, resolveCollectionRoute } from "@/router/routes";
import { SpaceRoute } from "@/router/SpaceRoute"; import { SpaceRoute } from "@/router/SpaceRoute";
@ -59,10 +59,10 @@ describe("Space route contract", () => {
it("carries the full calendar origin through a permanent memo link", () => { it("carries the full calendar origin through a permanent memo link", () => {
const parentPage = "/spaces/a/calendar/2026/09/06?filter=tagSearch%3Awork"; const parentPage = "/spaces/a/calendar/2026/09/06?filter=tagSearch%3Awork";
expect( expect(
resolveMemoOrigin({ pathname: "/spaces/a/calendar/2026/09/06", search: "?filter=tagSearch%3Awork", memoName: "memos/x" }), resolveMemoParentPage({ pathname: "/spaces/a/calendar/2026/09/06", search: "?filter=tagSearch%3Awork", memoName: "memos/x" }),
).toEqual({ parentPage, parentScope: "preserve" }); ).toBe(parentPage);
expect(resolveMemoDetailOrigin({ from: parentPage })).toEqual({ parentPage, parentScope: "preserve" }); expect(resolveMemoDetailOrigin({ from: parentPage })).toBe(parentPage);
expect(resolveMemoDetailOrigin(undefined)).toEqual({ parentPage: "/", parentScope: "all" }); expect(resolveMemoDetailOrigin(undefined)).toBe("/");
}); });
}); });