Skip to content

Commit 76b272f

Browse files
committed
refactors
1 parent c669c39 commit 76b272f

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

src/lib/components/Channel.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
let unlisten: UnlistenFn | undefined;
2020
2121
onMount(async () => {
22-
if (!channel.joined) {
23-
await channel.join();
24-
}
22+
await channel.join();
2523
2624
unlisten = await listen<IrcMessage[]>("recentmessages", async (event) => {
2725
for (const message of event.payload) {

src/lib/components/split/SplitNode.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414
{#if typeof node === "string"}
1515
<SplitView id={node} />
1616
{:else}
17-
<PaneGroup class="size-full" direction={node.direction}>
17+
<PaneGroup class="size-full" direction={node.axis}>
1818
<Pane defaultSize={node.size ?? 50}>
1919
<Self node={node.first} />
2020
</Pane>
2121

2222
<PaneResizer
2323
class={[
2424
"bg-muted relative flex items-center justify-center transition-colors hover:bg-blue-400",
25-
node.direction === "horizontal"
26-
? "w-0.5 cursor-col-resize"
27-
: "h-0.5 cursor-row-resize",
25+
node.axis === "horizontal" ? "w-0.5 cursor-col-resize" : "h-0.5 cursor-row-resize",
2826
]}
2927
/>
3028

src/lib/managers/split-manager.svelte.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import type { DragDropEvents } from "@dnd-kit-svelte/svelte";
22
import type { PaneGroupProps } from "paneforge";
33
import { settings } from "$lib/settings";
44

5+
export type SplitAxis = PaneGroupProps["direction"];
56
export type SplitDirection = "up" | "down" | "left" | "right";
67

7-
export interface SplitParent {
8-
direction: PaneGroupProps["direction"];
8+
export interface SplitBranch {
9+
axis: SplitAxis;
910
first: SplitNode;
1011
second: SplitNode;
1112
size?: number;
1213
}
1314

14-
export type SplitNode = SplitParent | string;
15+
export type SplitNode = SplitBranch | string;
1516

1617
type SplitPath = "first" | "second";
1718

@@ -24,7 +25,7 @@ export class SplitManager {
2425
settings.state.layout = value;
2526
}
2627

27-
public insert(target: string, newNode: string, data: SplitParent) {
28+
public insert(target: string, newNode: string, branch: SplitBranch) {
2829
if (!this.root) {
2930
this.root = target;
3031
return;
@@ -35,23 +36,23 @@ export class SplitManager {
3536

3637
this.root = this.#update(this.root, path, (node) => {
3738
if (typeof node === "string") {
38-
return { ...data, size: 50 };
39+
return { ...branch, size: 50 };
3940
}
4041

4142
return {
42-
direction: data.direction,
43+
axis: branch.axis,
4344
first: node,
4445
second: newNode,
4546
size: 50,
4647
};
4748
});
4849
}
4950

50-
public insertEmpty(target: string, direction: PaneGroupProps["direction"]) {
51+
public insertEmpty(target: string, axis: SplitAxis) {
5152
const id = `split-${crypto.randomUUID()}`;
5253

5354
this.insert(target, id, {
54-
direction,
55+
axis,
5556
first: target,
5657
second: id,
5758
});
@@ -127,7 +128,7 @@ export class SplitManager {
127128
second = targetId;
128129
}
129130

130-
this.insert(targetId, sourceId, { direction, first, second });
131+
this.insert(targetId, sourceId, { axis: direction, first, second });
131132
}
132133
}
133134

src/lib/menus/channel-menu.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CheckMenuItem, Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/a
22
import { goto } from "$app/navigation";
33
import { page } from "$app/state";
44
import { app } from "$lib/app.svelte";
5-
import type { SplitDirection, SplitParent } from "$lib/managers/split-manager.svelte";
5+
import type { SplitBranch, SplitDirection } from "$lib/managers/split-manager.svelte";
66
import type { Channel } from "$lib/models/channel.svelte";
77
import { settings } from "$lib/settings";
88

@@ -12,16 +12,14 @@ async function splitItem(channel: Channel, direction: SplitDirection) {
1212
text: `Split ${direction.charAt(0).toUpperCase() + direction.slice(1)}`,
1313
enabled: !settings.state["advanced.singleConnection"],
1414
async action() {
15-
if (!channel.joined) {
16-
await channel.join(true);
17-
}
15+
await channel.join(true);
1816

1917
if (!app.focused) return;
2018

2119
app.splits.root ??= app.focused.id;
2220

23-
const node: SplitParent = {
24-
direction: direction === "up" || direction === "down" ? "vertical" : "horizontal",
21+
const node: SplitBranch = {
22+
axis: direction === "up" || direction === "down" ? "vertical" : "horizontal",
2523
first: channel.id,
2624
second: app.focused.id,
2725
};

src/lib/models/channel.svelte.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export class Channel {
8989
}
9090

9191
public async join(split = false) {
92+
if (this.joined) return;
93+
9294
app.channels.set(this.id, this);
9395
this.joined = true;
9496

0 commit comments

Comments
 (0)