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
chore(ocr): make the OCR dialog more minimalist
Elian Doran441c4e536cbb
diff --git a/apps/client/src/widgets/dialogs/ocr_text.css b/apps/client/src/widgets/dialogs/ocr_text.cssindex 923fe00581..d9f97c9927 100644--- a/apps/client/src/widgets/dialogs/ocr_text.css+++ b/apps/client/src/widgets/dialogs/ocr_text.css@@ -1,43 +1,39 @@-.text-representation-loading {+.ocr-text-modal-loading {text-align: center;- padding: 30px;+ padding: 2em;color: var(--muted-text-color);}-.text-representation-content {+.ocr-text-modal-content {white-space: pre-wrap;line-height: 1.6;- border: 1px solid var(--main-border-color);- border-radius: 4px;- padding: 15px;- background-color: var(--accented-background-color);- min-height: 100px;user-select: text;}-.text-representation-meta {- font-size: 0.9em;- color: var(--muted-text-color);- margin-top: 10px;- font-style: italic;-}--.text-representation-empty {+.ocr-text-modal-empty {+ display: flex;+ flex-direction: column;+ align-items: center;+ padding: 2em;color: var(--muted-text-color);- font-style: italic;text-align: center;- padding: 30px;-}-.text-representation-process-btn {- margin-top: 15px;+ .bx {+ font-size: 3em;+ margin-bottom: 0.5rem;+ }++ .ocr-text-modal-explanation {+ margin-top: 0.5em;+ font-size: 0.9em;+ font-style: italic;+ }}-.text-representation-error {+.ocr-text-modal-error {color: var(--error-color);background-color: var(--error-background-color);border: 1px solid var(--error-border-color);- padding: 10px;+ padding: 0.75em;border-radius: 4px;- margin-top: 10px;}diff --git a/apps/client/src/widgets/dialogs/ocr_text.tsx b/apps/client/src/widgets/dialogs/ocr_text.tsxindex da3fab684c..b59c8355a0 100644--- a/apps/client/src/widgets/dialogs/ocr_text.tsx+++ b/apps/client/src/widgets/dialogs/ocr_text.tsx@@ -8,6 +8,7 @@ import { t } from "../../services/i18n";import server from "../../services/server";import toast from "../../services/toast";import { randomString } from "../../services/utils";+import Button from "../react/Button";import { useTriliumEvent } from "../react/hooks";import Modal from "../react/Modal";@@ -17,7 +18,7 @@ type State =| { kind: "empty" }| { kind: "error"; message: string };-export interface TextRepresentationProps {+interface TextRepresentationProps {/** The API path to fetch OCR text from (e.g. `ocr/notes/{id}/text`). */textUrl: string;/** The API path to trigger OCR processing (e.g. `ocr/process-note/{id}`). */@@ -35,21 +36,20 @@ export default function OcrTextDialog() {setShown(true);});- return (- <Modal- className="ocr-text-modal"- title={t("ocr.extracted_text_title")}- show={shown}+ return shown && (+ <TextRepresentationModal+ textUrl={textUrl}+ processUrl={processUrl}onHidden={() => setShown(false)}- size="lg"- scrollable- >- {shown && <TextRepresentation textUrl={textUrl} processUrl={processUrl} />}- </Modal>+ />);}-export function TextRepresentation({ textUrl, processUrl }: TextRepresentationProps) {+interface TextRepresentationModalProps extends TextRepresentationProps {+ onHidden: () => void;+}++function TextRepresentationModal({ textUrl, processUrl, onHidden }: TextRepresentationModalProps) {const [ state, setState ] = useState<State>({ kind: "loading" });const [ processing, setProcessing ] = useState(false);@@ -128,50 +128,51 @@ export function TextRepresentation({ textUrl, processUrl }: TextRepresentationPr}}+ const processButton = state.kind !== "loading" && (+ <Button+ icon={processing ? "bx-loader-alt bx-spin" : "bx-refresh"}+ text={processing ? t("ocr.processing") : t("ocr.process_now")}+ size="small"+ disabled={processing}+ onClick={processOCR}+ />+ );+return (- <div className="text-representation">+ <Modal+ className="ocr-text-modal"+ title={t("ocr.extracted_text_title")}+ footer={processButton}+ show={true}+ onHidden={onHidden}+ size="lg"+ scrollable+ >{state.kind === "loading" && (- <div className="text-representation-loading">+ <div className="ocr-text-modal-loading"><span className="bx bx-loader-alt bx-spin" />{" "}{t("ocr.loading_text")}</div>)}{state.kind === "loaded" && (- <div className="text-representation-content">+ <div className="ocr-text-modal-content">{state.text}</div>)}{state.kind === "empty" && (- <>- <div className="text-representation-empty">- <span className="bx bx-info-circle" />{" "}{t("ocr.no_text_available")}- </div>- <div className="text-representation-meta">- {t("ocr.no_text_explanation")}- </div>- </>+ <div className="ocr-text-modal-empty">+ <span className="bx bx-info-circle" />+ <div>{t("ocr.no_text_available")}</div>+ <div className="ocr-text-modal-explanation">{t("ocr.no_text_explanation")}</div>+ </div>)}{state.kind === "error" && (- <div className="text-representation-error">+ <div className="ocr-text-modal-error"><span className="bx bx-error" />{" "}{state.message}</div>)}-- {state.kind !== "loading" && (- <button- type="button"- className="btn btn-secondary text-representation-process-btn"- disabled={processing}- onClick={processOCR}- >- {processing- ? <><span className="bx bx-loader-alt bx-spin" />{" "}{t("ocr.processing")}</>- : <><span className="bx bx-play" />{" "}{t("ocr.process_now")}</>- }- </button>- )}- </div>+ </Modal>);}