-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathurl-prompt-modal.ts
More file actions
47 lines (36 loc) · 1.17 KB
/
Copy pathurl-prompt-modal.ts
File metadata and controls
47 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Modal, Notice, Setting, type App } from 'obsidian';
export class UrlPromptModal extends Modal {
private onSubmit: (url: string) => void;
constructor(app: App, onSubmit: (url: string) => void) {
super(app);
this.onSubmit = onSubmit;
}
onOpen() {
const { contentEl } = this;
contentEl.empty();
contentEl.createEl('h2', { text: 'Import article' });
let urlValue = '';
new Setting(contentEl).setName('Article URL').addText((text) =>
text.setPlaceholder('https://habr.com/...').onChange((value) => {
urlValue = value.trim();
}),
);
new Setting(contentEl).addButton((button) =>
button
.setButtonText('Download')
.setCta()
.onClick(() => {
if (!urlValue) {
new Notice('Please enter a URL.');
return;
}
this.close();
this.onSubmit(urlValue);
}),
);
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}