From 00f5fe1f33e509ffee0959e2a26908df8bbdf194 Mon Sep 17 00:00:00 2001 From: Philipp Traber Date: Wed, 14 Oct 2026 17:36:03 +0200 Subject: [PATCH] Open a link button's short link from the content tab Link blocks get an arrow button, and their path becomes a link, both leading to the short link's own page (analytics, QR code, settings). Block targets now include their namespace so other users' links open under Administration. The Link component accepts all anchor attributes. Co-Authored-By: Claude Opus 5.5 --- src/server/lib/pages.ts | 2 +- src/shared/api-types.ts | 2 +- src/web/components/ui/misc.tsx | 11 ++++------- src/web/screens/detail/ContentTab.tsx | 27 ++++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 12 deletions(-) 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 && ( + + + + )}