From a2d8c0a7da212c4a160125035ee03167b51c1e7c Mon Sep 17 00:00:00 2001 From: u8array Date: Mon, 11 May 2026 01:51:00 +0000 Subject: [PATCH] Refactor Labelary preview to support custom hosts Update the Labelary preview functionality to allow for custom API hosts and keys, supporting private Labelary instances. This includes changes to the store, locale strings, and the addition of a `isDefaultLabelaryHost` utility function. The privacy notice link has also been updated to point to Labelary's service and pricing information, rather than just privacy. --- src/components/AppShell.tsx | 6 +-- src/components/Output/LabelPreview.tsx | 24 ++++++----- src/components/Output/LabelaryNoticeModal.tsx | 2 +- src/components/Output/ZPLOutput.tsx | 6 +-- src/lib/labelary.ts | 41 ++++++++++++++++++- src/locales/ar.ts | 2 +- src/locales/bg.ts | 2 +- src/locales/cs.ts | 2 +- src/locales/da.ts | 2 +- src/locales/de.ts | 2 +- src/locales/el.ts | 2 +- src/locales/en.ts | 2 +- src/locales/es.ts | 2 +- src/locales/et.ts | 2 +- src/locales/fa.ts | 2 +- src/locales/fi.ts | 2 +- src/locales/fr.ts | 2 +- src/locales/he.ts | 2 +- src/locales/hr.ts | 2 +- src/locales/hu.ts | 2 +- src/locales/it.ts | 2 +- src/locales/ja.ts | 2 +- src/locales/ko.ts | 2 +- src/locales/lt.ts | 2 +- src/locales/lv.ts | 2 +- src/locales/nl.ts | 2 +- src/locales/no.ts | 2 +- src/locales/pl.ts | 2 +- src/locales/pt.ts | 2 +- src/locales/ro.ts | 2 +- src/locales/sk.ts | 2 +- src/locales/sl.ts | 2 +- src/locales/sr.ts | 2 +- src/locales/sv.ts | 2 +- src/locales/tr.ts | 2 +- src/locales/zh-hans.ts | 2 +- src/locales/zh-hant.ts | 2 +- src/store/labelStore.ts | 7 ++++ 38 files changed, 98 insertions(+), 52 deletions(-) diff --git a/src/components/AppShell.tsx b/src/components/AppShell.tsx index 87a7bf19..07a62fb4 100644 --- a/src/components/AppShell.tsx +++ b/src/components/AppShell.tsx @@ -31,7 +31,7 @@ import { SunIcon, MoonIcon, } from "@heroicons/react/16/solid"; -import { useLabelStore, useHistory } from "../store/labelStore"; +import { useLabelStore, useHistory, selectLabelaryNoticeRequired } from "../store/labelStore"; import { LabelaryNoticeModal } from "./Output/LabelaryNoticeModal"; import { localeNames } from "../locales"; import type { LocaleCode } from "../locales"; @@ -54,7 +54,7 @@ export function AppShell() { const theme = useLabelStore((s) => s.theme); const setTheme = useLabelStore((s) => s.setTheme); const labelaryEnabled = useLabelStore((s) => s.thirdParty.labelary); - const noticeAcknowledged = useLabelStore((s) => s.labelaryNoticeAcknowledged); + const noticeRequired = useLabelStore(selectLabelaryNoticeRequired); const [showPrintNotice, setShowPrintNotice] = useState(false); // Bridge the theme preference to so the CSS variables in @@ -218,7 +218,7 @@ export function AppShell() { {labelaryEnabled && ( (noticeAcknowledged ? handlePrint() : setShowPrintNotice(true))} + onClick={() => (noticeRequired ? setShowPrintNotice(true) : handlePrint())} disabled={!hasObjects} > {t.app.print} diff --git a/src/components/Output/LabelPreview.tsx b/src/components/Output/LabelPreview.tsx index 1a78d2c2..378505f9 100644 --- a/src/components/Output/LabelPreview.tsx +++ b/src/components/Output/LabelPreview.tsx @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'; import { XMarkIcon, ArrowDownTrayIcon } from '@heroicons/react/16/solid'; import { useLabelStore, useCurrentObjects } from '../../store/labelStore'; import { generateZPL } from '../../lib/zplGenerator'; -import { fetchPreview, labelaryErrorMessage } from '../../lib/labelary'; +import { fetchPreview, labelaryErrorMessage, isDefaultLabelaryHost } from '../../lib/labelary'; import { triggerDownload } from '../../lib/triggerDownload'; import { useT } from '../../lib/useT'; import { DialogShell } from '../ui/DialogShell'; @@ -101,16 +101,18 @@ export function LabelPreviewModal({ onClose }: Props) { -
- - {t.output.previewProvider} - -
+ {isDefaultLabelaryHost() && ( +
+ + {t.output.previewProvider} + +
+ )} ); } diff --git a/src/components/Output/LabelaryNoticeModal.tsx b/src/components/Output/LabelaryNoticeModal.tsx index 0c109030..6c16f16e 100644 --- a/src/components/Output/LabelaryNoticeModal.tsx +++ b/src/components/Output/LabelaryNoticeModal.tsx @@ -47,7 +47,7 @@ export function LabelaryNoticeModal({ onContinue, onClose }: Props) {
{t.output.previewNoticeBody} s.label); const pages = useLabelStore((s) => s.pages); const labelaryEnabled = useLabelStore((s) => s.thirdParty.labelary); - const noticeAcknowledged = useLabelStore((s) => s.labelaryNoticeAcknowledged); + const noticeRequired = useLabelStore(selectLabelaryNoticeRequired); const [copied, setCopied] = useState(false); const [showPreview, setShowPreview] = useState(false); const [showNotice, setShowNotice] = useState(false); @@ -50,7 +50,7 @@ export function ZPLOutput({ collapsed, onCollapse, onExpand }: Props) {
{labelaryEnabled && (