Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(web-clipper): draw "Trilium was not found" as the popup's empty state
Elian Doran37b74a405652
diff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsxindex be1b06a6d6..38c1a9964e 100644--- a/apps/web-clipper/entrypoints/popup/main.tsx+++ b/apps/web-clipper/entrypoints/popup/main.tsx@@ -14,6 +14,7 @@ import Lock from "@boxicons/js/icons/Lock";import RefreshCw from "@boxicons/js/icons/RefreshCw";import Screenshot from "@boxicons/js/icons/Screenshot";import Tabs from "@boxicons/js/icons/Tabs";+import Unlink from "@boxicons/js/icons/Unlink";import type { ComponentChildren } from "preact";import { render } from "preact";import { useEffect, useRef, useState } from "preact/hooks";@@ -244,9 +245,13 @@ function ToolbarAction({ icon, label, name, shortcut, disabledReason, onClick }:}/** Takes the place of the page preview when the page cannot be saved, in the style of the app's `NoItems`. */-function EmptyState({ icon, children }: { icon: IconDefinition, children: ComponentChildren }) {+function EmptyState({ icon, className, children }: {+ icon: IconDefinition;+ className?: string;+ children: ComponentChildren;+}) {return (- <div className="no-items">+ <div className={className ? `no-items ${className}` : "no-items"}><Icon icon={icon} />{children}</div>@@ -321,15 +326,19 @@ function Shortcut({ keys }: { keys: string | undefined }) {function TriliumNotFound() {return (- <div className="not-found">- <strong>Trilium was not found.</strong>- <p>Start the Trilium desktop application, or connect to a Trilium server in the options.</p>+ <EmptyState icon={Unlink} className="not-found">+ <h4>Trilium was not found</h4>+ <p>Start the desktop app, or connect to a server in the options.</p><div className="not-found-buttons">- <button className="btn btn-primary" onClick={() => sendMessage({ name: "trigger-trilium-search" })}>Retry</button>- <button className="btn btn-secondary" onClick={() => browser.runtime.openOptionsPage()}>Open options</button>+ <button className="btn btn-primary" onClick={() => sendMessage({ name: "trigger-trilium-search" })}>+ <Icon icon={RefreshCw} />Retry+ </button>+ <button className="btn btn-secondary" onClick={() => browser.runtime.openOptionsPage()}>+ <Icon icon={Cog} />Open options+ </button></div>- </div>+ </EmptyState>);}diff --git a/apps/web-clipper/entrypoints/popup/popup.css b/apps/web-clipper/entrypoints/popup/popup.cssindex a54b81be67..7e5513faca 100644--- a/apps/web-clipper/entrypoints/popup/popup.css+++ b/apps/web-clipper/entrypoints/popup/popup.css@@ -144,7 +144,7 @@ body {text-align: center;white-space: pre-line;- svg.icon {+ > svg.icon {width: 2em;height: 2em;margin-bottom: 0.5rem;@@ -204,27 +204,28 @@ body {}}- .not-found {- display: flex;- flex-direction: column;- gap: 4px;- padding: 12px;- border-radius: 6px;- background: var(--input-background-color);+ .no-items.not-found {+ h4 {+ margin: 0 0 4px;+ color: var(--main-text-color);+ font-size: 1.1em;+ font-weight: 500;+ }p {- margin: 0 0 8px;- color: var(--muted-text-color);+ margin: 0;}}.not-found-buttons {display: flex;- gap: 6px;+ gap: 8px;+ width: 100%;+ margin-top: 16px;button.btn {+ flex: 1;min-width: 0;- flex-grow: 1;}}diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsxindex 49ca2f919e..b5dca0e3b0 100644--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx@@ -115,7 +115,14 @@ describe("popup", () => {await receive({ name: "trilium-search-status", triliumSearch: { status: "not-found" } });expect(status()).toEqual({ dot: "status-dot status-dot-error", text: "Not found" });expect(captureButtons()).toHaveLength(0);- expect(container.querySelector(".not-found strong")?.textContent).toBe("Trilium was not found.");+ const notFound = container.querySelector(".no-items.not-found");+ expect(notFound).not.toBeNull();+ expect(notFound?.querySelector(":scope > svg.icon path")).not.toBeNull();+ expect(notFound?.querySelector("h4")?.textContent).toBe("Trilium was not found");+ expect(notFound?.querySelector("p")?.textContent)+ .toBe("Start the desktop app, or connect to a server in the options.");+ expect([ ...notFound?.querySelectorAll("button") ?? [] ].map((b) => [ b.textContent, !!b.querySelector("svg.icon") ]))+ .toEqual([ [ "Retry", true ], [ "Open options", true ] ]);expect(sendMessage).not.toHaveBeenCalledWith({ name: "trigger-trilium-search-note-url" });await click("Retry");