mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
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:
@@ -219,7 +219,7 @@ export function getBlocks(db: Db, pageId: number): Block[] {
|
|||||||
kind: b.kind,
|
kind: b.kind,
|
||||||
label: b.label,
|
label: b.label,
|
||||||
markdown: b.markdown,
|
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,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export interface Block {
|
|||||||
kind: "link" | "text";
|
kind: "link" | "text";
|
||||||
label: string | null;
|
label: string | null;
|
||||||
markdown: 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 {
|
export interface PageDetail extends PageSummary {
|
||||||
|
|||||||
@@ -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 { Check, Copy } from "lucide-react";
|
||||||
import { cx } from "../../lib/cx.js";
|
import { cx } from "../../lib/cx.js";
|
||||||
import { linkHandler } from "../../router.js";
|
import { linkHandler } from "../../router.js";
|
||||||
import { Button } from "./button.js";
|
import { Button } from "./button.js";
|
||||||
import { useToast } from "./toast.js";
|
import { useToast } from "./toast.js";
|
||||||
|
|
||||||
export function Link({ to, className, children, ...rest }: { to: string; className?: string; children: ReactNode; "aria-current"?: "page" }) {
|
// In-app link: a normal <a> that navigates without a page reload.
|
||||||
return (
|
export function Link({ to, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) {
|
||||||
<a href={to} onClick={linkHandler(to)} className={className} {...rest}>
|
return <a href={to} onClick={linkHandler(to)} {...rest} />;
|
||||||
{children}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function publicUrl(path: string): string {
|
export function publicUrl(path: string): string {
|
||||||
|
|||||||
@@ -2,16 +2,18 @@ import { useEffect, useState } from "react";
|
|||||||
import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core";
|
import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core";
|
||||||
import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
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 type { Block, Me, PageDetail, PageSummary } from "../../../shared/api-types.js";
|
||||||
import { api, ApiRequestError, errorMessage, useApi } from "../../api.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 { Dialog, useConfirm } from "../../components/ui/dialog.js";
|
||||||
import { Field, Input, PrefixInput, Segmented, Select, Textarea } from "../../components/ui/form.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 { Card, CardHeader, EmptyState } from "../../components/ui/surface.js";
|
||||||
import { useAction, useToast } from "../../components/ui/toast.js";
|
import { useAction, useToast } from "../../components/ui/toast.js";
|
||||||
import { cx } from "../../lib/cx.js";
|
import { cx } from "../../lib/cx.js";
|
||||||
import { stripMarkdown } from "../../lib/markdown.js";
|
import { stripMarkdown } from "../../lib/markdown.js";
|
||||||
|
import { detailPath } from "../../router.js";
|
||||||
import { LivePreview } from "./PhonePreview.js";
|
import { LivePreview } from "./PhonePreview.js";
|
||||||
|
|
||||||
type Editing = { kind: "link"; block?: Block } | { kind: "text"; block?: Block } | null;
|
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 }) {
|
function SortableBlock({ block, onEdit, onDelete }: { block: Block; onEdit: () => void; onDelete: () => void }) {
|
||||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: block.id });
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: block.id });
|
||||||
const isLink = block.kind === "link";
|
const isLink = block.kind === "link";
|
||||||
@@ -275,8 +280,24 @@ function SortableBlock({ block, onEdit, onDelete }: { block: Block; onEdit: () =
|
|||||||
</span>
|
</span>
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<div className="truncate text-sm font-medium">{isLink ? block.label : stripMarkdown(block.markdown ?? "")}</div>
|
<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>
|
</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">
|
<Button variant="ghost" size="icon-sm" onClick={onEdit} aria-label="Edit">
|
||||||
<Pencil />
|
<Pencil />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user