diff --git a/manifest.json b/manifest.json index 9b6ee02..d710e2e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-contacts", "name": "Contacts", - "version": "1.0.0", + "version": "1.0.1", "minAppVersion": "0.15.0", "description": "Allows you to manage and organize your contacts.", "author": "Vadim Beskrovnov", diff --git a/src/file/file.ts b/src/file/file.ts index d15e441..4c355d9 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -1,10 +1,7 @@ -import { normalizePath, Notice, TFile, TFolder, Vault } from "obsidian"; +import { normalizePath, Notice, TFile, TFolder, Vault, Workspace } from "obsidian"; import { join } from "path"; -const { vault } = window.app; - -export async function openFile(file: TFile) { - const { workspace } = window.app; +export async function openFile(file: TFile, workspace: Workspace) { const leaf = workspace.getLeaf() await leaf.openFile(file, { active: true }); } @@ -19,14 +16,14 @@ export function findContactFiles(contactsFolder: TFolder) { return contactFiles; } -export function createContactFile(folderPath: string) { +export function createContactFile(folderPath: string, vault: Vault, workspace: Workspace) { const folder = vault.getAbstractFileByPath(folderPath) if (!folder) { new Notice(`Can not find path: '${folderPath}'. Please update "Contacts" plugin settings`); return; } - vault.create(normalizePath(join(folderPath, `Contact ${findNextFileNumber(folderPath)}.md`)), ` + vault.create(normalizePath(join(folderPath, `Contact ${findNextFileNumber(folderPath, vault)}.md`)), ` /---contact---/ | key | value | | --------- | ----- | @@ -39,10 +36,10 @@ export function createContactFile(folderPath: string) { | Last chat | | | Friends | | /---contact---/`) - .then(createdFile => openFile(createdFile)); + .then(createdFile => openFile(createdFile, workspace)); } -function findNextFileNumber(folderPath: string) { +function findNextFileNumber(folderPath: string, vault: Vault) { const folder = vault.getAbstractFileByPath( normalizePath(folderPath) ) as TFolder; diff --git a/src/parse/parse.ts b/src/parse/parse.ts index d8b2b9a..57cac14 100644 --- a/src/parse/parse.ts +++ b/src/parse/parse.ts @@ -1,10 +1,10 @@ -import { TFile } from "obsidian"; +import { TFile, Vault } from "obsidian"; import { Contact } from "./contact"; -export async function parseContactFiles(files: TFile[]) { +export async function parseContactFiles(files: TFile[], vault: Vault) { const contactsData: Contact[] = []; for (const contactFile of files) { - const contact = await parseContactData(contactFile); + const contact = await parseContactData(contactFile, vault); if (contact) { contactsData.push(contact); } @@ -12,8 +12,7 @@ export async function parseContactFiles(files: TFile[]) { return contactsData; } -async function parseContactData(file: TFile): Promise { - const { vault } = window.app; +async function parseContactData(file: TFile, vault: Vault): Promise { const fileContents = await vault.cachedRead(file); if (!isContactFile(fileContents)) { return null; diff --git a/src/ui/sidebar/components/ContactView.tsx b/src/ui/sidebar/components/ContactView.tsx index de187a2..4afd1e4 100644 --- a/src/ui/sidebar/components/ContactView.tsx +++ b/src/ui/sidebar/components/ContactView.tsx @@ -1,4 +1,5 @@ import * as React from "react"; +import { useApp } from "src/context/hooks"; import { openFile } from "src/file/file"; import { Contact } from "src/parse/contact"; import { daysUntilBirthday, diffDateToday } from "src/util/dates"; @@ -8,9 +9,13 @@ type ContactProps = { }; export const ContactView = (props: ContactProps) => { + const { workspace } = useApp(); const contact = props.contact; return ( -
openFile(contact.file)}> +
openFile(contact.file, workspace)} + >
{contact.name} {contact.lastName} diff --git a/src/ui/sidebar/components/SidebarRootView.tsx b/src/ui/sidebar/components/SidebarRootView.tsx index c8ef3c1..9ecb0c1 100644 --- a/src/ui/sidebar/components/SidebarRootView.tsx +++ b/src/ui/sidebar/components/SidebarRootView.tsx @@ -14,7 +14,7 @@ type RootProps = { }; export const SidebarRootView = (props: RootProps) => { - const { vault } = useApp(); + const { vault, workspace } = useApp(); const [contacts, setContacts] = React.useState([]); const [sort, setSort] = React.useState(Sort.LAST_CONTACT); const folder = props.plugin.settings.contactsFolder; @@ -30,7 +30,7 @@ export const SidebarRootView = (props: RootProps) => { const contactFiles: TFile[] = findContactFiles(contactsFolder); - parseContactFiles(contactFiles).then((contactsData) => + parseContactFiles(contactFiles, vault).then((contactsData) => setContacts(contactsData) ); }, []); @@ -39,7 +39,7 @@ export const SidebarRootView = (props: RootProps) => {
createContactFile(folder)} + onCreateContact={() => createContactFile(folder, vault, workspace)} sort={sort} /> diff --git a/versions.json b/versions.json index 26382a1..a6d5a03 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,4 @@ { - "1.0.0": "0.15.0" -} + "1.0.0": "0.15.0", + "1.0.1": "0.15.0" +} \ No newline at end of file