Skip to content

Commit a2d3db1

Browse files
committed
move layout to separate store
1 parent e1c9fc4 commit a2d3db1

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/hooks.client.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { stats } from "tauri-plugin-cache-api";
22
import { log } from "$lib/log";
3-
import { settings } from "$lib/settings";
43
import { loadThemes } from "$lib/themes";
54

65
export async function init() {
76
const { totalSize } = await stats();
87
log.info(`Cache has ${totalSize} items`);
98

10-
await settings.start();
11-
log.info("Settings synced");
12-
139
await loadThemes();
1410
}

src/lib/menus/channel-menu.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { page } from "$app/state";
44
import { app } from "$lib/app.svelte";
55
import type { Channel } from "$lib/models/channel.svelte";
66
import { settings } from "$lib/settings";
7-
import type { SplitBranch, SplitDirection } from "$lib/split-layout";
7+
import type { SplitBranch } from "$lib/split-layout";
8+
9+
type SplitDirection = "up" | "down" | "left" | "right";
810

911
async function splitItem(channel: Channel, direction: SplitDirection) {
1012
return MenuItem.new({

src/lib/settings.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { RuneStore } from "@tauri-store/svelte";
22
import type { User } from "./graphql/twitch";
3-
import type { SplitNode } from "./split-layout";
43

54
export type HighlightType =
65
| "mention"
@@ -70,7 +69,6 @@ interface Settings extends UserSettings {
7069
user: StoredUser | null;
7170
lastJoined: string | null;
7271
pinned: string[];
73-
layout: SplitNode | null;
7472
}
7573

7674
export const defaultHighlightTypes: Record<HighlightType, HighlightConfig> = {
@@ -88,7 +86,6 @@ export const defaults: Settings = {
8886
user: null,
8987
lastJoined: null,
9088
pinned: [],
91-
layout: null,
9289

9390
"appearance.theme": "",
9491
"chat.hideScrollbar": false,
@@ -117,14 +114,4 @@ export const defaults: Settings = {
117114
"advanced.logs.level": "info",
118115
};
119116

120-
export const settings = new RuneStore<Settings>("settings", defaults, {
121-
hooks: {
122-
beforeBackendSync(state) {
123-
if (typeof state.layout === "string") {
124-
state.layout = null;
125-
}
126-
127-
return state;
128-
},
129-
},
130-
});
117+
export const settings = new RuneStore<Settings>("settings", defaults, { autoStart: true });

src/lib/split-layout.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { DragDropEvents } from "@dnd-kit-svelte/svelte";
22
import type { PaneGroupProps } from "paneforge";
3-
import { settings } from "$lib/settings";
3+
import { layout } from "./stores";
44

5-
export type SplitAxis = PaneGroupProps["direction"];
6-
export type SplitDirection = "up" | "down" | "left" | "right";
5+
type SplitAxis = PaneGroupProps["direction"];
76

87
export interface SplitBranch {
98
axis: SplitAxis;
@@ -18,11 +17,11 @@ type SplitPath = ("before" | "after")[];
1817

1918
export class SplitLayout {
2019
public get root() {
21-
return settings.state.layout;
20+
return layout.state.root;
2221
}
2322

2423
public set root(value: SplitNode | null) {
25-
settings.state.layout = value;
24+
layout.state.root = value;
2625
}
2726

2827
public insert(target: string, newNode: string, branch: SplitBranch) {

src/lib/stores.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RuneStore } from "@tauri-store/svelte";
2+
import type { SplitNode } from "./split-layout";
3+
4+
interface Layout {
5+
[key: string]: unknown;
6+
root: SplitNode | null;
7+
}
8+
9+
export const layout = new RuneStore<Layout>(
10+
"layout",
11+
{ root: null },
12+
{
13+
autoStart: true,
14+
hooks: {
15+
beforeBackendSync(state) {
16+
if (typeof state.root === "string") {
17+
state.root = null;
18+
}
19+
20+
return state;
21+
},
22+
},
23+
},
24+
);

src/routes/(main)/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { buttonVariants } from "$lib/components/ui/button";
99
import * as Empty from "$lib/components/ui/empty";
1010
import { settings } from "$lib/settings";
11+
import { layout } from "$lib/stores";
1112
1213
let loading = $state(true);
1314
@@ -18,8 +19,8 @@
1819
await app.user.fetchEmoteSets();
1920
}
2021
21-
if (settings.state.layout) {
22-
app.splits.root = settings.state.layout;
22+
if (layout.state.root) {
23+
app.splits.root = layout.state.root;
2324
2425
await goto("/channels/split");
2526
} else if (settings.state.lastJoined) {

0 commit comments

Comments
 (0)