summaryrefslogtreecommitdiffhomepage
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/store.svelte.ts14
-rw-r--r--src/app/store.test.ts23
2 files changed, 34 insertions, 3 deletions
diff --git a/src/app/store.svelte.ts b/src/app/store.svelte.ts
index d75495a..c354e11 100644
--- a/src/app/store.svelte.ts
+++ b/src/app/store.svelte.ts
@@ -123,9 +123,12 @@ import {
type VisionSettings,
type VisionSettingsPatch,
} from "../features/vision";
-import { createTileLayoutHttp } from "../features/workspaces/adapter/tile-layout-http";
-import type { TileLayoutStore } from "../features/workspaces/tile-layout-store.svelte";
-import { createTileLayoutStore } from "../features/workspaces/tile-layout-store.svelte";
+import {
+ createTileLayoutHttp,
+ createTileLayoutStore,
+ geometryFor,
+ type TileLayoutStore,
+} from "../features/workspaces";
import { createPluginHost } from "./plugin-host.svelte";
import { resolveHttpUrl } from "./resolve-http-url";
import { resolveWsUrl } from "./resolve-ws-url";
@@ -816,6 +819,11 @@ export function createAppStore(opts?: CreateAppStoreOptions): AppStore {
// the debounced PUT + rollback, and the offline degrade.
const tileLayoutStore = createTileLayoutStore({
http: createTileLayoutHttp(httpBase, fetchImpl),
+ initialMode:
+ typeof window === "undefined"
+ ? "wide"
+ : geometryFor(window.innerWidth, window.innerHeight).mode,
+ storage: localStorageOpt,
});
/**
diff --git a/src/app/store.test.ts b/src/app/store.test.ts
index bfd4039..4c530f1 100644
--- a/src/app/store.test.ts
+++ b/src/app/store.test.ts
@@ -234,6 +234,29 @@ describe("createAppStore", () => {
store.dispose();
});
+ it("probes only the portrait tile layout at boot and injects its cached document", () => {
+ const width = vi.spyOn(window, "innerWidth", "get").mockReturnValue(390);
+ const height = vi.spyOn(window, "innerHeight", "get").mockReturnValue(844);
+ const storage = createFakeStorage();
+ const cached = { version: 2, tiles: [{ id: "a", order: 0, colSpan: 2, rowSpan: 2 }] };
+ storage.setItem("dispatch.tile-layout.tall", JSON.stringify(cached));
+ const fetchImpl = vi.fn(fakeFetchImpl());
+ const store = createAppStore({ socketFactory: fakeSocket, fetchImpl, localStorage: storage });
+ try {
+ expect(store.tileLayout.mode).toBe("tall");
+ expect(store.tileLayout.entries).toEqual(cached.tiles);
+ expect(
+ fetchImpl.mock.calls
+ .map(([url]) => String(url))
+ .filter((url) => url.includes("/home/tile-layout/")),
+ ).toEqual([expect.stringMatching(/\/home\/tile-layout\/tall$/)]);
+ } finally {
+ store.dispose();
+ width.mockRestore();
+ height.mockRestore();
+ }
+ });
+
it("updates catalog when catalog message arrives", () => {
const ws = fakeSocket();
const store = createAppStore({