Skip to content

Commit

Permalink
fix: data updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdransf committed Oct 31, 2024
1 parent d53d3d3 commit a45ad87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions api-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ class ApiText extends HTMLElement {
this.applyTransition(content);
this.hideAll(loading, content);

if (cache) {
this.loadContent(JSON.parse(cache), loading, content);
} else {
this.fetchAndSetContent(loading, content, cacheKey);
}
if (cache) this.loadContent(JSON.parse(cache), loading, content);

await this.fetchAndUpdateContent(loading, content, cacheKey);
}

hideAll(loading, content) {
Expand Down Expand Up @@ -91,16 +89,17 @@ class ApiText extends HTMLElement {
content.style.display = this.display;
}

async fetchAndSetContent(loading, content, cacheKey) {
async fetchAndUpdateContent(loading, content, cacheKey) {
try {
const data = await this.data;
const value = data.content || "";

if (value) {
this.storage.setItem(cacheKey, JSON.stringify(value));
this.loadContent(value, loading, content);
} else {
this.loadFallbackContent(loading, content);
}

this.loadContent(value, loading, content);
} catch {
this.loadFallbackContent(loading, content);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cdransf/api-text",
"version": "1.8.0",
"version": "1.8.1",
"description": "A web component to load text from an API and display it.",
"main": "api-text.js",
"repository": {
Expand Down

0 comments on commit a45ad87

Please sign in to comment.