From bba41f4520fa65d6ceb874bc915ef9f45ec6613c Mon Sep 17 00:00:00 2001 From: L7Cy Date: Sat, 2 Sep 2023 12:32:54 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB?= =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TimetableView.tsx | 14 +++++--------- src/TimetableViewComponent.tsx | 8 ++------ 2 files changed, 7 insertions(+), 15 deletions(-) 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();