-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: open journal from calendar view click
- Loading branch information
1 parent
f7e8e74
commit c299cba
Showing
15 changed files
with
219 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { type App, SuggestModal } from "obsidian"; | ||
|
||
interface JournalOption { | ||
id: string; | ||
name: string; | ||
} | ||
|
||
export class JournalSuggestModal extends SuggestModal<JournalOption> { | ||
constructor( | ||
app: App, | ||
private journals: JournalOption[], | ||
private cb: (journalId: string) => void, | ||
) { | ||
super(app); | ||
} | ||
|
||
getSuggestions(query: string): JournalOption[] | Promise<JournalOption[]> { | ||
query = query.toLocaleLowerCase(); | ||
return this.journals.filter((journal) => journal.name.toLocaleLowerCase().contains(query)); | ||
} | ||
renderSuggestion(value: JournalOption, el: HTMLElement) { | ||
el.setText(value.name); | ||
} | ||
onChooseSuggestion(item: JournalOption) { | ||
this.cb(item.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Menu } from "obsidian"; | ||
import { app$, plugin$ } from "@/stores/obsidian.store"; | ||
import { JournalSuggestModal } from "@/components/suggests/journal-suggest"; | ||
|
||
export async function openDate( | ||
date: string, | ||
journals: { id: string; name: string }[], | ||
event?: MouseEvent, | ||
): Promise<void> { | ||
if (!journals.length) return; | ||
if (journals.length === 1) { | ||
const [{ id }] = journals; | ||
await openDateInJournal(date, id); | ||
return; | ||
} | ||
|
||
if (event) { | ||
const menu = new Menu(); | ||
for (const journal of journals) { | ||
menu.addItem((item) => { | ||
item.setTitle(journal.name).onClick(() => { | ||
openDateInJournal(date, journal.id); | ||
}); | ||
}); | ||
} | ||
menu.showAtMouseEvent(event); | ||
} else { | ||
new JournalSuggestModal(app$.value, journals, (journalId) => openDateInJournal(date, journalId)).open(); | ||
} | ||
} | ||
|
||
export async function openDateInJournal(date: string, journalId: string): Promise<void> { | ||
const journal = plugin$.value.getJournal(journalId); | ||
if (!journal) return; | ||
const metadata = await journal.find(date); | ||
if (!metadata) return; | ||
await journal.open(metadata); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.