mirror of
https://github.com/kadisonm/obsidian-homework-plugin.git
synced 2026-07-22 08:40:33 +00:00
Set up going to linked tasks
This commit is contained in:
parent
3916eaa4e7
commit
a4e377e89b
4 changed files with 29 additions and 51 deletions
|
|
@ -19,4 +19,8 @@ export default class HomeworkModal extends Modal {
|
|||
async onClose() {
|
||||
render(null, this.contentEl);
|
||||
}
|
||||
|
||||
closeModal() {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,24 @@ import { Subject, Task} from "src/data-editor";
|
|||
import { IconButton } from "src/ui/components/icon-button";
|
||||
import { HomeworkModalContext } from "..";
|
||||
import { useContext } from 'preact/hooks';
|
||||
import TaskComponent from "./task";
|
||||
import { Notice, TFile } from "obsidian";
|
||||
|
||||
export default function Body() {
|
||||
const props = useContext(HomeworkModalContext);
|
||||
|
||||
const taskLinkClicked = () => {
|
||||
console.log('test')
|
||||
function taskLinkClicked(page: string) {
|
||||
if (page !== undefined) {
|
||||
const file = this.app.vault.getAbstractFileByPath(page);
|
||||
|
||||
if (file instanceof TFile)
|
||||
{
|
||||
this.app.workspace.getLeaf().openFile(file);
|
||||
this.modal.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
new Notice("Linked file cannot be found.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -22,18 +33,18 @@ export default function Body() {
|
|||
|
||||
{subject.tasks.map((task: Task, index: number) => (
|
||||
<div id="task">
|
||||
{/* Left Div */}
|
||||
<div>
|
||||
<div id="check"/>
|
||||
{/* Left Div */}
|
||||
<div>
|
||||
<div id="check"/>
|
||||
</div>
|
||||
|
||||
{/* Right Div */}
|
||||
<div>
|
||||
<p onClick={() => {taskLinkClicked(task.page)}} className={task.page && "homework-link"} aria-label="Go to linked file" data-tooltip-position="right">
|
||||
{task.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Div */}
|
||||
<div>
|
||||
<p onClick={taskLinkClicked} className={task.page && "homework-link"} aria-label="Go to linked file" data-tooltip-position="right">
|
||||
{task.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
import { TFile, Notice } from "obsidian";
|
||||
import { Task } from "src/data-editor";
|
||||
import { useContext } from 'preact/hooks';
|
||||
import { HomeworkModalContext } from "..";
|
||||
|
||||
export default function TaskComponent({ task }: {task: Task}) {
|
||||
const props = useContext(HomeworkModalContext);
|
||||
|
||||
const onLinkClick = () => {
|
||||
const file = props.app.vault.getAbstractFileByPath(task.page);
|
||||
|
||||
if (file instanceof TFile)
|
||||
{
|
||||
props.app.workspace.getLeaf().openFile(file);
|
||||
props.modal.close();
|
||||
return;
|
||||
}
|
||||
|
||||
new Notice("Linked file cannot be found.");
|
||||
}
|
||||
|
||||
return (
|
||||
<div id="task">
|
||||
{/* Left Div */}
|
||||
<div>
|
||||
<div id="check"/>
|
||||
</div>
|
||||
|
||||
{/* Right Div */}
|
||||
<div>
|
||||
<p onClick={onLinkClick} className="homework-manager-link" aria-label="Go to linked file" data-tooltip-position="right">
|
||||
{task.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue