Skip to content

Build your personal knowledge base with Trilium Notes

client/image compression tool: refactor

Adorian Doranf063439fb9ec
diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts
index 47db7ac02d..c4cc587b5d 100644
--- a/apps/client/src/menus/tree_context_menu.ts
+++ b/apps/client/src/menus/tree_context_menu.ts
@@ -17,8 +17,8 @@ import server from "../services/server.js";
import toastService from "../services/toast.js";
import treeService from "../services/tree.js";
import utils from "../services/utils.js";
+import { showImageCompressionDialog } from "../widgets/dialogs/image_compression/image_compression_dialog.jsx";
import type NoteTreeWidget from "../widgets/note_tree.js";
-import { showImageCompressionDialog } from "../widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.jsx";
import contextMenu, { type MenuCommandItem, type MenuItem } from "./context_menu.js";
import NoteColorPicker from "./custom-items/NoteColorPicker.jsx";
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.css b/apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.css
similarity index 100%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.css
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.css
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.spec.tsx b/apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.spec.tsx
similarity index 99%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.spec.tsx
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.spec.tsx
index 7d14c2283f..179cf7bcf1 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.spec.tsx
+++ b/apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.spec.tsx
@@ -35,14 +35,14 @@ const mocks = vi.hoisted(() => ({
closePersistent: vi.fn<(id: string) => void>()
}));
-vi.mock("../../../../../services/options", () => ({
+vi.mock("../../../services/options", () => ({
default: {
get: () => mocks.storedOption,
save: mocks.save
}
}));
-vi.mock("../../../../../services/server", () => ({
+vi.mock("../../../services/server", () => ({
default: {
// The summary reads one of these before the dialog can draw anything. Everything else the
// app loads on the way past — the keyboard actions among them — expects a list.
@@ -59,7 +59,7 @@ vi.mock("../../../../../services/server", () => ({
}
}));
-vi.mock("../../../../../services/toast", () => ({
+vi.mock("../../../services/toast", () => ({
default: {
showMessage: mocks.showMessage,
showPersistent: mocks.showPersistent,
@@ -70,7 +70,7 @@ vi.mock("../../../../../services/toast", () => ({
// The harness loads no translations, so the real `t` answers undefined for every key. Echoing the
// key back instead lets each row be identified by the string it actually asked for, and lets the
// quality reading be read as the value it interpolates.
-vi.mock("../../../../../services/i18n", () => ({
+vi.mock("../../../services/i18n", () => ({
t: (key: string, params?: Record<string, unknown>) => (params ? `${key} ${JSON.stringify(params)}` : key),
translationsInitializedPromise: Promise.resolve(),
initLocale: async () => {},
@@ -81,7 +81,7 @@ vi.mock("../../../../../services/i18n", () => ({
// The real modal reports its close once the animation is done; the stub reports it as soon as it is
// told to hide, which is the signal the dialog's own flow keys off.
-vi.mock("../../../../react/Modal", () => ({
+vi.mock("../../react/Modal", () => ({
default: function ModalStub({ children, footer, show, onHidden }: {
children: ComponentChildren, footer: ComponentChildren, show: boolean, onHidden: () => void
}) {
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.tsx b/apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.tsx
similarity index 96%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.tsx
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.tsx
index e712360bd1..0fa1cc6b22 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_dialog.tsx
+++ b/apps/client/src/widgets/dialogs/image_compression/image_compression_dialog.tsx
@@ -4,12 +4,12 @@ import type { ImageCompressionResponse } from "@triliumnext/commons";
import { render } from "preact";
import { useRef, useState } from "preact/hooks";
-import { t } from "../../../../../services/i18n";
-import toast from "../../../../../services/toast";
-import Button from "../../../../react/Button";
-import { Card } from "../../../../react/Card";
-import { useTriliumOptionJson } from "../../../../react/hooks";
-import Modal from "../../../../react/Modal";
+import { t } from "../../../services/i18n";
+import toast from "../../../services/toast";
+import Button from "../../react/Button";
+import { Card } from "../../react/Card";
+import { useTriliumOptionJson } from "../../react/hooks";
+import Modal from "../../react/Modal";
import {
compressionResultMessage,
IMAGE_COMPRESSION_TOAST_ID,
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_operation.ts b/apps/client/src/widgets/dialogs/image_compression/image_compression_operation.ts
similarity index 95%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_operation.ts
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_operation.ts
index c86559a521..cca89a62f4 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_operation.ts
+++ b/apps/client/src/widgets/dialogs/image_compression/image_compression_operation.ts
@@ -1,8 +1,8 @@
import type { ImageCompressionResponse } from "@triliumnext/commons";
-import { t } from "../../../../../services/i18n";
-import server from "../../../../../services/server";
-import { formatSize } from "../../../../../services/utils";
+import { t } from "../../../services/i18n";
+import server from "../../../services/server";
+import { formatSize } from "../../../services/utils";
import type { ImageCompressionToolOptions } from "./image_compression_options";
/**
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_options.ts b/apps/client/src/widgets/dialogs/image_compression/image_compression_options.ts
similarity index 100%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_options.ts
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_options.ts
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_sections.css b/apps/client/src/widgets/dialogs/image_compression/image_compression_sections.css
similarity index 100%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_sections.css
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_sections.css
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_sections.tsx b/apps/client/src/widgets/dialogs/image_compression/image_compression_sections.tsx
similarity index 96%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_sections.tsx
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_sections.tsx
index d3f690e609..5a747d990f 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_sections.tsx
+++ b/apps/client/src/widgets/dialogs/image_compression/image_compression_sections.tsx
@@ -3,13 +3,13 @@ import "./image_compression_sections.css";
import { IMAGE_JPEG_HANDLINGS, IMAGE_PNG_HANDLINGS } from "@triliumnext/commons";
import clsx from "clsx";
-import { t } from "../../../../../services/i18n";
-import { CardSection } from "../../../../react/Card";
-import ContextualHelp from "../../../../react/ContextualHelp";
-import { FormTextBoxWithUnit } from "../../../../react/FormTextBox";
-import FormToggle from "../../../../react/FormToggle";
-import SegmentedChoice from "../../../../react/SegmentedChoice";
-import Slider from "../../../../react/Slider";
+import { t } from "../../../services/i18n";
+import { CardSection } from "../../react/Card";
+import ContextualHelp from "../../react/ContextualHelp";
+import { FormTextBoxWithUnit } from "../../react/FormTextBox";
+import FormToggle from "../../react/FormToggle";
+import SegmentedChoice from "../../react/SegmentedChoice";
+import Slider from "../../react/Slider";
import {
type ImageCompressionToolOptions,
MAX_QUALITY,
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_summary.css b/apps/client/src/widgets/dialogs/image_compression/image_compression_summary.css
similarity index 100%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_summary.css
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_summary.css
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_summary.tsx b/apps/client/src/widgets/dialogs/image_compression/image_compression_summary.tsx
similarity index 96%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_summary.tsx
rename to apps/client/src/widgets/dialogs/image_compression/image_compression_summary.tsx
index 9e29f9b72d..aa4beb8219 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/image_compression_summary.tsx
+++ b/apps/client/src/widgets/dialogs/image_compression/image_compression_summary.tsx
@@ -7,12 +7,12 @@ import {
type ImageInventoryResponse
} from "@triliumnext/commons";
-import { t } from "../../../../../services/i18n";
-import { formatSize } from "../../../../../services/utils";
-import { useDebouncedValue } from "../../../../react/hooks";
+import { t } from "../../../services/i18n";
+import { formatSize } from "../../../services/utils";
+import { useDebouncedValue } from "../../react/hooks";
+import { useFetch } from "../../react/use_fetch";
import { type ImageCompressionTarget, isSingleImage } from "./image_compression_operation";
import type { ImageCompressionToolOptions } from "./image_compression_options";
-import { useSpaceUsageFetch } from "./use_space_usage_fetch";
/**
* What the dialog is about to act on, read before it acts and before it offers anything: the note
@@ -45,7 +45,7 @@ export function useCompressionReading(
): CompressionReading {
const settledBound = useDebouncedValue(options.maxWidthHeight, READING_DEBOUNCE_MS);
const single = isSingleImage(target);
- const { data, failed } = useSpaceUsageFetch<ImageInfoResponse | ImageInventoryResponse>(
+ const { data, failed } = useFetch<ImageInfoResponse | ImageInventoryResponse>(
single ? imageInfoUrl(target) : inventoryUrl(target, options.processChildNotes, settledBound)
);
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.spec.tsx b/apps/client/src/widgets/react/use_fetch.spec.tsx
similarity index 95%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.spec.tsx
rename to apps/client/src/widgets/react/use_fetch.spec.tsx
index 982afd8bb7..dd965500bc 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.spec.tsx
+++ b/apps/client/src/widgets/react/use_fetch.spec.tsx
@@ -9,24 +9,24 @@ const mocks = vi.hoisted(() => ({
const serverGet = vi.fn<(url: string) => Promise<unknown>>();
mocks.serverGet = serverGet;
-vi.mock("../../../../../services/server", () => ({
+vi.mock("../../services/server", () => ({
default: { get: (url: string) => mocks.serverGet(url) }
}));
// A full mock, not a partial one: the real hooks module transitively imports half the app at module
// scope (app_context, keyboard actions). Any subscription the hook made would land here, which is
// how the "measures only when asked" test can prove it makes none.
-vi.mock("../../../../react/hooks", () => ({
+vi.mock("./hooks", () => ({
useTriliumEvent: (_name: string, handler: (data: { loadResults: unknown }) => void) => {
mocks.entitiesReloadedHandler = handler;
}
}));
// Import AFTER the mocks (vi.mock is hoisted, but the hook import must resolve the mocked deps).
-import { useSpaceUsageFetch } from "./use_space_usage_fetch";
+import { useFetch } from "./use_fetch";
function Probe({ url }: { url: string }) {
- const { data, failed } = useSpaceUsageFetch<{ label: string }>(url);
+ const { data, failed } = useFetch<{ label: string }>(url);
return <div>{data ? data.label : (failed ? "failed" : "loading")}</div>;
}
@@ -49,7 +49,7 @@ afterEach(() => {
vi.useRealTimers();
});
-describe("useSpaceUsageFetch", () => {
+describe("useFetch", () => {
it("fetches the url and renders the payload once it arrives", async () => {
serverGet.mockResolvedValueOnce({ label: "first" });
const probe = renderProbe("space-usage/overview");
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.ts b/apps/client/src/widgets/react/use_fetch.ts
similarity index 70%
rename from apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.ts
rename to apps/client/src/widgets/react/use_fetch.ts
index be3ed65b3b..36b003677c 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/use_space_usage_fetch.ts
+++ b/apps/client/src/widgets/react/use_fetch.ts
@@ -1,33 +1,33 @@
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
-import server from "../../../../../services/server";
+import server from "../../services/server";
-export interface SpaceUsageFetch<T> {
+export interface FetchState<T> {
data: T | null;
/** The last attempt failed. Meaningful only while {@link data} is still null — see below. */
failed: boolean;
- /** A request is in flight. Measuring is expensive enough to be worth keeping to one at a time. */
+ /** A request is in flight. One at a time, however often the URL changes. */
loading: boolean;
}
/**
- * Fetches a space-usage endpoint once, and again whenever the URL changes (Browse navigation) or
- * {@link refreshToken} does — which is how the page's refresh button asks for a fresh reading.
+ * Reads a GET endpoint once, and again whenever the URL changes or {@link refreshToken} does.
*
- * Deliberately *not* refreshed when notes change: measuring the database is expensive enough that
- * re-running it after every edit would keep the server busy for as long as this page stayed open —
- * and the numbers are a snapshot to read, not a live readout. Re-measuring is the user's call.
+ * Nothing else re-runs it — not a note changing, not the component re-rendering. That suits a
+ * reading that costs the server real work to produce and is meant to be looked at rather than
+ * watched: measuring the database for the space-usage pages, or counting up a note's images for the
+ * compression dialog. Asking again is the caller's decision, expressed by bumping the token.
*
* `null` until the first response; on a URL change the previous payload stays up while the new one
- * is in flight, so the charts transition instead of blanking.
+ * is in flight, so a view transitions instead of blanking.
*
* A failure is reported rather than swallowed, because there is nothing to fall back on before the
- * first success: the view would otherwise claim to be measuring for as long as it stayed open. The
+ * first success: the view would otherwise claim to be loading for as long as it stayed open. The
* server service toasts most failures, but not one the browser itself rejected (a dropped
* connection, an unreachable server), which would leave no trace at all. Callers show the failure
- * only while `data` is null — once a payload exists, keeping it beats blanking the charts.
+ * only while `data` is null — once a payload exists, keeping it beats blanking what is shown.
*/
-export function useSpaceUsageFetch<T>(url: string, refreshToken = 0): SpaceUsageFetch<T> {
+export function useFetch<T>(url: string, refreshToken = 0): FetchState<T> {
const [ data, setData ] = useState<T | null>(null);
const [ failed, setFailed ] = useState(false);
const [ loading, setLoading ] = useState(true);
diff --git a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx
index 703e18ed54..8f9b021a75 100644
--- a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx
+++ b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx
@@ -6,11 +6,11 @@ import { downloadFileNote, openNoteExternally } from "../../services/open";
import server from "../../services/server";
import toast from "../../services/toast";
import { clearBrowserCache, formatSize } from "../../services/utils";
+import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
import Button from "../react/Button";
import { FormFileUploadButton } from "../react/FormFileUpload";
import { useNoteBlob, useNoteLabel } from "../react/hooks";
import { ParentComponent } from "../react/react_utils";
-import { showImageCompressionDialog } from "../type_widgets/options/content_manager/space_usage/image_compression_dialog";
import { TabContext } from "./ribbon-interface";
export default function ImagePropertiesTab({ note, ntxId }: TabContext) {
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index 73a04683e1..eb5231733e 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -21,13 +21,13 @@ import ws from "../../services/ws";
import ClosePaneButton from "../buttons/close_pane_button";
import CreatePaneButton from "../buttons/create_pane_button";
import MovePaneButton from "../buttons/move_pane_button";
+import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
import { isAlwaysFullWidthByType } from "../note_wrapper";
import ActionButton from "../react/ActionButton";
import Dropdown from "../react/Dropdown";
import { FormDropdownDivider, FormDropdownSubmenu, FormListHeader, FormListItem, FormListToggleableItem } from "../react/FormList";
import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteLabelOptionalBool, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption } from "../react/hooks";
import { ParentComponent } from "../react/react_utils";
-import { showImageCompressionDialog } from "../type_widgets/options/content_manager/space_usage/image_compression_dialog";
import { NoteTypeDropdownContent, useNoteBookmarkState, useShareState } from "./BasicPropertiesTab";
import NoteActionsCustom from "./NoteActionsCustom";
diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
index 53c59aad9b..5ef95703bf 100644
--- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
@@ -13,13 +13,13 @@ import { downloadFileNote, openNoteExternally } from "../../services/open";
import { createImageSrcUrl, isMobile, openInAppHelpFromUrl } from "../../services/utils";
import { ViewTypeOptions } from "../collections/interface";
import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions";
+import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
import ActionButton, { ActionButtonProps } from "../react/ActionButton";
import { ButtonGroup } from "../react/Button";
import { FormFileUploadActionButton, FormFileUploadFormListItem, FormFileUploadProps } from "../react/FormFileUpload";
import { FormListItem } from "../react/FormList";
import { useEffectiveReadOnly, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";
import { isSplitEditorForcedReadOnly, resolveDisplayMode } from "../type_widgets/helpers/split_editor_mode";
-import { showImageCompressionDialog } from "../type_widgets/options/content_manager/space_usage/image_compression_dialog";
import { ParentComponent } from "../react/react_utils";
import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";
import { buildUploadNewImageRevisionListener } from "./ImagePropertiesTab";
diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx
index 60b996664c..5d71d93425 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.tsx
+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx
@@ -20,6 +20,7 @@ import server from "../../services/server";
import toast from "../../services/toast";
import utils from "../../services/utils";
import ws from "../../services/ws";
+import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
import ActionButton from "../react/ActionButton";
import Admonition from "../react/Admonition";
import Button from "../react/Button";
@@ -36,7 +37,6 @@ import { ParentComponent, refToJQuerySelector } from "../react/react_utils";
import SiblingNavigator from "../react/SiblingNavigator";
import { TextPreview } from "./File";
import MediaPreview from "./file/MediaPreview";
-import { showImageCompressionDialog } from "./options/content_manager/space_usage/image_compression_dialog";
import { TypeWidgetProps } from "./type_widget";
/**
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.spec.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.spec.tsx
index 44ba928c9d..5ebf6c1d0e 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.spec.tsx
@@ -30,8 +30,8 @@ vi.mock("./context_menu", () => ({
openSpaceUsageContextMenu: (...args: unknown[]) => mocks.openContextMenu(...args)
}));
-vi.mock("./use_space_usage_fetch", () => ({
- useSpaceUsageFetch: (url: string) => {
+vi.mock("../../../../react/use_fetch", () => ({
+ useFetch: (url: string) => {
mocks.fetchedUrls.push(url);
return { data: mocks.usage, failed: mocks.failed, loading: mocks.loading };
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
index cdd82c099f..780aafdc75 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
@@ -9,12 +9,12 @@ import { t } from "../../../../../services/i18n";
import { formatSize } from "../../../../../services/utils";
import ActionButton from "../../../../react/ActionButton";
import type { DonutRing } from "../../../../react/charts/DonutChart";
+import { useFetch } from "../../../../react/use_fetch";
import { type ContentChangedHandler, openSpaceUsageContextMenu } from "./context_menu";
import { buildChildrenSegments, type UsageSegmentData } from "./donut_segments";
import { deletedEntitiesLabel } from "./labels";
import NoteUsageDonut, { segmentTooltip } from "./note_usage_donut";
import SpaceUsagePlaceholder from "./placeholder";
-import { useSpaceUsageFetch } from "./use_space_usage_fetch";
const CHILDREN_RING_RADIUS = 180;
const CHILDREN_RING_THICKNESS = 46;
@@ -46,7 +46,7 @@ export default function Browse({
path, onPathChange, refreshToken, onContentChanged, onLoadingChange
}: BrowseProps) {
const noteId = path[path.length - 1];
- const { data: usage, failed, loading } = useSpaceUsageFetch<SpaceUsageNoteResponse>(
+ const { data: usage, failed, loading } = useFetch<SpaceUsageNoteResponse>(
`space-usage/note/${noteId}`, refreshToken);
useEffect(() => onLoadingChange(loading), [ loading, onLoadingChange ]);
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/cleanup_dialog.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/cleanup_dialog.tsx
index bb10896c2e..68fdee037f 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/cleanup_dialog.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/cleanup_dialog.tsx
@@ -18,6 +18,7 @@ import FormTextBox from "../../../../react/FormTextBox";
import FormToggle from "../../../../react/FormToggle";
import { useDebouncedValue, useTriliumOptionJson } from "../../../../react/hooks";
import Modal from "../../../../react/Modal";
+import { useFetch } from "../../../../react/use_fetch";
import {
CLEANUP_ITEMS,
type CleanupPhase,
@@ -29,7 +30,6 @@ import {
runCleanup,
storedCleanupOptions
} from "./cleanup_operation";
-import { useSpaceUsageFetch } from "./use_space_usage_fetch";
/**
* Opens the cleanup dialog, and resolves once it has finished with the database: the bytes the run
@@ -76,11 +76,11 @@ function CleanupDialog({ onFinished }: { onFinished: (reclaimed: number | null)
// Measured with the history erased outright: the whole the reading is "of", and fixed for as
// long as the dialog is open, since no setting here can reclaim more than that.
- const everything = useSpaceUsageFetch<SpaceUsageNoteResponse>(`${ROOT_USAGE_URL}?snapshotsToKeep=0`);
+ const everything = useFetch<SpaceUsageNoteResponse>(`${ROOT_USAGE_URL}?snapshotsToKeep=0`);
// Measured as the settings would trim it. The retention trails the field being typed in, so a
// number entered digit by digit costs one measurement rather than one per keystroke.
const settledSnapshotsToKeep = useDebouncedValue(options.snapshotsToKeep, ESTIMATE_DEBOUNCE_MS);
- const trimmed = useSpaceUsageFetch<SpaceUsageNoteResponse>(
+ const trimmed = useFetch<SpaceUsageNoteResponse>(
`${ROOT_USAGE_URL}?snapshotsToKeep=${settledSnapshotsToKeep}&keepNamedSnapshots=${options.keepNamedSnapshots}`);
// What a rebuild would return, and what the file occupies now — read once on open: only erasures
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
index 6aa2aee2b0..46000d84a3 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
@@ -58,7 +58,7 @@ vi.mock("../../../../../services/server", () => ({
// Stubbed rather than rendered: what belongs here is that the menu opens it, and the dialog's own
// spec covers what it then does.
-vi.mock("./image_compression_dialog", () => ({
+vi.mock("../../../../dialogs/image_compression/image_compression_dialog", () => ({
showImageCompressionDialog: (...args: unknown[]) => mocks.showCompressionDialog(...args)
}));
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
index bf4abcfbfa..b8ce566236 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
@@ -12,7 +12,7 @@ import { downloadFileNote } from "../../../../../services/open";
import options from "../../../../../services/options";
import server from "../../../../../services/server";
import toast from "../../../../../services/toast";
-import { showImageCompressionDialog } from "./image_compression_dialog";
+import { showImageCompressionDialog } from "../../../../dialogs/image_compression/image_compression_dialog";
const ROOT_NOTE_ID = "root";
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.spec.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.spec.tsx
index 7b713c7167..7070d1111b 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.spec.tsx
@@ -15,8 +15,8 @@ const mocks = vi.hoisted(() => ({
reportBrowseLoading: undefined as ((loading: boolean) => void) | undefined
}));
-vi.mock("./use_space_usage_fetch", () => ({
- useSpaceUsageFetch: (_url: string, refreshToken: number) => {
+vi.mock("../../../../react/use_fetch", () => ({
+ useFetch: (_url: string, refreshToken: number) => {
mocks.overviewToken = refreshToken;
return { data: mocks.overview, failed: mocks.failed, loading: mocks.loading };
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
index 433db1f7e3..39ad09fe56 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
@@ -8,13 +8,13 @@ import { formatSize } from "../../../../../services/utils";
import ActionButton from "../../../../react/ActionButton";
import { useStaticTooltip } from "../../../../react/hooks";
import SegmentedChoice from "../../../../react/SegmentedChoice";
+import { useFetch } from "../../../../react/use_fetch";
import OptionsPageHeader from "../../components/OptionsPageHeader";
import type { ContentManagerSectionProps } from "../index";
import Browse from "./browse";
import { showCleanupDialog } from "./cleanup_dialog";
import Overview from "./overview";
import SpaceUsagePlaceholder from "./placeholder";
-import { useSpaceUsageFetch } from "./use_space_usage_fetch";
/** Matches the server default; the treemap could not label more cells anyway. */
const OVERVIEW_LIMIT = 500;
@@ -42,7 +42,7 @@ export default function SpaceUsage({ sectionSwitcher }: ContentManagerSectionPro
// Kept fetched across both views so returning to the treemap draws immediately rather than
// blanking. Revisions stay out of the ranking so it shares the basis of the areas the treemap
// draws — asking for one basis and drawing the other would rank in notes the cells then shrink.
- const { data: overview, failed, loading } = useSpaceUsageFetch<SpaceUsageOverviewResponse>(
+ const { data: overview, failed, loading } = useFetch<SpaceUsageOverviewResponse>(
`space-usage/overview?limit=${OVERVIEW_LIMIT}`, refreshToken);
return (