andy-stack_vaultkeeper-ai/Views/MainView.ts

71 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-09-08 14:50:06 +00:00
import { ItemView, WorkspaceLeaf } from 'obsidian';
import { mount, unmount } from 'svelte';
import ChatWindow from 'Components/ChatWindow.svelte';
import TopBar from 'Components/TopBar.svelte';
import { AssetsService } from 'Services/AssetsService';
import { Resolve } from 'Services/DependencyService';
import { Services } from 'Services/Services';
2025-09-08 14:50:06 +00:00
2025-11-10 08:03:27 +00:00
export const VIEW_TYPE_MAIN = 'vaultkeeper-ai-main-view';
2025-09-08 14:50:06 +00:00
interface ChatWindowComponent {
focusInput: () => void;
resetChatArea: () => void;
}
2025-09-08 14:50:06 +00:00
export class MainView extends ItemView {
private readonly assetsService: AssetsService;
2025-09-08 14:50:06 +00:00
constructor(leaf: WorkspaceLeaf) {
super(leaf);
this.assetsService = Resolve<AssetsService>(Services.AssetsService);
2025-09-08 14:50:06 +00:00
}
topBar: ReturnType<typeof TopBar> | undefined;
input: ChatWindowComponent | undefined;
2025-09-08 14:50:06 +00:00
public getViewType() {
2025-09-08 14:50:06 +00:00
return VIEW_TYPE_MAIN;
}
public getDisplayText() {
2025-11-10 08:03:27 +00:00
return "Vaultkeeper AI";
2025-09-08 14:50:06 +00:00
}
public getIcon(): string {
return this.assetsService.pluginIcon;
}
protected override onOpen(): Promise<void> {
2025-09-08 14:50:06 +00:00
const container = this.contentEl;
container.empty();
this.topBar = mount(TopBar, {
target: container,
props: {
leaf: this.leaf,
onNewConversation: () => {
this.input?.resetChatArea();
this.input?.focusInput();
}
}
});
this.input = mount(ChatWindow, {
2025-09-08 14:50:06 +00:00
target: container,
props: {}
}) as ChatWindowComponent;
return Promise.resolve();
2025-09-08 14:50:06 +00:00
}
public override async onClose(): Promise<void> {
if (this.topBar) {
await unmount(this.topBar);
}
2025-09-08 14:50:06 +00:00
if (this.input) {
await unmount(this.input);
2025-09-08 14:50:06 +00:00
}
}
}