diff --git a/.assets/dashboard.png b/.assets/dashboard.png deleted file mode 100644 index ab01cf4..0000000 Binary files a/.assets/dashboard.png and /dev/null differ diff --git a/.assets/linkpage-editor.png b/.assets/linkpage-editor.png deleted file mode 100644 index 2fd6c45..0000000 Binary files a/.assets/linkpage-editor.png and /dev/null differ diff --git a/.assets/linkpage.png b/.assets/linkpage.png deleted file mode 100644 index d84c5ca..0000000 Binary files a/.assets/linkpage.png and /dev/null differ diff --git a/README.md b/README.md index e0b796e..4ae41c6 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,6 @@ A small self-hosted URL shortener and link-page tool for a handful of people, wi See [REQUIREMENTS.md](REQUIREMENTS.md) for the full feature list. -![Link page](.assets/linkpage.png) - -![Dashboard](.assets/dashboard.png) - -![Link page editor](.assets/linkpage-editor.png) - ## URLs | Path | What | diff --git a/package.json b/package.json index 7c1ea03..86f431c 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@vitejs/plugin-react": "^6.1.2", "concurrently": "^10.0.6", "drizzle-kit": "^0.31.11", + "lucide-react": "^1.56.0", "qrcode": "^1.5.4", "react": "^19.3.0", "react-dom": "^19.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 34128dc..cb866b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: drizzle-kit: specifier: ^0.31.11 version: 0.31.11 + lucide-react: + specifier: ^1.56.0 + version: 1.56.0(@types/react@19.3.0)(react@19.3.0) qrcode: specifier: ^1.5.4 version: 1.5.4 @@ -1398,6 +1401,15 @@ packages: resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} engines: {node: '>=8'} + lucide-react@1.56.0: + resolution: {integrity: sha512-b+hqj30/trHBma5r1zlKb6yLewQp6tUtnz9loc3xdrYerPmvLYhlEbyPVCJ8DOg2/blBf6lwPLznftFVACka6A==} + peerDependencies: + '@types/react': '*' + react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + '@types/react': + optional: true + magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} @@ -2540,6 +2552,12 @@ snapshots: dependencies: p-locate: 4.1.0 + lucide-react@1.56.0(@types/react@19.3.0)(react@19.3.0): + dependencies: + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + magic-string@0.30.21: dependencies: '@jridgewell/sourcemap-codec': 1.6.0 diff --git a/src/web/app/App.tsx b/src/web/app/App.tsx new file mode 100644 index 0000000..05dd65f --- /dev/null +++ b/src/web/app/App.tsx @@ -0,0 +1,100 @@ +import { ArrowLeft, LogIn } from "lucide-react"; +import type { Me } from "../../shared/api-types.js"; +import { useApi } from "../api.js"; +import { buttonClass } from "../components/ui/button.js"; +import { Link } from "../components/ui/misc.js"; +import { EmptyState } from "../components/ui/surface.js"; +import { parseRoute, usePath } from "../router.js"; +import { AdminScreen } from "../screens/AdminScreen.js"; +import { DetailScreen } from "../screens/detail/DetailScreen.js"; +import { ListScreen } from "../screens/ListScreen.js"; +import { OverviewScreen } from "../screens/OverviewScreen.js"; +import { TokensScreen } from "../screens/TokensScreen.js"; +import { Shell } from "./Shell.js"; + +function Login() { + return ( +
+
+ +

Sign in to short

+

Manage your short links, link pages and stats.

+ + + Continue with single sign-on + + + Back to homepage + +
+
+ ); +} + +function Splash() { + return ( +
+ +
+ ); +} + +export function App() { + const me = useApi("/me"); + const path = usePath(); + + if (me.error?.status === 401) return ; + if (me.error) { + return ( +
+
+

Can't reach the server

+

{me.error.message}

+
+
+ ); + } + if (!me.data) return ; + + const logout = async () => { + await fetch("/~/auth/logout", { method: "POST", credentials: "same-origin" }); + location.href = "/~/"; + }; + + const route = parseRoute(path); + let screen; + switch (route.name) { + case "overview": + screen = ; + break; + case "list": + screen = ; + break; + case "detail": + screen = ; + break; + case "tokens": + screen = ; + break; + case "admin": + screen = me.data.isAdmin ? : null; + break; + } + + return ( + + {screen ?? ( + } + title="Page not found" + description="This part of the dashboard doesn't exist." + action={ + + Go to overview + + } + /> + )} + + ); +} diff --git a/src/web/app/Shell.tsx b/src/web/app/Shell.tsx new file mode 100644 index 0000000..d1c09bc --- /dev/null +++ b/src/web/app/Shell.tsx @@ -0,0 +1,124 @@ +import type { ReactNode } from "react"; +import { KeyRound, LayoutDashboard, Link2, LogOut, PanelsTopLeft, ShieldCheck } from "lucide-react"; +import type { Me } from "../../shared/api-types.js"; +import { Button } from "../components/ui/button.js"; +import { Link } from "../components/ui/misc.js"; +import { cx } from "../lib/cx.js"; +import type { Route } from "../router.js"; + +type Section = "overview" | "links" | "pages" | "tokens" | "admin"; + +function sectionOf(route: Route): Section | null { + switch (route.name) { + case "overview": + case "tokens": + case "admin": + return route.name; + case "list": + case "detail": + return route.kind === "redirect" ? "links" : "pages"; + default: + return null; + } +} + +const NAV: { id: Section; label: string; short: string; to: string; icon: ReactNode; adminOnly?: boolean }[] = [ + { id: "overview", label: "Overview", short: "Overview", to: "/~/", icon: }, + { id: "links", label: "Short links", short: "Links", to: "/~/links", icon: }, + { id: "pages", label: "Link pages", short: "Pages", to: "/~/pages", icon: }, + { id: "tokens", label: "API tokens", short: "Tokens", to: "/~/tokens", icon: }, + { id: "admin", label: "Administration", short: "Admin", to: "/~/admin", icon: , adminOnly: true }, +]; + +function Logo() { + return ( + + + short + + ); +} + +function UserAvatar({ username }: { username: string }) { + return ( + + {username.charAt(0)} + + ); +} + +export function Shell({ me, route, onLogout, children }: { me: Me; route: Route; onLogout: () => void; children: ReactNode }) { + const active = sectionOf(route); + const items = NAV.filter((n) => !n.adminOnly || me.isAdmin); + + return ( +
+ {/* Desktop sidebar */} + + + {/* Mobile top bar */} +
+ +
+ + +
+
+ +
{children}
+ + {/* Mobile tab bar */} + +
+ ); +} diff --git a/src/web/components/BlockEditor.tsx b/src/web/components/BlockEditor.tsx deleted file mode 100644 index b34b929..0000000 --- a/src/web/components/BlockEditor.tsx +++ /dev/null @@ -1,156 +0,0 @@ -import { 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 type { Block, PageSummary } from "../../shared/api-types.js"; -import { api, useApi } from "../api.js"; -import { useAction } from "./ui.js"; - -function SortableBlock({ block, onChange }: { block: Block; onChange: (blocks: Block[]) => void }) { - const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: block.id }); - const [editing, setEditing] = useState(false); - const [text, setText] = useState(block.kind === "text" ? (block.markdown ?? "") : (block.label ?? "")); - const { busy, run } = useAction(); - - const save = () => - run(async () => { - onChange(await api("PATCH", `/blocks/${block.id}`, block.kind === "text" ? { markdown: text } : { label: text })); - setEditing(false); - }); - const remove = () => run(async () => onChange(await api("DELETE", `/blocks/${block.id}`))); - - return ( -
- -
-
{block.kind === "text" ? "Text" : `Link → ${block.target?.path}`}
- {editing ? ( - block.kind === "text" ? ( -