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 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 17:36:03 +02:00
co-authored by Claude Opus 5.5
parent 5f30a6d448
commit 00f5fe1f33
4 changed files with 30 additions and 12 deletions
+1 -1
View File
@@ -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,
};
});
}
+1 -1
View File
@@ -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 {
+4 -7
View File
@@ -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 (
<a href={to} onClick={linkHandler(to)} className={className} {...rest}>
{children}
</a>
);
// In-app link: a normal <a> that navigates without a page reload.
export function Link({ to, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) {
return <a href={to} onClick={linkHandler(to)} {...rest} />;
}
export function publicUrl(path: string): string {
+24 -3
View File
@@ -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<Block["target"]>) => 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: () =
</span>
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-medium">{isLink ? block.label : stripMarkdown(block.markdown ?? "")}</div>
<div className="truncate font-mono text-xs text-muted">{isLink ? block.target?.path : "Text"}</div>
{isLink && block.target ? (
<Link to={targetPath(block.target)} className="block truncate font-mono text-xs text-muted hover:text-accent hover:underline">
{block.target.path}
</Link>
) : (
<div className="truncate font-mono text-xs text-muted">Text</div>
)}
</div>
{isLink && block.target && (
<Link
to={targetPath(block.target)}
className={buttonClass("ghost", "icon-sm")}
aria-label={`Open short link ${block.target.path}`}
title={`Open ${block.target.path}`}
>
<ArrowUpRight />
</Link>
)}
<Button variant="ghost" size="icon-sm" onClick={onEdit} aria-label="Edit">
<Pencil />
</Button>