iaremarkus_wol-reference-vi.../ReferenceModal.ts
Mark Bloomfield 1e6737fc62 Address automated plugin review feedback
- Replace fetch with requestUrl (Obsidian API requirement)
- Remove CSS style injection; Obsidian loads styles.css automatically
- Remove console.log; use only warn/error/debug
- Mark all unhandled promises with void operator
- Remove unnecessary async keywords from methods without await
- Fix rightSplit type cast (any → proper union type)
- Fix querySelector type assertions to use generic form
- Move remaining inline styles to CSS
- Fix sentence case in UI text (Modal dialog, View on wol.jw.org)
- Fix while-loop assignment expression lint warning

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 14:35:56 +02:00

71 lines
1.9 KiB
TypeScript

import { App, ButtonComponent, Modal } from 'obsidian';
import { ReferenceData, appendHTML } from './types';
import { fetchReference } from './referenceService';
export class ReferenceModal extends Modal {
verseRef: string;
data: ReferenceData | null;
loading: boolean;
constructor(app: App, verseRef: string) {
super(app);
this.verseRef = verseRef;
this.data = null;
this.loading = true;
}
onOpen() {
const { contentEl } = this;
contentEl.empty();
contentEl.addClass('ref-modal');
this.titleEl.setText(this.verseRef);
this.displayMessage();
void this.fetchAndDisplay();
}
onClose() {
this.contentEl.empty();
}
private displayMessage() {
const { contentEl } = this;
contentEl.empty();
if (this.loading) {
contentEl.createEl('p', { text: 'Loading\u2026' });
return;
}
if (!this.data) {
contentEl.createEl('p', { text: 'Error loading reference.' });
return;
}
if (this.data.results.length === 0) {
contentEl.createEl('p', { text: 'No results found.' });
} else {
for (const html of this.data.results) {
appendHTML(contentEl.createDiv({ cls: 'ref-modal-result' }), html);
}
}
const buttonContainer = contentEl.createDiv({ cls: 'ref-modal-button-container' });
new ButtonComponent(buttonContainer)
.setButtonText('View on wol.jw.org')
.setCta()
.onClick(() => {
window.open(
`https://wol.jw.org/en/wol/l/r1/lp-e?q=${encodeURIComponent(this.verseRef)}`,
'_blank'
);
});
}
private async fetchAndDisplay() {
this.data = await fetchReference(this.verseRef);
this.loading = false;
this.displayMessage();
}
}