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
client/options/ETAPI: switch to the new card component
Adorian Doranc45ac0ee178c
diff --git a/apps/client/src/widgets/type_widgets/options/etapi.css b/apps/client/src/widgets/type_widgets/options/etapi.cssnew file mode 100644index 0000000000..ba06c49f98--- /dev/null+++ b/apps/client/src/widgets/type_widgets/options/etapi.css@@ -0,0 +1,28 @@+/* What the page is for, and the one thing it offers, on the row below the title — a narrow header+ puts the button on a line of its own rather than squeezing the sentence to a word. */+.etapi-header-row {+ display: flex;+ flex-wrap: wrap;+ justify-content: end;+ align-items: center;+ gap: 16px;++ > .btn {+ flex-shrink: 0;+ white-space: nowrap;+ }+}++/* Carried by the page's header rather than by a card, so it states its own type: the size and colour+ a card's own introducing sentence is set in. */+.etapi-description {+ flex: 1 1 auto;+ margin: 0;+ color: var(--muted-text-color);+ font-size: 13px;+}++.etapi-token-actions {+ display: flex;+ gap: 4px;+}diff --git a/apps/client/src/widgets/type_widgets/options/etapi.tsx b/apps/client/src/widgets/type_widgets/options/etapi.tsxindex 28e7fbaa79..0094f9f218 100644--- a/apps/client/src/widgets/type_widgets/options/etapi.tsx+++ b/apps/client/src/widgets/type_widgets/options/etapi.tsx@@ -1,3 +1,5 @@+import "./etapi.css";+import { EtapiToken, PostTokensResponse } from "@triliumnext/commons";import { useCallback, useEffect, useState } from "preact/hooks";@@ -8,11 +10,10 @@ import toast from "../../../services/toast";import { formatDateTime } from "../../../utils/formatters";import ActionButton from "../../react/ActionButton";import Button from "../../react/Button";+import { Card, CardOption } from "../../react/Card";import { useTriliumEvent } from "../../react/hooks";import NoItems from "../../react/NoItems";import OptionsPageHeader from "./components/OptionsPageHeader";-import OptionsRow from "./components/OptionsRow";-import OptionsSection from "./components/OptionsSection";type RenameTokenCallback = (tokenId: string, oldName: string) => Promise<void>;type DeleteTokenCallback = (tokenId: string, name: string ) => Promise<void>;@@ -54,21 +55,26 @@ export default function EtapiSettings() {return (<>- <OptionsPageHeader helpUrl="pgxEVkzLl1OP" />- <OptionsSection- description={t("etapi.description")}- >- <TokenList tokens={tokens} />-- <OptionsRow name="create-etapi-token" centered>- <Button- name="create-etapi-token-button"- size="micro" icon="bx bx-plus"- text={t("etapi.create_token")}- onClick={createTokenCallback}- />- </OptionsRow>- </OptionsSection>+ {/* Both the sentence and the way to add a token belong to the page rather than to the+ list: with no tokens yet there is no card for either of them to sit in. They share the+ row below the title, where the button is clear of the dialog's own close button. */}+ <OptionsPageHeader+ helpUrl="pgxEVkzLl1OP"+ below={+ <div className="etapi-header-row">+ <p className="etapi-description">{t("etapi.description")}</p>++ <Button+ name="create-etapi-token-button"+ size="micro" icon="bx-plus"+ text={t("etapi.create_token")}+ onClick={createTokenCallback}+ />+ </div>+ }+ />++ <TokenList tokens={tokens} /></>);}@@ -96,36 +102,44 @@ function TokenList({ tokens }: { tokens: EtapiToken[] }) {await server.remove(`etapi-tokens/${tokenId}`);}, []);+ // Nothing to frame while there is nothing to list: the placeholder stands on the page itself, an+ // empty card being a statement of its own.if (!tokens.length) {- return <NoItems icon="bx bx-key" text={t("etapi.no_tokens")} />;+ return (+ <div className="options-section">+ <NoItems icon="bx bx-key" text={t("etapi.no_tokens")} />+ </div>+ );}- return <>- {tokens.map(({ etapiTokenId, name, utcDateCreated }) => (- <OptionsRow- key={etapiTokenId ?? name}- name="etapi-token"- label={name}- description={formatDateTime(utcDateCreated)}- >- <div>- {etapiTokenId && (- <>- <ActionButton- icon="bx bx-edit-alt"- text={t("etapi.rename_token")}- onClick={() => renameCallback(etapiTokenId, name)}- />-- <ActionButton- icon="bx bx-trash"- text={t("etapi.delete_token")}- onClick={() => deleteCallback(etapiTokenId, name)}- />- </>- )}- </div>- </OptionsRow>- ))}- </>;+ return (+ <div className="options-section">+ <Card>+ {tokens.map(({ etapiTokenId, name, utcDateCreated }) => (+ <CardOption+ key={etapiTokenId ?? name}+ label={name}+ description={formatDateTime(utcDateCreated)}+ >+ {etapiTokenId && (+ <span className="etapi-token-actions">+ <ActionButton+ icon="bx bx-edit-alt"+ text={t("etapi.rename_token")}+ onClick={() => renameCallback(etapiTokenId, name)}+ />++ <ActionButton+ className="destructive-action-icon"+ icon="bx bx-trash"+ text={t("etapi.delete_token")}+ onClick={() => deleteCallback(etapiTokenId, name)}+ />+ </span>+ )}+ </CardOption>+ ))}+ </Card>+ </div>+ );}