Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 4ab35d8

Browse files
committed
refactor: convert fetch calls to async/await in main.ts
1 parent b34c98e commit 4ab35d8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

main.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class CssSnippetStore extends Plugin {
1818

1919
observer: MutationObserver;
2020

21-
onload() {
21+
async onload() {
2222
// Start the mutation observer when the plugin is loaded.
2323
this.injectWhenSettingsLoaded();
2424

@@ -27,11 +27,8 @@ export default class CssSnippetStore extends Plugin {
2727
const url = "https://raw.githubusercontent.com/xavwe/obsidian-css-snippet-store/refs/heads/main/snippets.json"
2828
try {
2929
if (navigator.onLine) {
30-
fetch(url)
31-
.then(r => r.json())
32-
.then(t => {
33-
this.snippets = t;
34-
})
30+
const response = await fetch(url);
31+
const data = await response.json();
3532
} else {
3633
new Notice(`No Internet connection...`);
3734
return;
@@ -165,17 +162,14 @@ class CssSnippetStoreModal extends Modal {
165162
const button = buttonWrapper.createEl('button', { text: 'Install', cls: 'mod-cta' });
166163

167164
// Attach event listener
168-
button.addEventListener('click', () => {
165+
button.addEventListener('click', async () => {
169166
let code;
170167
const url = "https://raw.githubusercontent.com/" + snippet.repo + "/refs/heads/main/" + snippet.folder + "/snippet.css"
171168
try {
172169
if (navigator.onLine) {
173-
fetch(url)
174-
.then( r => r.text() )
175-
.then( t => {
176-
code = t;
177-
this.install(snippet.id , code);
178-
})
170+
const response = await fetch(url);
171+
const code = await response.text();
172+
await this.install(snippet.id, code);
179173
} else {
180174
new Notice(`No Internet connection...`);
181175
return;

0 commit comments

Comments
 (0)