diff --git a/src/server/lib/pages.ts b/src/server/lib/pages.ts index 751399f..b562a8c 100644 --- a/src/server/lib/pages.ts +++ b/src/server/lib/pages.ts @@ -219,7 +219,7 @@ export function getBlocks(db: Db, pageId: number): Block[] { kind: b.kind, label: b.label, markdown: b.markdown, - target: target ? { id: target.id, path: pagePath(target), dest: target.dest } : null, + target: target ? { id: target.id, namespace: target.namespace, path: pagePath(target), dest: target.dest } : null, }; }); } diff --git a/src/shared/api-types.ts b/src/shared/api-types.ts index 4870975..77a6d1b 100644 --- a/src/shared/api-types.ts +++ b/src/shared/api-types.ts @@ -32,7 +32,7 @@ export interface Block { kind: "link" | "text"; label: string | null; markdown: string | null; - target: { id: number; path: string; dest: string | null } | null; + target: { id: number; namespace: string; path: string; dest: string | null } | null; } export interface PageDetail extends PageSummary { diff --git a/src/web/components/ui/misc.tsx b/src/web/components/ui/misc.tsx index 090c4c1..5753f5d 100644 --- a/src/web/components/ui/misc.tsx +++ b/src/web/components/ui/misc.tsx @@ -1,16 +1,13 @@ -import { useState, type ReactNode } from "react"; +import { useState, type AnchorHTMLAttributes, type ReactNode } from "react"; import { Check, Copy } from "lucide-react"; import { cx } from "../../lib/cx.js"; import { linkHandler } from "../../router.js"; import { Button } from "./button.js"; import { useToast } from "./toast.js"; -export function Link({ to, className, children, ...rest }: { to: string; className?: string; children: ReactNode; "aria-current"?: "page" }) { - return ( - - {children} - - ); +// In-app link: a normal that navigates without a page reload. +export function Link({ to, ...rest }: AnchorHTMLAttributes & { to: string }) { + return ; } export function publicUrl(path: string): string { diff --git a/src/web/screens/detail/ContentTab.tsx b/src/web/screens/detail/ContentTab.tsx index 2226262..c79160f 100644 --- a/src/web/screens/detail/ContentTab.tsx +++ b/src/web/screens/detail/ContentTab.tsx @@ -2,16 +2,18 @@ import { useEffect, useState } from "react"; import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core"; import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; -import { GripVertical, LayoutList, Link2, Pencil, Plus, Trash2, Type } from "lucide-react"; +import { ArrowUpRight, GripVertical, LayoutList, Link2, Pencil, Plus, Trash2, Type } from "lucide-react"; import type { Block, Me, PageDetail, PageSummary } from "../../../shared/api-types.js"; import { api, ApiRequestError, errorMessage, useApi } from "../../api.js"; -import { Button } from "../../components/ui/button.js"; +import { Button, buttonClass } from "../../components/ui/button.js"; import { Dialog, useConfirm } from "../../components/ui/dialog.js"; import { Field, Input, PrefixInput, Segmented, Select, Textarea } from "../../components/ui/form.js"; +import { Link } from "../../components/ui/misc.js"; import { Card, CardHeader, EmptyState } from "../../components/ui/surface.js"; import { useAction, useToast } from "../../components/ui/toast.js"; import { cx } from "../../lib/cx.js"; import { stripMarkdown } from "../../lib/markdown.js"; +import { detailPath } from "../../router.js"; import { LivePreview } from "./PhonePreview.js"; type Editing = { kind: "link"; block?: Block } | { kind: "text"; block?: Block } | null; @@ -245,6 +247,9 @@ function BlockDialog({ ); } +// The short link's own page in the dashboard (analytics, QR code, settings). +const targetPath = (target: NonNullable) => detailPath({ id: target.id, kind: "redirect", namespace: target.namespace }); + function SortableBlock({ block, onEdit, onDelete }: { block: Block; onEdit: () => void; onDelete: () => void }) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: block.id }); const isLink = block.kind === "link"; @@ -275,8 +280,24 @@ function SortableBlock({ block, onEdit, onDelete }: { block: Block; onEdit: () = {isLink ? block.label : stripMarkdown(block.markdown ?? "")} - {isLink ? block.target?.path : "Text"} + {isLink && block.target ? ( + + {block.target.path} + + ) : ( + Text + )} + {isLink && block.target && ( + + + + )}