diff --git a/src/TimetableView.tsx b/src/TimetableView.tsx index d7d0614..4d9eefe 100644 --- a/src/TimetableView.tsx +++ b/src/TimetableView.tsx @@ -2,23 +2,19 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; import { WorkspaceLeaf, ItemView } from 'obsidian'; import DynamicTimetable from './main'; -import TimetableViewComponent, { - TimetableViewComponentRef, -} from './TimetableViewComponent'; +import TimetableViewComponent from './TimetableViewComponent'; import { CommandsManager } from './Commands'; export class TimetableView extends ItemView { private readonly plugin: DynamicTimetable; - private componentRef: React.RefObject; private root: any; private commandsManager: CommandsManager; constructor(leaf: WorkspaceLeaf, plugin: DynamicTimetable) { super(leaf); this.plugin = plugin; - this.componentRef = React.createRef(); this.commandsManager = new CommandsManager(plugin); - this.icon = "table"; + this.icon = 'table'; } getViewType(): string { @@ -33,7 +29,7 @@ export class TimetableView extends ItemView { this.root = createRoot(this.containerEl); this.root.render( @@ -47,8 +43,8 @@ export class TimetableView extends ItemView { } async update() { - if (this.componentRef.current) { - this.componentRef.current.update(); + if (this.plugin.timetableViewComponentRef.current) { + this.plugin.timetableViewComponentRef.current.update(); } } } diff --git a/src/TimetableViewComponent.tsx b/src/TimetableViewComponent.tsx index fcab314..78b2a59 100644 --- a/src/TimetableViewComponent.tsx +++ b/src/TimetableViewComponent.tsx @@ -12,7 +12,7 @@ import ProgressBar from './ProgressBar'; import { CommandsManager } from './Commands'; import BufferTimeRow from './BufferTimeRow'; import TaskRow from './TaskRow'; -import { MarkdownView, Notice } from 'obsidian'; +import { Notice } from 'obsidian'; import { convertHexToHSLA, getHSLAColorForCategory, @@ -70,10 +70,6 @@ const TimetableViewComponent = forwardRef< const performScroll = () => { if (firstUncompletedTaskRef.current && containerRef.current) { - const activeView = plugin.app.workspace.getActiveViewOfType(MarkdownView); - if (activeView?.file === plugin.targetFile) { - return; - } const containerHeight = containerRef.current.offsetHeight; const taskOffsetTop = firstUncompletedTaskRef.current.offsetTop; const scrollToPosition = taskOffsetTop - containerHeight / 5; @@ -199,7 +195,7 @@ const TimetableViewComponent = forwardRef< useEffect(() => { performScroll(); - }, [tasks]); + }, [plugin.targetFile]); useEffect(() => { updateBackgroundColors();