Skip to content

Commit

Permalink
fix: remove deprecated usages of app
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Sep 13, 2023
1 parent 2efb3be commit 343ff57
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/FormModal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { App, Modal, Setting } from "obsidian";
import FormResult, { type ModalFormData } from "./FormResult";
import { exhaustiveGuard } from "./safety";
import { FileSuggest } from "./suggestFile";
import { get_tfiles_from_folder } from "./utils/files";
import type { FormDefinition } from "./core/formDefinition";
import { FileSuggest } from "./suggesters/suggestFile";

export type SubmitFn = (formResult: FormResult) => void;

Expand Down Expand Up @@ -124,7 +124,7 @@ export class FormModal extends Modal {

case "notes":
return fieldBase.addDropdown((element) => {
const files = get_tfiles_from_folder(fieldInput.folder);
const files = get_tfiles_from_folder(fieldInput.folder, this.app);
const options = files.reduce(
(
acc: Record<string, string>,
Expand Down
28 changes: 0 additions & 28 deletions src/suggestArray.ts

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions src/suggesters/suggestArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { App } from "obsidian";
import { TextInputSuggest } from "./suggest";

export class ArraySuggest extends TextInputSuggest<string> {
content: Set<string>;

constructor(app: App, input: HTMLInputElement, content: Set<string>) {
super(app, input);
this.content = content;
}

getSuggestions(inputStr: string): string[] {
const lowerCaseInputStr = inputStr.toLowerCase();
return [...this.content].filter((content) =>
content.contains(lowerCaseInputStr)
);
}

renderSuggestion(content: string, el: HTMLElement): void {
el.setText(content);
}

selectSuggestion(content: string): void {
this.inputEl.value = content;
this.inputEl.trigger("input");
this.close();
}
}
6 changes: 3 additions & 3 deletions src/suggestFile.ts → src/suggesters/suggestFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { App, TAbstractFile, TFile } from "obsidian";
import { TextInputSuggest } from "./suggest";
import { get_tfiles_from_folder } from "./utils/files";
import { errorWrapperSync } from "./utils/Error";
import { get_tfiles_from_folder } from "../utils/files";
import { errorWrapperSync } from "../utils/Error";

// Instead of hardcoding the logic in separate and almost identical classes,
// we move this little logic parts into an interface and we can use the samme
Expand All @@ -25,7 +25,7 @@ export class FileSuggest extends TextInputSuggest<TFile> {

getSuggestions(input_str: string): TFile[] {
const all_files = errorWrapperSync(
() => get_tfiles_from_folder(this.folder),
() => get_tfiles_from_folder(this.folder, this.app),
"The folder does not exist"
);
if (!all_files) {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/utils/files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TAbstractFile, TFile, TFolder, Vault, normalizePath } from "obsidian";
import { App, TAbstractFile, TFile, TFolder, Vault, normalizePath } from "obsidian";
import { ModalFormError } from "./Error";

export function resolve_tfolder(folder_str: string): TFolder {
export function resolve_tfolder(folder_str: string, app: App): TFolder {
folder_str = normalizePath(folder_str);

const folder = app.vault.getAbstractFileByPath(folder_str);
Expand All @@ -15,7 +15,7 @@ export function resolve_tfolder(folder_str: string): TFolder {
return folder;
}

export function resolve_tfile(file_str: string): TFile {
export function resolve_tfile(file_str: string, app: App): TFile {
file_str = normalizePath(file_str);

const file = app.vault.getAbstractFileByPath(file_str);
Expand All @@ -29,8 +29,8 @@ export function resolve_tfile(file_str: string): TFile {
return file;
}

export function get_tfiles_from_folder(folder_str: string): Array<TFile> {
const folder = resolve_tfolder(folder_str);
export function get_tfiles_from_folder(folder_str: string, app: App): Array<TFile> {
const folder = resolve_tfolder(folder_str, app);

const files: Array<TFile> = [];
Vault.recurseChildren(folder, (file: TAbstractFile) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/FormBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
isValidFormDefinition,
isInputNoteFromFolder,
} from "src/core/formDefinition";
import { FolderSuggest } from "src/suggestFolder";
import { FolderSuggest } from "src/suggesters/suggestFolder";
import { FieldTypeReadable } from "src/views/EditFormView";
import { setIcon, Setting, App } from "obsidian";
import FormRow from "./components/FormRow.svelte";
Expand Down

0 comments on commit 343ff57

Please sign in to comment.