Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

feat(extension): polish the popup UI and allow editing titles (#3232)

Mohamed Bassemc24a885683e9
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index 231ed37c..ad30c124 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -42,7 +42,7 @@
"zod": "^4.2.0"
},
"devDependencies": {
- "@crxjs/vite-plugin": "2.7.1",
+ "@crxjs/vite-plugin": "3.0.0",
"@karakeep/tailwind-config": "workspace:^0.1.0",
"@karakeep/tsconfig": "workspace:^0.1.0",
"@types/chrome": "^0.0.260",
diff --git a/apps/browser-extension/src/BookmarkDeletedPage.tsx b/apps/browser-extension/src/BookmarkDeletedPage.tsx
index c26e9616..49312c1c 100644
--- a/apps/browser-extension/src/BookmarkDeletedPage.tsx
+++ b/apps/browser-extension/src/BookmarkDeletedPage.tsx
@@ -1,3 +1,17 @@
+import { Trash2 } from "lucide-react";
+
export default function BookmarkDeletedPage() {
- return <p className="text-xl">Bookmark Deleted!</p>;
+ return (
+ <div className="flex flex-col items-center gap-3 py-6 text-center">
+ <div className="flex size-10 items-center justify-center rounded-full bg-muted">
+ <Trash2 className="size-5 text-muted-foreground" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-base font-semibold">Bookmark deleted</p>
+ <p className="text-sm text-muted-foreground">
+ This page was removed from your Karakeep.
+ </p>
+ </div>
+ </div>
+ );
}
diff --git a/apps/browser-extension/src/BookmarkSavedPage.tsx b/apps/browser-extension/src/BookmarkSavedPage.tsx
index dc2647b7..dd4cc606 100644
--- a/apps/browser-extension/src/BookmarkSavedPage.tsx
+++ b/apps/browser-extension/src/BookmarkSavedPage.tsx
@@ -1,20 +1,44 @@
import { useState } from "react";
-import { ArrowUpRightFromSquare, Trash } from "lucide-react";
-import { Link, useNavigate, useParams } from "react-router-dom";
+import { CircleCheck, ExternalLink, Trash2 } from "lucide-react";
+import { useNavigate, useParams } from "react-router-dom";
-import { useDeleteBookmark } from "@karakeep/shared-react/hooks/bookmarks";
+import {
+ useAutoRefreshingBookmarkQuery,
+ useDeleteBookmark,
+} from "@karakeep/shared-react/hooks/bookmarks";
+import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";
+import { getSourceUrl } from "@karakeep/shared/utils/bookmarkUtils";
import BookmarkLists from "./components/BookmarkLists";
+import { ErrorCallout } from "./components/ErrorCallout";
import { ListsSelector } from "./components/ListsSelector";
import { NoteEditor } from "./components/NoteEditor";
import TagList from "./components/TagList";
import { TagsSelector } from "./components/TagsSelector";
+import { TitleEditor } from "./components/TitleEditor";
import { Button, buttonVariants } from "./components/ui/button";
import Spinner from "./Spinner";
import { cn } from "./utils/css";
import usePluginSettings from "./utils/settings";
import { MessageType } from "./utils/type";
+function Section({
+ title,
+ children,
+}: {
+ title: string;
+ children: React.ReactNode;
+}) {
+ return (
+ <section className="flex flex-col gap-2">
+ <h3 className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
+ {title}
+ </h3>
+ {children}
+ </section>
+ );
+}
+
export default function BookmarkSavedPage() {
const { bookmarkId } = useParams();
const navigate = useNavigate();
@@ -43,58 +67,94 @@ export default function BookmarkSavedPage() {
});
const { settings } = usePluginSettings();
+ const { data: bookmark } = useAutoRefreshingBookmarkQuery({
+ bookmarkId: bookmarkId ?? "",
+ });
if (!bookmarkId) {
- return <div>NOT FOUND</div>;
+ return (
+ <ErrorCallout title="Bookmark not found">
+ This bookmark doesn&apos;t exist.
+ </ErrorCallout>
+ );
+ }
+
+ // The title is editable below, so the header names where it came from.
+ const sourceUrl = bookmark ? getSourceUrl(bookmark) : null;
+ let subtitle: string | null = null;
+ if (sourceUrl) {
+ try {
+ subtitle = new URL(sourceUrl).hostname.replace(/^www\./, "");
+ } catch {
+ subtitle = sourceUrl;
+ }
+ } else if (bookmark?.content.type === BookmarkTypes.TEXT) {
+ subtitle = bookmark.content.text;
}
return (
- <div className="flex flex-col gap-2">
- {error && <p className="text-red-500">{error}</p>}
- <div className="flex items-center justify-between gap-2">
- <p className="text-xl">Hoarded!</p>
- <div className="flex gap-2">
- <Link
+ <div className="flex flex-col gap-5">
+ {error && (
+ <ErrorCallout title="Couldn't delete bookmark">{error}</ErrorCallout>
+ )}
+ <div className="flex items-start gap-3">
+ <CircleCheck className="mt-0.5 size-5 shrink-0 text-green-600 dark:text-green-500" />
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
+ <p className="text-base font-semibold leading-tight">Hoarded!</p>
+ <p className="truncate text-xs text-muted-foreground">
+ {subtitle ?? "Saved to Karakeep"}
+ </p>
+ </div>
+ <div className="flex shrink-0 items-center gap-1">
+ <a
className={cn(
- buttonVariants({ variant: "link" }),
- "flex gap-2 rounded-md p-3",
+ buttonVariants({ variant: "outline", size: "sm" }),
+ "h-8 gap-1.5 px-2.5",
)}
target="_blank"
rel="noreferrer"
- to={`${settings.address}/dashboard/preview/${bookmarkId}`}
+ href={`${settings.address}/dashboard/preview/${bookmarkId}`}
>
- <ArrowUpRightFromSquare className="my-auto" size="20" />
- <p className="my-auto">Open</p>
- </Link>
+ <ExternalLink className="size-3.5" />
+ Open
+ </a>
<Button
- variant="link"
+ variant="ghost"
+ size="icon"
onClick={() => deleteBookmark({ bookmarkId })}
- className="flex gap-2 text-red-500 hover:text-red-500"
+ disabled={isPending}
+ className="size-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
+ aria-label="Delete bookmark"
+ title="Delete bookmark"
>
- {!isPending ? (
- <>
- <Trash className="my-auto" size="20" />
- <p className="my-auto">Delete</p>
- </>
+ {isPending ? (
+ <Spinner className="size-4" />
) : (
- <span className="m-auto">
- <Spinner />
- </span>
+ <Trash2 className="size-4" />
)}
</Button>
</div>
</div>
- <hr />
- <p className="text-lg">Notes</p>
- <NoteEditor bookmarkId={bookmarkId} />
- <hr />
- <p className="text-lg">Tags</p>
- <TagList bookmarkId={bookmarkId} />
- <TagsSelector bookmarkId={bookmarkId} />
- <hr />
- <p className="text-lg">Lists</p>
- <BookmarkLists bookmarkId={bookmarkId} />
- <ListsSelector bookmarkId={bookmarkId} />
+ <Section title="Title">
+ <TitleEditor bookmarkId={bookmarkId} />
+ </Section>
+ <Section title="Note">
+ <NoteEditor bookmarkId={bookmarkId} />
+ </Section>
+ <Section title="Tags">
+ <div className="flex flex-wrap items-center gap-1.5">
+ <TagList bookmarkId={bookmarkId} />
+ <TagsSelector bookmarkId={bookmarkId} />
+ </div>
+ </Section>
+ <Section title="Lists">
+ <div className="flex flex-col divide-y overflow-hidden rounded-lg border">
+ {/* The picker sits above the lists so adding one doesn't push it
+ (and its open dropdown) down. */}
+ <ListsSelector bookmarkId={bookmarkId} />
+ <BookmarkLists bookmarkId={bookmarkId} />
+ </div>
+ </Section>
</div>
);
}
diff --git a/apps/browser-extension/src/CustomHeadersPage.tsx b/apps/browser-extension/src/CustomHeadersPage.tsx
deleted file mode 100644
index 1b3fd8df..00000000
--- a/apps/browser-extension/src/CustomHeadersPage.tsx
+++ /dev/null
@@ -1,155 +0,0 @@
-import { useEffect, useState } from "react";
-import { Plus, Trash2 } from "lucide-react";
-import { useNavigate } from "react-router-dom";
-
-import { Button } from "./components/ui/button";
-import { Input } from "./components/ui/input";
-import Logo from "./Logo";
-import usePluginSettings from "./utils/settings";
-
-export default function CustomHeadersPage() {
- const navigate = useNavigate();
- const { settings, setSettings } = usePluginSettings();
-
- // Convert headers object to array of entries for easier manipulation
- const [headers, setHeaders] = useState<{ key: string; value: string }[]>([]);
- const [newHeaderKey, setNewHeaderKey] = useState("");
- const [newHeaderValue, setNewHeaderValue] = useState("");
-
- // Update headers when settings change (e.g., when loaded from storage)
- useEffect(() => {
- setHeaders(
- Object.entries(settings.customHeaders || {}).map(([key, value]) => ({
- key,
- value,
- })),
- );
- }, [settings.customHeaders]);
-
- const handleAddHeader = () => {
- if (!newHeaderKey.trim() || !newHeaderValue.trim()) {
- return;
- }
-
- // Check if header already exists
- const existingIndex = headers.findIndex((h) => h.key === newHeaderKey);
- if (existingIndex >= 0) {
- // Update existing header
- const updatedHeaders = [...headers];
- updatedHeaders[existingIndex].value = newHeaderValue;
- setHeaders(updatedHeaders);
- } else {
- // Add new header
- setHeaders([...headers, { key: newHeaderKey, value: newHeaderValue }]);
- }
-
- setNewHeaderKey("");
- setNewHeaderValue("");
- };
-
- const handleRemoveHeader = (index: number) => {
- setHeaders(headers.filter((_, i) => i !== index));
- };
-
- const handleSave = () => {
- // Convert array back to object
- const headersObject = headers.reduce(
- (acc, { key, value }) => {
- if (key.trim() && value.trim()) {
- acc[key] = value;
- }
- return acc;
- },
- {} as Record<string, string>,
- );
-
- setSettings((s) => ({ ...s, customHeaders: headersObject }));
- navigate(-1);
- };
-
- const handleCancel = () => {
- navigate(-1);
- };
-
- return (
- <div className="flex flex-col space-y-2">
- <Logo />
- <span className="text-lg">Custom Headers</span>
- <p className="text-sm text-muted-foreground">
- Add custom HTTP headers that will be sent with every API request.
- </p>
- <hr />
-
- {/* Existing Headers List */}
- <div className="max-h-64 space-y-2 overflow-y-auto">
- {headers.length === 0 ? (
- <p className="py-4 text-center text-sm text-muted-foreground">
- No custom headers configured
- </p>
- ) : (
- headers.map((header, index) => (
- <div
- key={index}
- className="flex items-center gap-2 rounded-lg border bg-background p-3"
- >
- <div className="flex-1 space-y-1">
- <p className="text-sm font-semibold">{header.key}</p>
- <p className="truncate text-xs text-muted-foreground">
- {header.value}
- </p>
- </div>
- <Button
- variant="ghost"
- size="sm"
- onClick={() => handleRemoveHeader(index)}
- className="h-8 w-8 p-0 text-destructive hover:text-destructive"
- >
- <Trash2 className="h-4 w-4" />
- </Button>
- </div>
- ))
- )}
- </div>
-
- <hr />
-
- {/* Add New Header */}
- <div className="space-y-2">
- <p className="text-sm font-semibold">Add New Header</p>
- <Input
- placeholder="Header Name (e.g., X-Custom-Header)"
- value={newHeaderKey}
- onChange={(e) => setNewHeaderKey(e.target.value)}
- autoCapitalize="none"
- />
- <Input
- placeholder="Header Value"
- value={newHeaderValue}
- onChange={(e) => setNewHeaderValue(e.target.value)}
- autoCapitalize="none"
- />
- <Button
- variant="secondary"
- onClick={handleAddHeader}
- disabled={!newHeaderKey.trim() || !newHeaderValue.trim()}
- className="w-full"
- >
- <Plus className="mr-2 h-4 w-4" />
- Add Header
- </Button>
- </div>
-
- <hr />
-
- {/* Action Buttons */}
- <div className="flex gap-2">
- <Button variant="outline" onClick={handleCancel} className="flex-1">
- Cancel
- </Button>
- <Button onClick={handleSave} className="flex-1">
- Save
- </Button>
- </div>
- </div>
- );
-}
diff --git a/apps/browser-extension/src/Layout.tsx b/apps/browser-extension/src/Layout.tsx
index 5c6eb3d2..865b94b4 100644
--- a/apps/browser-extension/src/Layout.tsx
+++ b/apps/browser-extension/src/Layout.tsx
@@ -1,53 +1,60 @@
-import { Home, RefreshCw, Settings, X } from "lucide-react";
-import { Outlet, useNavigate } from "react-router-dom";
+import { House, RefreshCw, Settings, X } from "lucide-react";
+import { Navigate, Outlet, useNavigate } from "react-router-dom";
-import { Button } from "./components/ui/button";
+import { HeaderIconButton, PopupHeader } from "./components/PopupHeader";
+import { buttonVariants } from "./components/ui/button";
+import Spinner from "./Spinner";
+import { cn } from "./utils/css";
import usePluginSettings from "./utils/settings";
export default function Layout() {
const navigate = useNavigate();
const { settings, isPending: isInit } = usePluginSettings();
+
if (!isInit) {
- return <div className="p-4">Loading ... </div>;
+ return (
+ <div className="flex justify-center py-8 text-muted-foreground">
+ <Spinner className="size-5" />
+ </div>
+ );
}
if (!settings.apiKey || !settings.address) {
- navigate("/notconfigured");
- return;
+ return <Navigate to="/signin" replace />;
}
return (
- <div className="flex flex-col space-y-2">
- <div className="rounded-md bg-gray-100 p-4 dark:bg-gray-900">
- <Outlet />
- </div>
- <hr />
- <div className="flex justify-between space-x-3">
- <div className="my-auto">
- <a
- className="flex gap-2 text-foreground"
- target="_blank"
- rel="noreferrer"
- href={`${settings.address}/dashboard/bookmarks`}
- >
- <Home />
- <span className="text-md my-auto">Bookmarks</span>
- </a>
- </div>
- <div className="flex space-x-3">
- {process.env.NODE_ENV == "development" && (
- <Button onClick={() => navigate(0)}>
- <RefreshCw className="w-4" />
- </Button>
+ <div className="flex flex-col gap-4">
+ <PopupHeader>
+ <a
+ className={cn(
+ buttonVariants({ variant: "ghost", size: "icon" }),
+ "size-8 text-muted-foreground hover:text-foreground",
)}
- <Button onClick={() => navigate("/options")}>
- <Settings className="w-4" />
- </Button>
- <Button onClick={() => window.close()}>
- <X className="w-4" />
- </Button>
- </div>
- </div>
+ target="_blank"
+ rel="noreferrer"
+ href={`${settings.address}/dashboard/bookmarks`}
+ aria-label="Open Karakeep"
+ title="Open Karakeep"
+ >
+ <House className="size-4" />
+ </a>
+ {process.env.NODE_ENV == "development" && (
+ <HeaderIconButton label="Reload" onClick={() => navigate(0)}>
+ <RefreshCw className="size-4" />
+ </HeaderIconButton>
+ )}
+ <HeaderIconButton
+ label="Settings"
+ onClick={() => navigate("/options", { state: { canGoBack: true } })}
+ >
+ <Settings className="size-4" />
+ </HeaderIconButton>
+ <HeaderIconButton label="Close" onClick={() => window.close()}>
+ <X className="size-4" />
+ </HeaderIconButton>
+ </PopupHeader>
+ <Outlet />
</div>
);
}
diff --git a/apps/browser-extension/src/Logo.tsx b/apps/browser-extension/src/Logo.tsx
index b7c470ca..88ff8aac 100644
--- a/apps/browser-extension/src/Logo.tsx
+++ b/apps/browser-extension/src/Logo.tsx
@@ -1,14 +1,19 @@
import logoImgWhite from "../public/logo-full-white.png";
import logoImg from "../public/logo-full.png";
+import { cn } from "./utils/css";
-export default function Logo() {
+export default function Logo({ className }: { className?: string }) {
return (
- <span className="flex items-center justify-center">
- <img src={logoImg} alt="karakeep logo" className="h-14 dark:hidden" />
+ <span className="flex items-center">
+ <img
+ src={logoImg}
+ alt="karakeep logo"
+ className={cn("h-8 dark:hidden", className)}
+ />
<img
src={logoImgWhite}
alt="karakeep logo"
- className="hidden h-14 dark:block"
+ className={cn("hidden h-8 dark:block", className)}
/>
</span>
);
diff --git a/apps/browser-extension/src/NotConfiguredPage.tsx b/apps/browser-extension/src/NotConfiguredPage.tsx
deleted file mode 100644
index 94b95ed4..00000000
--- a/apps/browser-extension/src/NotConfiguredPage.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import { useEffect, useState } from "react";
-import { useNavigate } from "react-router-dom";
-
-import { Button } from "./components/ui/button";
-import { Input } from "./components/ui/input";
-import Logo from "./Logo";
-import usePluginSettings from "./utils/settings";
-import { isHttpUrl } from "./utils/url";
-
-export default function NotConfiguredPage() {
- const navigate = useNavigate();
-
- const { settings, setSettings } = usePluginSettings();
-
- const [error, setError] = useState("");
- const [serverAddress, setServerAddress] = useState(settings.address);
-
- useEffect(() => {
- setServerAddress(settings.address);
- }, [settings.address]);
-
- const onSave = () => {
- const input = serverAddress.trim();
- if (input == "") {
- setError("Server address is required");
- return;
- }
-
- // Add URL protocol validation
- if (!isHttpUrl(input)) {
- setError("Server address must start with http:// or https://");
- return;
- }
-
- setSettings((s) => ({ ...s, address: input.replace(/\/$/, "") }));
- navigate("/signin");
- };
-
- return (
- <div className="flex flex-col space-y-2">
- <Logo />
- <span className="pt-3">
- To use the plugin, you need to configure it first.
- </span>
- <p className="text-red-500">{error}</p>
- <div className="flex gap-2">
- <label className="my-auto">Server Address</label>
- <Input
- name="address"
- value={serverAddress}
- className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
- onChange={(e) => setServerAddress(e.target.value)}
- />
- </div>
- <div className="flex justify-start">
- <button
- type="button"
- onClick={() => navigate("/customheaders")}
- className="text-xs text-muted-foreground underline hover:text-foreground"
- >
- Configure Custom Headers
- {settings.customHeaders &&
- Object.keys(settings.customHeaders).length > 0 &&
- ` (${Object.keys(settings.customHeaders).length})`}
- </button>
- </div>
- <Button onClick={onSave}>Configure</Button>
- </div>
- );
-}
diff --git a/apps/browser-extension/src/OptionsPage.tsx b/apps/browser-extension/src/OptionsPage.tsx
index 653f9347..708a5a15 100644
--- a/apps/browser-extension/src/OptionsPage.tsx
+++ b/apps/browser-extension/src/OptionsPage.tsx
@@ -1,18 +1,12 @@
import React, { useEffect, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
-import { useNavigate } from "react-router-dom";
+import { Laptop, LogOut, Moon, Sun, SunMoon } from "lucide-react";
+import { useLocation, useNavigate } from "react-router-dom";
+import { PopupHeader } from "./components/PopupHeader";
import { Button } from "./components/ui/button";
import { Input } from "./components/ui/input";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "./components/ui/select";
import { Switch } from "./components/ui/switch";
-import Logo from "./Logo";
import Spinner from "./Spinner";
import {
hasHostPermission,
@@ -22,13 +16,21 @@ import {
import usePluginSettings, {
DEFAULT_BADGE_CACHE_EXPIRE_MS,
} from "./utils/settings";
+import { cn } from "./utils/css";
import { useTheme } from "./utils/ThemeProvider";
import { useTRPC } from "./utils/trpc";
+const THEME_OPTIONS = [
+ { value: "light", icon: Sun, label: "Light mode" },
+ { value: "dark", icon: Moon, label: "Dark mode" },
+ { value: "system", icon: Laptop, label: "System mode" },
+] as const;
+
export default function OptionsPage() {
const api = useTRPC();
const queryClient = useQueryClient();
const navigate = useNavigate();
+ const location = useLocation();
const { settings, setSettings } = usePluginSettings();
const { setTheme, theme } = useTheme();
@@ -84,153 +86,246 @@ export default function OptionsPage() {
invalidateWhoami();
}, [settings]);
- let loggedInMessage: React.ReactNode;
+ let accountLabel: React.ReactNode;
if (whoAmIError) {
if (whoAmIError.data?.code == "UNAUTHORIZED") {
- loggedInMessage = <span>Not logged in</span>;
+ accountLabel = "Not signed in";
} else {
- loggedInMessage = (
- <span>Something went wrong: {whoAmIError.message}</span>
+ accountLabel = (
+ <span className="text-destructive">
+ Something went wrong: {whoAmIError.message}
+ </span>
);
}
} else if (whoami) {
- loggedInMessage = <span>{whoami.email}</span>;
+ accountLabel = whoami.email;
} else {
- loggedInMessage = <Spinner />;
+ accountLabel = <Spinner className="size-4 text-muted-foreground" />;
}
+ // Opened from the popup's header: return to that screen. Going to "/" would
+ // re-run the save flow for the active tab. Otherwise (e.g. right after
+ // sign-in) "/" is where the user wants to go next.
+ const onBack = () => {
+ if ((location.state as { canGoBack?: boolean } | null)?.canGoBack) {
+ navigate(-1);
+ } else {
+ navigate("/");
+ }
+ };
+
const onLogout = () => {
if (settings.apiKeyId) {
deleteKey({ id: settings.apiKeyId });
}
setSettings((s) => ({ ...s, apiKey: "", apiKeyId: undefined }));
invalidateWhoami();
- navigate("/notconfigured");
+ navigate("/signin");
};
return (
- <div className="flex flex-col space-y-2">
- <Logo />
- <span className="text-lg">Settings</span>
- <hr />
- <div className="flex items-center justify-between gap-2">
- <span className="text-sm font-medium">Show count badge</span>
- <Switch
- checked={settings.showCountBadge}
- onCheckedChange={(checked) =>
- setSettings((s) => ({ ...s, showCountBadge: checked }))
- }
- />
- </div>
- {settings.showCountBadge && (
- <>
- <div className="flex items-center justify-between gap-2">
- <span className="text-sm font-medium">Use badge cache</span>
- <Switch
- checked={settings.useBadgeCache}
- onCheckedChange={(checked) =>
- setSettings((s) => ({ ...s, useBadgeCache: checked }))
- }
- />
+ <div className="flex flex-col gap-5">
+ <PopupHeader
+ title="Settings"
+ onBack={location.key !== "default" ? onBack : undefined}
+ />
+
+ <SettingsSection title="Account">
+ <div className="flex items-center gap-3 px-3 py-2.5">
+ <div className="flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm font-medium uppercase">
+ {whoami?.email?.[0] ?? "?"}
</div>
- {settings.useBadgeCache && (
- <>
- <div className="flex items-center justify-between gap-2">
- <span className="text-sm font-medium">
- Badge cache expire time (second)
- </span>
- <Input
- type="number"
- min="1"
- step="1"
- value={settings.badgeCacheExpireMs / 1000}
- onChange={(e) =>
- setSettings((s) => ({
- ...s,
- badgeCacheExpireMs:
- parseInt(e.target.value) * 1000 ||
- DEFAULT_BADGE_CACHE_EXPIRE_MS,
- }))
- }
- className="w-32"
- />
- </div>
- </>
- )}
- </>
- )}
- <hr />
- <div className="flex items-start justify-between gap-2">
- <div className="flex flex-col">
- <div className="flex items-center gap-2">
- <span className="text-sm font-medium">Client-side crawling</span>
- <span className="rounded bg-yellow-100 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-yellow-800 dark:bg-yellow-900/40 dark:text-yellow-300">
- Experimental
+ <div className="flex min-w-0 flex-1 flex-col">
+ <span className="truncate text-sm font-medium">{accountLabel}</span>
+ <span className="truncate text-xs text-muted-foreground">
+ {settings.address}
</span>
</div>
- <span className="text-xs text-gray-500">
- Captures the page in the browser instead of on the server. Slower,
- but captures the page more accurately as you see it. Enabling this
- asks for permission to read the content of pages you save.
- </span>
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-8 gap-1.5 px-2.5"
+ onClick={onLogout}
+ >
+ <LogOut className="size-3.5" />
+ Sign out
+ </Button>
</div>
- <Switch
- checked={clientSideCrawlingEnabled}
- onCheckedChange={onToggleClientSideCrawling}
- />
- </div>
- {clientSideCrawlingEnabled && (
- <div className="flex items-start justify-between gap-2 pl-4">
- <div className="flex flex-col">
- <span className="text-sm font-medium">Include images</span>
- <span className="text-xs text-gray-500">
- Including images makes the upload slower.
+ </SettingsSection>
+
+ <SettingsSection title="Saving">
+ <SettingsRow
+ label="Auto-save on open"
+ description="Save the page as soon as you open the extension. When off, you'll confirm first."
+ >
+ <Switch
+ checked={settings.autoSave}
+ onCheckedChange={(checked) =>
+ setSettings((s) => ({ ...s, autoSave: checked }))
+ }
+ />
+ </SettingsRow>
+ <SettingsRow
+ label={
+ <span className="flex items-center gap-2">
+ Client-side crawling
+ <span className="rounded bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-amber-800 dark:bg-amber-500/15 dark:text-amber-300">
+ Experimental
+ </span>
</span>
- </div>
+ }
+ description="Capture the page in your browser, exactly as you see it. Slower, and needs permission to read pages you save."
+ >
<Switch
- checked={settings.singleFileIncludeImages}
+ checked={clientSideCrawlingEnabled}
+ onCheckedChange={onToggleClientSideCrawling}
+ />
+ </SettingsRow>
+ {clientSideCrawlingEnabled && (
+ <SettingsRow
+ label="Include images"
+ description="Makes the upload slower."
+ inset
+ >
+ <Switch
+ checked={settings.singleFileIncludeImages}
+ onCheckedChange={(checked) =>
+ setSettings((s) => ({ ...s, singleFileIncludeImages: checked }))
+ }
+ />
+ </SettingsRow>
+ )}
+ </SettingsSection>
+
+ <SettingsSection title="Toolbar badge">
+ <SettingsRow
+ label="Show badge on saved pages"
+ description="Mark the toolbar icon when the current page is already saved."
+ >
+ <Switch
+ checked={settings.showCountBadge}
onCheckedChange={(checked) =>
- setSettings((s) => ({ ...s, singleFileIncludeImages: checked }))
+ setSettings((s) => ({ ...s, showCountBadge: checked }))
}
/>
- </div>
- )}
- <hr />
- <div className="flex items-center justify-between gap-2">
- <span className="text-sm font-medium">Auto-save on open</span>
- <Switch
- checked={settings.autoSave}
- onCheckedChange={(checked) =>
- setSettings((s) => ({ ...s, autoSave: checked }))
+ </SettingsRow>
+ {settings.showCountBadge && (
+ <SettingsRow
+ label="Cache badge status"
+ description="Fewer requests to your server, but the badge can be stale."
+ >
+ <Switch
+ checked={settings.useBadgeCache}
+ onCheckedChange={(checked) =>
+ setSettings((s) => ({ ...s, useBadgeCache: checked }))
+ }
+ />
+ </SettingsRow>
+ )}
+ {settings.showCountBadge && settings.useBadgeCache && (
+ <SettingsRow label="Cache duration" inset>
+ <div className="flex items-center gap-2">
+ <Input
+ type="number"
+ min="1"
+ step="1"
+ value={settings.badgeCacheExpireMs / 1000}
+ onChange={(e) =>
+ setSettings((s) => ({
+ ...s,
+ badgeCacheExpireMs:
+ parseInt(e.target.value) * 1000 ||
+ DEFAULT_BADGE_CACHE_EXPIRE_MS,
+ }))
+ }
+ className="h-8 w-20 text-right"
+ />
+ <span className="text-xs text-muted-foreground">sec</span>
+ </div>
+ </SettingsRow>
+ )}
+ </SettingsSection>
+
+ <SettingsSection title="Appearance">
+ <SettingsRow
+ label={
+ <span className="flex items-center gap-2">
+ <SunMoon className="size-4 text-muted-foreground" />
+ Theme
+ </span>
}
- />
- </div>
- <p className="text-xs text-muted-foreground">
- When disabled, you&apos;ll confirm before saving bookmarks.
- </p>
- <hr />
- <div className="flex gap-2">
- <span className="my-auto">Server Address:</span>
- {settings.address}
- </div>
- <div className="flex gap-2">
- <span className="my-auto">Logged in as:</span>
- {loggedInMessage}
- </div>
- <div className="flex gap-2">
- <span className="my-auto">Theme:</span>
- <Select value={theme} onValueChange={setTheme}>
- <SelectTrigger className="w-24">
- <SelectValue placeholder="Theme" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="light">Light</SelectItem>
- <SelectItem value="dark">Dark</SelectItem>
- <SelectItem value="system">System</SelectItem>
- </SelectContent>
- </Select>
+ >
+ <div
+ role="group"
+ aria-label="Theme"
+ className="flex items-center gap-0.5 rounded-md bg-muted p-0.5"
+ >
+ {THEME_OPTIONS.map(({ value, icon: Icon, label }) => (
+ <Button
+ key={value}
+ variant="ghost"
+ className={cn(
+ "h-auto rounded px-2 py-1 text-muted-foreground focus:bg-background/60",
+ theme === value &&
+ "bg-background text-foreground shadow-sm hover:bg-background focus:bg-background",
+ )}
+ aria-pressed={theme === value}
+ aria-label={label}
+ title={label}
+ onClick={() => setTheme(value)}
+ >
+ <Icon className="size-3.5" />
+ </Button>
+ ))}
+ </div>
+ </SettingsRow>
+ </SettingsSection>
+ </div>
+ );
+}
+
+function SettingsSection({
+ title,
+ children,
+}: {
+ title: string;
+ children: React.ReactNode;
+}) {
+ return (
+ <section className="flex flex-col gap-2">
+ <h2 className="px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground">
+ {title}
+ </h2>
+ <div className="flex flex-col divide-y rounded-lg border">{children}</div>
+ </section>
+ );
+}
+
+function SettingsRow({
+ label,
+ description,
+ inset,
+ children,
+}: {
+ label: React.ReactNode;
+ description?: string;
+ inset?: boolean;
+ children: React.ReactNode;
+}) {
+ return (
+ <div
+ className={cn(
+ "flex items-center justify-between gap-4 px-3 py-2.5",
+ inset && "bg-muted/40 pl-6",
+ )}
+ >
+ <div className="flex min-w-0 flex-col gap-0.5">
+ <span className="text-sm font-medium">{label}</span>
+ {description && (
+ <span className="text-xs text-muted-foreground">{description}</span>
+ )}
</div>
- <Button onClick={onLogout}>Logout</Button>
+ <div className="shrink-0">{children}</div>
</div>
);
}
diff --git a/apps/browser-extension/src/SavePage.tsx b/apps/browser-extension/src/SavePage.tsx
index 460699b5..425b344e 100644
--- a/apps/browser-extension/src/SavePage.tsx
+++ b/apps/browser-extension/src/SavePage.tsx
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { useMutation } from "@tanstack/react-query";
+import { BookmarkPlus, Link2 } from "lucide-react";
import { Navigate } from "react-router-dom";
import {
@@ -9,10 +10,11 @@ import {
} from "@karakeep/shared/types/bookmarks";
import { NEW_BOOKMARK_REQUEST_KEY_NAME } from "./background/protocol";
+import { ErrorCallout } from "./components/ErrorCallout";
+import { StatusMessage } from "./components/StatusMessage";
import { Button } from "./components/ui/button";
import { Input } from "./components/ui/input";
import { Textarea } from "./components/ui/textarea";
-import Spinner from "./Spinner";
import { hasHostPermission } from "./utils/permissions";
import usePluginSettings from "./utils/settings";
import {
@@ -45,7 +47,7 @@ export default function SavePage() {
} = useMutation(
api.bookmarks.createBookmark.mutationOptions({
onError: (e) => {
- setError("Something went wrong: " + e.message);
+ setError(e.message);
},
onSuccess: async () => {
// After successful creation, update badge cache and notify background
@@ -90,15 +92,13 @@ export default function SavePage() {
await getNewBookmarkRequestFromBackgroundScriptIfAny();
if (!newBookmarkRequest) {
if (!currentTab?.url) {
- setError("Current tab has no URL to bookmark.");
+ setError("This tab doesn't have a link to save.");
setHasCheckedRequest(true);
return;
}
if (!isHttpUrl(currentTab.url)) {
- setError(
- "Cannot bookmark this type of URL. Only HTTP/HTTPS URLs are supported.",
- );
+ setError("Only web pages (http:// and https:// links) can be saved.");
setHasCheckedRequest(true);
return;
}
@@ -188,45 +188,53 @@ export default function SavePage() {
};
if (error) {
- return <div className="text-red-500">{error}</div>;
+ return <ErrorCallout title="Couldn't save this page">{error}</ErrorCallout>;
}
+ const pendingLabel =
+ pendingBookmark?.type === BookmarkTypes.LINK
+ ? pendingBookmark.url
+ : pendingBookmark?.type === BookmarkTypes.TEXT
+ ? pendingBookmark.text
+ : pendingBookmark?.fileName;
+
if (isCapturing) {
- return (
- <div className="flex justify-between text-lg">
- <span>Capturing Page </span>
- <Spinner />
- </div>
- );
+ return <StatusMessage label="Capturing page…" detail={pendingLabel} />;
}
switch (status) {
case "error": {
- return <div className="text-red-500">{error}</div>;
+ return (
+ <ErrorCallout title="Couldn't save this page">{error}</ErrorCallout>
+ );
}
case "success": {
return <Navigate to={`/bookmark/${data.id}`} />;
}
case "pending": {
return (
- <div className="flex justify-between text-lg">
- <span>Saving Bookmark </span>
- <Spinner />
- </div>
+ <StatusMessage label="Saving to Karakeep…" detail={pendingLabel} />
);
}
case "idle": {
// Show confirmation UI when autoSave is disabled
if (!settings.autoSave && pendingBookmark && hasCheckedRequest) {
return (
- <div className="flex flex-col gap-3">
- <p className="text-lg font-medium">Save Bookmark?</p>
+ <form
+ className="flex flex-col gap-4"
+ onSubmit={(e) => {
+ e.preventDefault();
+ handleManualSave();
+ }}
+ >
+ <h2 className="text-base font-semibold">Save to Karakeep</h2>
{pendingBookmark.type === BookmarkTypes.LINK && (
- <div className="flex flex-col gap-2">
- <label className="text-xs font-medium text-muted-foreground">
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="bookmark-title" className="text-sm font-medium">
Title
</label>
<Input
+ id="bookmark-title"
value={pendingBookmark.title ?? ""}
onChange={(e) =>
setPendingBookmark((prev) =>
@@ -235,24 +243,27 @@ export default function SavePage() {
}
placeholder="Untitled"
/>
- <p className="truncate text-xs text-muted-foreground">
- {pendingBookmark.url}
+ <p className="flex items-center gap-1.5 text-xs text-muted-foreground">
+ <Link2 className="size-3.5 shrink-0" />
+ <span className="truncate">{pendingBookmark.url}</span>
</p>
</div>
)}
{pendingBookmark.type === BookmarkTypes.TEXT && (
- <p className="text-xs text-muted-foreground">
- {pendingBookmark.text.length > 150
- ? `${pendingBookmark.text.substring(0, 150)}...`
- : pendingBookmark.text}
- </p>
+ <div className="flex flex-col gap-1.5">
+ <span className="text-sm font-medium">Text</span>
+ <p className="line-clamp-4 whitespace-pre-wrap rounded-md border bg-muted/50 px-3 py-2 text-sm text-muted-foreground">
+ {pendingBookmark.text}
+ </p>
+ </div>
)}
{pendingBookmark.type === BookmarkTypes.ASSET && (
- <div className="flex flex-col gap-2">
- <label className="text-xs font-medium text-muted-foreground">
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="bookmark-title" className="text-sm font-medium">
Title
</label>
<Input
+ id="bookmark-title"
value={pendingBookmark.title ?? ""}
onChange={(e) =>
setPendingBookmark((prev) =>
@@ -263,32 +274,34 @@ export default function SavePage() {
/>
</div>
)}
- <div className="flex flex-col gap-2">
- <label className="text-xs font-medium text-muted-foreground">
- Notes
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="bookmark-note" className="text-sm font-medium">
+ Note{" "}
+ <span className="font-normal text-muted-foreground">
+ (optional)
+ </span>
</label>
<Textarea
+ id="bookmark-note"
value={pendingBookmark.note ?? ""}
onChange={(e) =>
setPendingBookmark((prev) =>
prev ? { ...prev, note: e.target.value } : prev,
)
}
- placeholder="Add notes..."
+ placeholder="Why are you saving this?"
className="h-20 resize-none"
/>
</div>
- <Button onClick={handleManualSave} className="w-full">
- Save Bookmark
+ <Button type="submit" className="w-full gap-2">
+ <BookmarkPlus className="size-4" />
+ Save bookmark
</Button>
- </div>
+ </form>
);
}
return (
- <div className="flex justify-between text-lg">
- <span>Saving Bookmark </span>
- <Spinner />
- </div>
+ <StatusMessage label="Saving to Karakeep…" detail={pendingLabel} />
);
}
}
diff --git a/apps/browser-extension/src/ServerAddressPage.tsx b/apps/browser-extension/src/ServerAddressPage.tsx
new file mode 100644
index 00000000..64837d82
--- /dev/null
+++ b/apps/browser-extension/src/ServerAddressPage.tsx
@@ -0,0 +1,221 @@
+import { useEffect, useState } from "react";
+import { Plus, Trash2 } from "lucide-react";
+import { useNavigate } from "react-router-dom";
+
+import { ErrorCallout } from "./components/ErrorCallout";
+import { PopupHeader } from "./components/PopupHeader";
+import { Button } from "./components/ui/button";
+import { Input } from "./components/ui/input";
+import usePluginSettings from "./utils/settings";
+import { isHttpUrl } from "./utils/url";
+
+export default function ServerAddressPage() {
+ const navigate = useNavigate();
+ const { settings, setSettings } = usePluginSettings();
+
+ const [error, setError] = useState("");
+ const [serverAddress, setServerAddress] = useState(settings.address);
+
+ useEffect(() => {
+ setServerAddress(settings.address);
+ }, [settings.address]);
+
+ // Convert headers object to array of entries for easier manipulation
+ const [headers, setHeaders] = useState<{ key: string; value: string }[]>([]);
+ const [newHeaderKey, setNewHeaderKey] = useState("");
+ const [newHeaderValue, setNewHeaderValue] = useState("");
+
+ // Update headers when settings change (e.g., when loaded from storage)
+ useEffect(() => {
+ setHeaders(
+ Object.entries(settings.customHeaders || {}).map(([key, value]) => ({
+ key,
+ value,
+ })),
+ );
+ }, [settings.customHeaders]);
+
+ const handleAddHeader = () => {
+ if (!newHeaderKey.trim() || !newHeaderValue.trim()) {
+ return;
+ }
+
+ // Check if header already exists
+ const existingIndex = headers.findIndex((h) => h.key === newHeaderKey);
+ if (existingIndex >= 0) {
+ // Update existing header
+ const updatedHeaders = [...headers];
+ updatedHeaders[existingIndex].value = newHeaderValue;
+ setHeaders(updatedHeaders);
+ } else {
+ // Add new header
+ setHeaders([...headers, { key: newHeaderKey, value: newHeaderValue }]);
+ }
+
+ setNewHeaderKey("");
+ setNewHeaderValue("");
+ };
+
+ const handleRemoveHeader = (index: number) => {
+ setHeaders(headers.filter((_, i) => i !== index));
+ };
+
+ const handleSave = () => {
+ const address = serverAddress.trim();
+ if (address == "") {
+ setError("Server address is required");
+ return;
+ }
+
+ if (!isHttpUrl(address)) {
+ setError("Server address must start with http:// or https://");
+ return;
+ }
+
+ // Convert array back to object
+ const headersObject = headers.reduce(
+ (acc, { key, value }) => {
+ if (key.trim() && value.trim()) {
+ acc[key] = value;
+ }
+ return acc;
+ },
+ {} as Record<string, string>,
+ );
+
+ setSettings((s) => ({
+ ...s,
+ address: address.replace(/\/$/, ""),
+ customHeaders: headersObject,
+ }));
+ navigate(-1);
+ };
+
+ const handleCancel = () => {
+ navigate(-1);
+ };
+
+ return (
+ <div className="flex flex-col gap-5">
+ <PopupHeader title="Server" onBack={handleCancel} />
+
+ {error && <ErrorCallout>{error}</ErrorCallout>}
+
+ <section className="flex flex-col gap-1.5">
+ <label htmlFor="address" className="text-sm font-medium">
+ Server address
+ </label>
+ <Input
+ id="address"
+ name="address"
+ value={serverAddress}
+ placeholder="https://cloud.karakeep.app"
+ autoComplete="url"
+ autoFocus
+ onChange={(e) => {
+ setServerAddress(e.target.value);
+ setError("");
+ }}
+ />
+ <p className="text-xs text-muted-foreground">
+ Use https://cloud.karakeep.app for Karakeep Cloud, or the address of
+ your self-hosted instance.
+ </p>
+ </section>
+
+ <section className="flex flex-col gap-2">
+ <div className="flex flex-col gap-0.5">
+ <h2 className="text-sm font-medium">
+ Custom headers
+ {headers.length > 0 && (
+ <span className="font-normal text-muted-foreground">
+ {" "}
+ ({headers.length})
+ </span>
+ )}
+ </h2>
+ <p className="text-xs text-muted-foreground">
+ Sent with every request. Useful behind an auth proxy such as
+ Cloudflare Access.
+ </p>
+ </div>
+
+ {headers.length > 0 && (
+ <div className="flex max-h-48 flex-col divide-y overflow-y-auto rounded-lg border">
+ {headers.map((header, index) => (
+ <div
+ key={index}
+ className="flex items-center gap-2 py-2 pl-3 pr-1.5"
+ >
+ <div className="flex min-w-0 flex-1 flex-col">
+ <p className="truncate font-mono text-xs font-semibold">
+ {header.key}
+ </p>
+ <p className="truncate font-mono text-xs text-muted-foreground">
+ {header.value}
+ </p>
+ </div>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => handleRemoveHeader(index)}
+ className="size-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
+ aria-label={`Remove ${header.key}`}
+ title="Remove header"
+ >
+ <Trash2 className="size-4" />
+ </Button>
+ </div>
+ ))}
+ </div>
+ )}
+
+ <form
+ className="flex gap-2"
+ onSubmit={(e) => {
+ e.preventDefault();
+ handleAddHeader();
+ }}
+ >
+ <Input
+ placeholder="Name"
+ aria-label="Header name"
+ value={newHeaderKey}
+ onChange={(e) => setNewHeaderKey(e.target.value)}
+ autoCapitalize="none"
+ className="h-9 min-w-0 font-mono text-xs"
+ />
+ <Input
+ placeholder="Value"
+ aria-label="Header value"
+ value={newHeaderValue}
+ onChange={(e) => setNewHeaderValue(e.target.value)}
+ autoCapitalize="none"
+ className="h-9 min-w-0 font-mono text-xs"
+ />
+ <Button
+ type="submit"
+ variant="secondary"
+ size="icon"
+ disabled={!newHeaderKey.trim() || !newHeaderValue.trim()}
+ className="size-9 shrink-0"
+ aria-label="Add header"
+ title="Add header"
+ >
+ <Plus className="size-4" />
+ </Button>
+ </form>
+ </section>
+
+ {/* Action Buttons */}
+ <div className="-mx-4 -mb-4 flex gap-2 border-t p-4">
+ <Button variant="outline" onClick={handleCancel} className="flex-1">
+ Cancel
+ </Button>
+ <Button onClick={handleSave} className="flex-1">
+ Save
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/browser-extension/src/SignInPage.tsx b/apps/browser-extension/src/SignInPage.tsx
index 8a7229b6..5a27a722 100644
--- a/apps/browser-extension/src/SignInPage.tsx
+++ b/apps/browser-extension/src/SignInPage.tsx
@@ -1,179 +1,203 @@
import { useState } from "react";
import { useMutation } from "@tanstack/react-query";
+import { Server } from "lucide-react";
import { useNavigate } from "react-router-dom";
+import { ErrorCallout } from "./components/ErrorCallout";
import { Button } from "./components/ui/button";
import { Input } from "./components/ui/input";
import Logo from "./Logo";
+import Spinner from "./Spinner";
import usePluginSettings from "./utils/settings";
import { useTRPC } from "./utils/trpc";
-const enum LoginState {
- NONE = "NONE",
- USERNAME_PASSWORD = "USERNAME/PASSWORD",
- API_KEY = "API_KEY",
+const enum LoginType {
+ Password = "PASSWORD",
+ ApiKey = "API_KEY",
+}
+
+const CONNECTION_ERROR_MESSAGE =
+ "Couldn't connect to this Karakeep server. Check the server address and your internet connection, then try again.";
+
+function getLoginErrorMessage(
+ error: { data?: { code?: string } | null; message: string },
+ unauthorizedMessage: string,
+) {
+ if (error.data?.code === "UNAUTHORIZED") {
+ return unauthorizedMessage;
+ }
+
+ // Chrome reports "Failed to fetch", Firefox "NetworkError when attempting
+ // to fetch resource."
+ if (error.message.toLowerCase().includes("fetch")) {
+ return CONNECTION_ERROR_MESSAGE;
+ }
+
+ return error.message;
}
export default function SignInPage() {
const api = useTRPC();
const navigate = useNavigate();
const { settings, setSettings } = usePluginSettings();
+ const [error, setError] = useState<string | undefined>();
+ const [loginType, setLoginType] = useState<LoginType>(LoginType.Password);
- const {
- mutate: login,
- error: usernamePasswordError,
- isPending: userNamePasswordRequestIsPending,
- } = useMutation(
- api.apiKeys.exchange.mutationOptions({
- onSuccess: (resp) => {
- setSettings((s) => ({ ...s, apiKey: resp.key, apiKeyId: resp.id }));
- navigate("/options");
- },
- }),
- );
-
- const {
- mutate: validateApiKey,
- error: apiKeyValidationError,
- isPending: apiKeyValueRequestIsPending,
- } = useMutation(
- api.apiKeys.validate.mutationOptions({
- onSuccess: () => {
- setSettings((s) => ({ ...s, apiKey: apiKeyFormData.apiKey }));
- navigate("/options");
- },
- }),
- );
+ const [formData, setFormData] = useState({ email: "", password: "" });
+ const [apiKey, setApiKey] = useState("");
- const [lastLoginAttemptSource, setLastLoginAttemptSource] =
- useState<LoginState>(LoginState.NONE);
+ const { mutate: login, isPending: userNamePasswordRequestIsPending } =
+ useMutation(
+ api.apiKeys.exchange.mutationOptions({
+ onSuccess: (resp) => {
+ setSettings((s) => ({ ...s, apiKey: resp.key, apiKeyId: resp.id }));
+ navigate("/options");
+ },
+ onError: (e) => {
+ setError(getLoginErrorMessage(e, "Incorrect email or password."));
+ },
+ }),
+ );
- const [formData, setFormData] = useState<{
- email: string;
- password: string;
- }>({
- email: "",
- password: "",
- });
+ const { mutate: validateApiKey, isPending: apiKeyValueRequestIsPending } =
+ useMutation(
+ api.apiKeys.validate.mutationOptions({
+ onSuccess: (_resp, req) => {
+ // Store exactly the key that was validated, not the live input.
+ setSettings((s) => ({ ...s, apiKey: req.apiKey }));
+ navigate("/options");
+ },
+ onError: (e) => {
+ setError(getLoginErrorMessage(e, "That API key isn't valid."));
+ },
+ }),
+ );
- const [apiKeyFormData, setApiKeyFormData] = useState<{
- apiKey: string;
- }>({
- apiKey: "",
- });
-
- const onUserNamePasswordSubmit = (e: React.FormEvent) => {
- e.preventDefault();
- setLastLoginAttemptSource(LoginState.USERNAME_PASSWORD);
- const randStr = (Math.random() + 1).toString(36).substring(5);
- login({ ...formData, keyName: `Browser extension: (${randStr})` });
- };
+ const isPending =
+ userNamePasswordRequestIsPending || apiKeyValueRequestIsPending;
- const onApiKeySubmit = (e: React.FormEvent) => {
+ const onSubmit = (e: React.FormEvent) => {
e.preventDefault();
- setLastLoginAttemptSource(LoginState.API_KEY);
- validateApiKey({ ...apiKeyFormData });
+ setError(undefined);
+ if (loginType === LoginType.Password) {
+ const randStr = (Math.random() + 1).toString(36).substring(5);
+ login({
+ email: formData.email.trim(),
+ password: formData.password,
+ keyName: `Browser extension: (${randStr})`,
+ });
+ } else {
+ validateApiKey({ apiKey: apiKey.trim() });
+ }
};
- let errorMessage = "";
- let loginError;
- switch (lastLoginAttemptSource) {
- case LoginState.USERNAME_PASSWORD:
- loginError = usernamePasswordError;
- break;
- case LoginState.API_KEY:
- loginError = apiKeyValidationError;
- break;
- }
- if (loginError) {
- errorMessage = loginError.message || "Wrong username or password";
- }
-
return (
- <div className="flex flex-col space-y-2">
- <Logo />
- <p className="text-lg">Login</p>
- <p className="text-red-500">{errorMessage}</p>
- <form
- className="flex flex-col gap-y-2"
- onSubmit={onUserNamePasswordSubmit}
- >
- <div className="flex flex-col gap-y-1">
- <label className="my-auto font-bold">Email</label>
- <Input
- value={formData.email}
- onChange={(e) =>
- setFormData((f) => ({ ...f, email: e.target.value }))
- }
- type="text"
- name="email"
- className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
- />
- </div>
- <div className="flex flex-col gap-y-1">
- <label className="my-auto font-bold">Password</label>
- <Input
- value={formData.password}
- onChange={(e) =>
- setFormData((f) => ({
- ...f,
- password: e.target.value,
- }))
- }
- type="password"
- name="password"
- className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
- />
- </div>
- <Button
- type="submit"
- disabled={
- userNamePasswordRequestIsPending || apiKeyValueRequestIsPending
- }
- >
- Login
- </Button>
- </form>
- <div className="flex w-full flex-row items-center gap-3">
- <hr className="flex-1" />
- Or
- <hr className="flex-1" />
+ <div className="flex flex-col gap-6 pb-2 pt-6">
+ <div className="flex justify-center">
+ <Logo className="h-10" />
</div>
- <form className="flex flex-col gap-y-2" onSubmit={onApiKeySubmit}>
- <div className="flex flex-col gap-y-1">
- <label className="my-auto font-bold">API Key</label>
- <Input
- value={apiKeyFormData.apiKey}
- onChange={(e) =>
- setApiKeyFormData((f) => ({ ...f, apiKey: e.target.value }))
- }
- type="text"
- name="apiKey"
- className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
- />
- </div>
- <Button
- type="submit"
- disabled={
- userNamePasswordRequestIsPending || apiKeyValueRequestIsPending
- }
- >
- Login with API key
+ <form className="flex flex-col gap-3" onSubmit={onSubmit}>
+ {loginType === LoginType.Password ? (
+ <>
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="email" className="text-sm font-medium">
+ Email
+ </label>
+ <Input
+ id="email"
+ name="email"
+ type="email"
+ autoComplete="username"
+ placeholder="[email protected]"
+ autoFocus
+ value={formData.email}
+ onChange={(e) =>
+ setFormData((f) => ({ ...f, email: e.target.value }))
+ }
+ />
+ </div>
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="password" className="text-sm font-medium">
+ Password
+ </label>
+ <Input
+ id="password"
+ name="password"
+ type="password"
+ autoComplete="current-password"
+ value={formData.password}
+ onChange={(e) =>
+ setFormData((f) => ({ ...f, password: e.target.value }))
+ }
+ />
+ </div>
+ </>
+ ) : (
+ <div className="flex flex-col gap-1.5">
+ <label htmlFor="apiKey" className="text-sm font-medium">
+ API key
+ </label>
+ <Input
+ id="apiKey"
+ name="apiKey"
+ type="password"
+ autoComplete="off"
+ placeholder="Paste your key"
+ autoFocus
+ value={apiKey}
+ onChange={(e) => setApiKey(e.target.value)}
+ />
+ </div>
+ )}
+
+ {error && <ErrorCallout>{error}</ErrorCallout>}
+
+ <Button type="submit" disabled={isPending} className="mt-1 gap-2">
+ {isPending && <Spinner className="size-4" />}
+ {isPending ? "Signing in…" : "Sign in"}
</Button>
</form>
- <div className="flex justify-center pt-2">
+ <div className="flex flex-col items-center gap-2.5 text-xs text-muted-foreground">
+ <button
+ type="button"
+ onClick={() => navigate("/server")}
+ className="flex max-w-full items-center gap-1.5 rounded-full border px-3 py-1 hover:bg-accent hover:text-foreground"
+ title="Change server"
+ >
+ <Server className="size-3.5 shrink-0" />
+ <span className="truncate">
+ {settings.address.replace(/^https?:\/\//, "")}
+ </span>
+ </button>
<button
type="button"
- onClick={() => navigate("/customheaders")}
- className="text-xs text-muted-foreground underline hover:text-foreground"
+ onClick={() => {
+ setLoginType(
+ loginType === LoginType.Password
+ ? LoginType.ApiKey
+ : LoginType.Password,
+ );
+ setError(undefined);
+ }}
+ className="underline-offset-4 hover:text-foreground hover:underline"
>
- Configure Custom Headers
- {settings.customHeaders &&
- Object.keys(settings.customHeaders).length > 0 &&
- ` (${Object.keys(settings.customHeaders).length})`}
+ {loginType === LoginType.Password
+ ? "Use an API key instead"
+ : "Use your password instead"}
</button>
+ <span>
+ New to Karakeep?{" "}
+ <a
+ href={`${settings.address}/signup`}
+ target="_blank"
+ rel="noreferrer"
+ className="font-medium text-foreground underline-offset-4 hover:underline"
+ >
+ Create account
+ </a>
+ </span>
</div>
</div>
);
diff --git a/apps/browser-extension/src/Spinner.tsx b/apps/browser-extension/src/Spinner.tsx
index 9fd8839b..c1b4f99d 100644
--- a/apps/browser-extension/src/Spinner.tsx
+++ b/apps/browser-extension/src/Spinner.tsx
@@ -1,4 +1,6 @@
-export default function Spinner() {
+import { cn } from "./utils/css";
+
+export default function Spinner({ className }: { className?: string }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
@@ -10,7 +12,7 @@ export default function Spinner() {
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
- className="animate-spin"
+ className={cn("animate-spin", className)}
>
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
</svg>
diff --git a/apps/browser-extension/src/components/BookmarkLists.tsx b/apps/browser-extension/src/components/BookmarkLists.tsx
index 8debef5c..d405ff8f 100644
--- a/apps/browser-extension/src/components/BookmarkLists.tsx
+++ b/apps/browser-extension/src/components/BookmarkLists.tsx
@@ -1,13 +1,47 @@
import { useQuery } from "@tanstack/react-query";
import { X } from "lucide-react";
+import type { ZBookmarkList } from "@karakeep/shared/types/lists";
import {
useBookmarkLists,
useRemoveBookmarkFromList,
} from "@karakeep/shared-react/hooks/lists";
import { useTRPC } from "../utils/trpc";
-import { Button } from "./ui/button";
+
+export function byListPathName(a: ZBookmarkList[], b: ZBookmarkList[]) {
+ const commonPathLength = Math.min(a.length, b.length);
+
+ for (let index = 0; index < commonPathLength; index++) {
+ const comparison = a[index].name.localeCompare(b[index].name);
+ if (comparison !== 0) return comparison;
+ }
+
+ return a.length - b.length;
+}
+
+export function ListPathLabel({ path }: { path: ZBookmarkList[] }) {
+ const list = path[path.length - 1];
+ // The full path lives in the tooltip; the direct parent is what tells
+ // similarly named lists apart.
+ const parent = path.length > 1 ? path[path.length - 2] : undefined;
+ return (
+ <span
+ className="flex min-w-0 flex-1 items-center gap-2"
+ title={path.map((l) => l.name).join(" / ")}
+ >
+ <span className="shrink-0 text-base leading-none">{list.icon}</span>
+ <span className="flex min-w-0 flex-col">
+ <span className="truncate">{list.name}</span>
+ {parent && (
+ <span className="truncate text-xs text-muted-foreground">
+ in {parent.name}
+ </span>
+ )}
+ </span>
+ </span>
+ );
+}
export default function BookmarkLists({ bookmarkId }: { bookmarkId: string }) {
const api = useTRPC();
@@ -22,28 +56,32 @@ export default function BookmarkLists({ bookmarkId }: { bookmarkId: string }) {
return null;
}
+ const paths = lists.lists
+ .map((l) => allLists.getPathById(l.id) ?? [l])
+ .sort(byListPathName);
+
return (
- <ul className="flex flex-col gap-1">
- {lists.lists.map((l) => (
- <li
- key={l.id}
- className="flex items-center justify-between rounded border border-border bg-background p-2 text-sm text-foreground"
- >
- <span>
- {allLists
- .getPathById(l.id)!
- .map((l) => `${l.icon} ${l.name}`)
- .join(" / ")}
- </span>
- <Button
- variant="ghost"
- size="sm"
- onClick={() => deleteFromList({ bookmarkId, listId: l.id })}
+ <>
+ {paths.map((path) => {
+ const list = path[path.length - 1];
+ return (
+ <div
+ key={list.id}
+ className="flex h-11 items-center gap-2 pl-3 pr-1 text-sm"
>
- <X className="size-4" />
- </Button>
- </li>
- ))}
- </ul>
+ <ListPathLabel path={path} />
+ <button
+ type="button"
+ onClick={() => deleteFromList({ bookmarkId, listId: list.id })}
+ className="shrink-0 rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground"
+ aria-label={`Remove from ${list.name}`}
+ title="Remove from list"
+ >
+ <X className="size-3.5" />
+ </button>
+ </div>
+ );
+ })}
+ </>
);
}
diff --git a/apps/browser-extension/src/components/ErrorCallout.tsx b/apps/browser-extension/src/components/ErrorCallout.tsx
new file mode 100644
index 00000000..be9e1fbd
--- /dev/null
+++ b/apps/browser-extension/src/components/ErrorCallout.tsx
@@ -0,0 +1,29 @@
+import { CircleAlert } from "lucide-react";
+
+import { cn } from "../utils/css";
+
+export function ErrorCallout({
+ title,
+ children,
+ className,
+}: {
+ title?: string;
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div
+ role="alert"
+ className={cn(
+ "flex gap-2.5 rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-sm",
+ className,
+ )}
+ >
+ <CircleAlert className="mt-0.5 size-4 shrink-0 text-destructive" />
+ <div className="flex min-w-0 flex-col gap-0.5">
+ {title && <p className="font-medium text-destructive">{title}</p>}
+ <div className="break-words text-muted-foreground">{children}</div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/browser-extension/src/components/ListsSelector.tsx b/apps/browser-extension/src/components/ListsSelector.tsx
index b27e866a..e548664c 100644
--- a/apps/browser-extension/src/components/ListsSelector.tsx
+++ b/apps/browser-extension/src/components/ListsSelector.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import { useQuery } from "@tanstack/react-query";
import { useSet } from "@uidotdev/usehooks";
-import { Check, ChevronsUpDown } from "lucide-react";
+import { Check, Plus } from "lucide-react";
import {
useAddBookmarkToList,
@@ -11,6 +11,7 @@ import {
import { cn } from "../utils/css";
import { useTRPC } from "../utils/trpc";
+import { byListPathName, ListPathLabel } from "./BookmarkLists";
import { Button } from "./ui/button";
import {
Command,
@@ -63,23 +64,30 @@ export function ListsSelector({ bookmarkId }: { bookmarkId: string }) {
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
- variant="outline"
+ variant="ghost"
role="combobox"
aria-expanded={open}
- className="justify-between"
+ className="h-11 w-full justify-start gap-2 rounded-none px-3 font-normal text-muted-foreground hover:text-foreground"
>
- Add to List...
- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ <Plus className="size-4" />
+ Add to list
</Button>
</PopoverTrigger>
- <DynamicPopoverContent className="w-[320px] p-0">
+ <DynamicPopoverContent
+ align="start"
+ collisionPadding={16}
+ className="w-[--radix-popover-trigger-width] p-0"
+ >
<Command>
- <CommandInput placeholder="Search Lists ..." />
+ <CommandInput placeholder="Search lists…" />
<CommandList>
- <CommandEmpty>You don&apos;t have any lists.</CommandEmpty>
+ <CommandEmpty>No lists found.</CommandEmpty>
<CommandGroup>
{allLists?.allPaths
.filter((path) => path[path.length - 1].userRole !== "viewer")
+ // Smart lists are query-based; bookmarks can't be added by hand.
+ .filter((path) => path[path.length - 1].type !== "smart")
+ .sort(byListPathName)
.map((path) => {
const lastItem = path[path.length - 1];
@@ -93,15 +101,13 @@ export function ListsSelector({ bookmarkId }: { bookmarkId: string }) {
>
<Check
className={cn(
- "mr-2 size-4",
+ "mr-2 size-4 shrink-0",
existingListIds.has(lastItem.id)
? "opacity-100"
: "opacity-0",
)}
/>
- {path
- .map((item) => `${item.icon} ${item.name}`)
- .join(" / ")}
+ <ListPathLabel path={path} />
</CommandItem>
);
})}
diff --git a/apps/browser-extension/src/components/NoteEditor.tsx b/apps/browser-extension/src/components/NoteEditor.tsx
index fb94f83b..602f5448 100644
--- a/apps/browser-extension/src/components/NoteEditor.tsx
+++ b/apps/browser-extension/src/components/NoteEditor.tsx
@@ -1,11 +1,12 @@
import { useEffect, useState } from "react";
-import { Check, Save } from "lucide-react";
+import { Check } from "lucide-react";
import {
useAutoRefreshingBookmarkQuery,
useUpdateBookmark,
} from "@karakeep/shared-react/hooks/bookmarks";
+import Spinner from "../Spinner";
import { Button } from "./ui/button";
import { Textarea } from "./ui/textarea";
@@ -52,55 +53,59 @@ export function NoteEditor({ bookmarkId }: { bookmarkId: string }) {
return null;
}
+ const showStatusRow = isSaving || !!error || hasUnsavedChanges;
+
return (
<div className="flex flex-col gap-2">
<Textarea
autoFocus
- className="h-32 w-full overflow-auto rounded bg-background p-2 text-sm text-gray-400 dark:text-gray-300"
+ className="h-24 w-full resize-none overflow-auto bg-background text-sm"
value={noteValue}
- placeholder="Write some notes ..."
+ placeholder="Add a note…"
onChange={(e) => {
setNoteValue(e.currentTarget.value);
setHasUnsavedChanges(e.currentTarget.value !== bookmark.note);
}}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
+ e.preventDefault();
+ handleSave();
+ }
+ }}
/>
- <div className="flex items-center justify-between gap-2">
- <div className="flex-1">
- {isSaving && <p className="text-xs text-gray-500">Saving note...</p>}
- {error && <p className="text-xs text-red-500">{error}</p>}
- {!isSaving && !error && hasUnsavedChanges && (
- <p className="text-xs text-amber-600 dark:text-amber-500">
- Unsaved changes
- </p>
- )}
- </div>
- {hasUnsavedChanges && (
+ {!showStatusRow && noteValue && (
+ <p className="flex items-center gap-1 text-xs text-muted-foreground">
+ <Check className="size-3.5 text-green-600 dark:text-green-500" />
+ Saved
+ </p>
+ )}
+ {showStatusRow && (
+ <div className="flex items-center justify-between gap-2">
+ <div className="min-w-0 flex-1 text-xs">
+ {error ? (
+ <p className="text-destructive">{error}</p>
+ ) : (
+ hasUnsavedChanges &&
+ !isSaving && (
+ <p className="text-muted-foreground">Unsaved changes</p>
+ )
+ )}
+ </div>
<Button
onClick={handleSave}
disabled={isSaving}
size="sm"
- className="gap-1.5"
+ className="h-7 gap-1.5 px-2.5 text-xs"
>
{isSaving ? (
- <>
- <Save className="h-3.5 w-3.5 animate-pulse" />
- Saving...
- </>
+ <Spinner className="size-3.5" />
) : (
- <>
- <Save className="h-3.5 w-3.5" />
- Save Note
- </>
+ <Check className="size-3.5" />
)}
+ {isSaving ? "Saving…" : "Save note"}
</Button>
- )}
- {!hasUnsavedChanges && !isSaving && noteValue && (
- <div className="flex items-center gap-1 text-xs text-green-600 dark:text-green-500">
- <Check className="h-3.5 w-3.5" />
- Saved
- </div>
- )}
- </div>
+ </div>
+ )}
</div>
);
}
diff --git a/apps/browser-extension/src/components/PopupHeader.tsx b/apps/browser-extension/src/components/PopupHeader.tsx
new file mode 100644
index 00000000..dc5d5b40
--- /dev/null
+++ b/apps/browser-extension/src/components/PopupHeader.tsx
@@ -0,0 +1,53 @@
+import { ArrowLeft } from "lucide-react";
+
+import Logo from "../Logo";
+import { Button } from "./ui/button";
+
+export function PopupHeader({
+ title,
+ onBack,
+ children,
+}: {
+ title?: string;
+ onBack?: () => void;
+ children?: React.ReactNode;
+}) {
+ return (
+ <div className="-mx-4 -mt-4 flex h-14 items-center gap-1 border-b px-3">
+ {onBack && (
+ <Button
+ variant="ghost"
+ size="icon"
+ className="size-8 text-muted-foreground"
+ onClick={onBack}
+ aria-label="Back"
+ title="Back"
+ >
+ <ArrowLeft className="size-4" />
+ </Button>
+ )}
+ {title ? (
+ <h1 className="px-1 text-base font-semibold">{title}</h1>
+ ) : (
+ <Logo className="ml-1 h-6" />
+ )}
+ <div className="ml-auto flex items-center gap-0.5">{children}</div>
+ </div>
+ );
+}
+
+export function HeaderIconButton({
+ label,
+ ...props
+}: React.ComponentProps<typeof Button> & { label: string }) {
+ return (
+ <Button
+ variant="ghost"
+ size="icon"
+ className="size-8 text-muted-foreground hover:text-foreground"
+ aria-label={label}
+ title={label}
+ {...props}
+ />
+ );
+}
diff --git a/apps/browser-extension/src/components/StatusMessage.tsx b/apps/browser-extension/src/components/StatusMessage.tsx
new file mode 100644
index 00000000..dfe2a0b6
--- /dev/null
+++ b/apps/browser-extension/src/components/StatusMessage.tsx
@@ -0,0 +1,23 @@
+import Spinner from "../Spinner";
+
+export function StatusMessage({
+ label,
+ detail,
+}: {
+ label: string;
+ detail?: string;
+}) {
+ return (
+ <div className="flex flex-col items-center gap-3 py-8 text-center">
+ <Spinner className="size-6 text-muted-foreground" />
+ <div className="flex w-full flex-col gap-1">
+ <p className="text-sm font-medium">{label}</p>
+ {detail && (
+ <p className="truncate px-4 text-xs text-muted-foreground">
+ {detail}
+ </p>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/browser-extension/src/components/TagList.tsx b/apps/browser-extension/src/components/TagList.tsx
index 77a3ea87..e8b78a84 100644
--- a/apps/browser-extension/src/components/TagList.tsx
+++ b/apps/browser-extension/src/components/TagList.tsx
@@ -1,6 +1,9 @@
+import { Sparkles } from "lucide-react";
+
import { useAutoRefreshingBookmarkQuery } from "@karakeep/shared-react/hooks/bookmarks";
import { isBookmarkStillTagging } from "@karakeep/shared/utils/bookmarkUtils";
+import Spinner from "../Spinner";
import { Badge } from "./ui/badge";
export default function TagList({ bookmarkId }: { bookmarkId: string }) {
@@ -10,23 +13,33 @@ export default function TagList({ bookmarkId }: { bookmarkId: string }) {
}
return (
- <div className="flex flex-wrap gap-1">
- {bookmark.tags.length === 0 && !isBookmarkStillTagging(bookmark) && (
- <Badge variant="secondary">No tags</Badge>
+ <>
+ {[...bookmark.tags].map((tag) =>
+ tag.attachedBy === "ai" ? (
+ <Badge
+ key={tag.id}
+ variant="outline"
+ className="h-7 gap-1 border-purple-200 bg-purple-50 font-medium text-purple-700 dark:border-purple-500/30 dark:bg-purple-500/10 dark:text-purple-300"
+ title="Added by AI"
+ >
+ <Sparkles className="size-3" />
+ {tag.name}
+ </Badge>
+ ) : (
+ <Badge key={tag.id} variant="secondary" className="h-7 font-medium">
+ {tag.name}
+ </Badge>
+ ),
)}
- {[...bookmark.tags].map((tag) => (
+ {isBookmarkStillTagging(bookmark) && (
<Badge
- key={tag.id}
- className={
- tag.attachedBy === "ai" ? "bg-purple-500 text-white" : undefined
- }
+ variant="outline"
+ className="h-7 gap-1.5 font-normal text-muted-foreground"
>
- {tag.name}
+ <Spinner className="size-3" />
+ AI tagging…
</Badge>
- ))}
- {isBookmarkStillTagging(bookmark) && (
- <Badge variant="secondary">AI tags loading...</Badge>
)}
- </div>
+ </>
);
}
diff --git a/apps/browser-extension/src/components/TagsSelector.tsx b/apps/browser-extension/src/components/TagsSelector.tsx
index 30cdcafc..378972ca 100644
--- a/apps/browser-extension/src/components/TagsSelector.tsx
+++ b/apps/browser-extension/src/components/TagsSelector.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import { useQuery } from "@tanstack/react-query";
import { useSet } from "@uidotdev/usehooks";
-import { Check, ChevronsUpDown, Plus } from "lucide-react";
+import { Check, Plus } from "lucide-react";
import {
useAutoRefreshingBookmarkQuery,
@@ -13,6 +13,7 @@ import { useTRPC } from "../utils/trpc";
import { Button } from "./ui/button";
import {
Command,
+ CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
@@ -60,37 +61,47 @@ export function TagsSelector({ bookmarkId }: { bookmarkId: string }) {
<PopoverTrigger asChild>
<Button
variant="outline"
+ size="sm"
role="combobox"
aria-expanded={open}
- className="justify-between"
+ className="h-7 gap-1 rounded-full border-dashed px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground"
>
- Add Tags...
- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ <Plus className="size-3.5" />
+ Add tag
</Button>
</PopoverTrigger>
- <DynamicPopoverContent className="w-[320px] p-0">
+ <DynamicPopoverContent
+ align="start"
+ collisionPadding={16}
+ className="w-[320px] p-0"
+ >
<Command>
<CommandInput
value={input}
onValueChange={setInput}
- placeholder="Search Tags ..."
+ placeholder="Search or create a tag…"
/>
<CommandList>
- <CommandGroup>
- <CommandItem
- onSelect={() =>
- mutate({
- bookmarkId,
- attach: [{ tagName: input }],
- detach: [],
- })
- }
- >
- <Plus className="mr-2 size-4" />
- Create &quot;{input}&quot; ...
- </CommandItem>
- </CommandGroup>
- <CommandSeparator />
+ <CommandEmpty>Type a name to create a tag.</CommandEmpty>
+ {input.trim() && (
+ <>
+ <CommandGroup>
+ <CommandItem
+ onSelect={() =>
+ mutate({
+ bookmarkId,
+ attach: [{ tagName: input.trim() }],
+ detach: [],
+ })
+ }
+ >
+ <Plus className="mr-2 size-4" />
+ Create &quot;{input.trim()}&quot;
+ </CommandItem>
+ </CommandGroup>
+ <CommandSeparator />
+ </>
+ )}
<CommandGroup>
{allTags?.tags
.sort((a, b) => a.name.localeCompare(b.name))
diff --git a/apps/browser-extension/src/components/TitleEditor.tsx b/apps/browser-extension/src/components/TitleEditor.tsx
new file mode 100644
index 00000000..8184a24c
--- /dev/null
+++ b/apps/browser-extension/src/components/TitleEditor.tsx
@@ -0,0 +1,115 @@
+import { useState } from "react";
+import { useQueryClient } from "@tanstack/react-query";
+import { Check } from "lucide-react";
+
+import type { ZBookmark } from "@karakeep/shared/types/bookmarks";
+import {
+ useAutoRefreshingBookmarkQuery,
+ useUpdateBookmark,
+} from "@karakeep/shared-react/hooks/bookmarks";
+import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";
+import { isBookmarkStillCrawling } from "@karakeep/shared/utils/bookmarkUtils";
+
+import Spinner from "../Spinner";
+import { useTRPC } from "../utils/trpc";
+import { Button } from "./ui/button";
+import { Input } from "./ui/input";
+
+// The title shown when the user hasn't set one. The crawler fills it in, so it
+// can change while the popup is open; it's only ever used as the placeholder.
+function getFallbackTitle(bookmark: ZBookmark) {
+ switch (bookmark.content.type) {
+ case BookmarkTypes.LINK:
+ return bookmark.content.title ?? null;
+ case BookmarkTypes.ASSET:
+ return bookmark.content.fileName ?? null;
+ default:
+ return null;
+ }
+}
+
+export function TitleEditor({ bookmarkId }: { bookmarkId: string }) {
+ const api = useTRPC();
+ const queryClient = useQueryClient();
+ const { data: bookmark } = useAutoRefreshingBookmarkQuery({ bookmarkId });
+ // The user's in-progress edit; null when not editing. While editing, the
+ // field shows the draft, so refreshes (e.g. the crawl finishing) can't
+ // overwrite what's being typed.
+ const [draft, setDraft] = useState<string | null>(null);
+
+ const { mutate, isPending, error } = useUpdateBookmark({
+ // Stay pending until the refreshed bookmark is in, so the field never
+ // briefly shows the pre-save title.
+ onSuccess: () =>
+ queryClient
+ .invalidateQueries(
+ api.bookmarks.getBookmark.queryFilter({ bookmarkId }),
+ )
+ .then(() => setDraft(null)),
+ });
+
+ if (!bookmark) {
+ return null;
+ }
+
+ // Only the user's own title is edited. An empty field clears it, so the
+ // crawled title shows again.
+ const newTitle = draft?.trim() || null;
+ const hasChanges = draft !== null && newTitle !== (bookmark.title ?? null);
+
+ const save = () => {
+ if (hasChanges && !isPending) {
+ mutate({ bookmarkId, title: newTitle });
+ }
+ };
+
+ return (
+ <div className="flex flex-col gap-2">
+ <Input
+ value={draft ?? bookmark.title ?? ""}
+ placeholder={
+ getFallbackTitle(bookmark) ??
+ (isBookmarkStillCrawling(bookmark) ? "Fetching title…" : "Untitled")
+ }
+ aria-label="Title"
+ disabled={isPending}
+ onChange={(e) => setDraft(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ save();
+ } else if (e.key === "Escape" && draft !== null) {
+ e.preventDefault();
+ setDraft(null);
+ }
+ }}
+ />
+ {(hasChanges || isPending) && (
+ <div className="flex items-center justify-between gap-2">
+ <p className="min-w-0 flex-1 text-xs">
+ {error ? (
+ <span className="text-destructive">
+ {error.message || "Failed to save title"}
+ </span>
+ ) : (
+ <span className="text-muted-foreground">Unsaved changes</span>
+ )}
+ </p>
+ <Button
+ onClick={save}
+ disabled={isPending || !hasChanges}
+ size="sm"
+ className="h-7 gap-1.5 px-2.5 text-xs"
+ >
+ {isPending ? (
+ <Spinner className="size-3.5" />
+ ) : (
+ <Check className="size-3.5" />
+ )}
+ {isPending ? "Saving…" : "Save title"}
+ </Button>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/apps/browser-extension/src/main.tsx b/apps/browser-extension/src/main.tsx
index 123e505e..8f96e341 100644
--- a/apps/browser-extension/src/main.tsx
+++ b/apps/browser-extension/src/main.tsx
@@ -6,11 +6,10 @@ import { HashRouter, Route, Routes } from "react-router-dom";
import BookmarkDeletedPage from "./BookmarkDeletedPage.tsx";
import BookmarkSavedPage from "./BookmarkSavedPage.tsx";
-import CustomHeadersPage from "./CustomHeadersPage.tsx";
import Layout from "./Layout.tsx";
-import NotConfiguredPage from "./NotConfiguredPage.tsx";
import OptionsPage from "./OptionsPage.tsx";
import SavePage from "./SavePage.tsx";
+import ServerAddressPage from "./ServerAddressPage.tsx";
import SignInPage from "./SignInPage.tsx";
import { Providers } from "./utils/providers.tsx";
@@ -31,10 +30,9 @@ function App() {
element={<BookmarkDeletedPage />}
/>
</Route>
- <Route path="/notconfigured" element={<NotConfiguredPage />} />
<Route path="/options" element={<OptionsPage />} />
<Route path="/signin" element={<SignInPage />} />
- <Route path="/customheaders" element={<CustomHeadersPage />} />
+ <Route path="/server" element={<ServerAddressPage />} />
</Routes>
</HashRouter>
</Providers>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0e87aa7f..4e3987d9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -132,8 +132,8 @@ importers:
version: 4.3.6
devDependencies:
'@crxjs/vite-plugin':
- specifier: 2.7.1
+ specifier: 3.0.0
'@karakeep/tailwind-config':
specifier: workspace:^0.1.0
version: link:../../tooling/tailwind
@@ -3303,8 +3303,8 @@ packages:
peerDependencies:
commander: ~12.1.0
- '@crxjs/[email protected]':
- resolution: {integrity: sha512-mn77Lc1ilIvbO7ZqijjNy+AnRgc8srkfHOtV6HrGrYZgRe8YI3aIcSjHJCU5Kq75SejEZGrdAoHdn3gBGeKpEA==}
+ '@crxjs/[email protected]':
+ resolution: {integrity: sha512-86InOwnuCC6WPAC6/fsZYAzrmxbWn4qLtrchA6iApJ+CoWugHbyWJlsav1ZH2quw+Laq+1T6LBHMjYwxEVtyEQ==}
peerDependencies:
vite: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
@@ -10742,6 +10742,10 @@ packages:
resolution: {integrity: sha512-EQsFzMUJkCKGr1ePqlYADkIUmHW1s3ZXr5Yqy6wbGrfUCphpl2maM/kyOIRA2HpP3AaFQTZXD4ldjek+nccddA==}
engines: {node: '>=14.14'}
+ resolution: {integrity: sha512-KYAb4c9BJQI6QqGKthV68OHe0badztdXJWKo0WtBA9IuCFPTKvE5ZdUBglP833aMjhaSPNO4A5j/EkzZtGlKjA==}
+ engines: {node: '>=14.14'}
+
resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
@@ -19053,14 +19057,14 @@ snapshots:
dependencies:
commander: 12.1.0
dependencies:
'@webcomponents/custom-elements': 1.6.0
acorn-walk: 8.3.5
convert-source-map: 2.0.0
debug: 4.4.3
es-module-lexer: 0.10.5
- fs-extra: 11.4.0
+ fs-extra: 11.4.1
jsesc: 3.1.0
magic-string: 0.30.21
node-html-parser: 7.1.0
@@ -27741,6 +27745,12 @@ snapshots:
jsonfile: 6.2.1
universalify: 2.0.1
+ dependencies:
+ graceful-fs: 4.2.11
+ jsonfile: 6.2.1
+ universalify: 2.0.1
+