Skip to content

Commit

Permalink
Make sure there's an empty state when listing distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed May 10, 2024
1 parent d594836 commit b130bb6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions PWA/public/RouteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RouteEvents.home = "/index.html";
RouteEvents.distributionsHome = "/distrib.html";
RouteEvents.nameDistribution = "/name_distrib.html";
RouteEvents.listDistributions = "/list_distrib.html";
RouteEvents.listDistributionsEmptyState = "no_distrib.html";
RouteEvents.deleteDistribution = "/list_distrib_delete.html";
RouteEvents.uploadData = "/upload_data.html";
RouteEvents.viewData = "/view_data.html";
Expand Down
1 change: 1 addition & 0 deletions PWA/public/Services/CacheFilePathService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class CacheFilePathService {
RouteEvents.distributionsHome,
RouteEvents.nameDistribution,
RouteEvents.listDistributions,
RouteEvents.listDistributionsEmptyState,
RouteEvents.deleteDistribution,
RouteEvents.uploadData,
RouteEvents.uploadDataError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ export class ListDistributionRequestHandler extends ActiveSessionContainer {
try {
const distributions = await this.activeSession.database.readDistributions();
console.log(distributions);
return ResponseTools.replaceTemplateKeysWithValues(await fetch(RouteEvents.listDistributions), {
columns: Distribution.colums,
rows: distributions
});
if (distributions.length > 0) {
return ResponseTools.replaceTemplateKeysWithValues(await fetch(RouteEvents.listDistributions), {
columns: Distribution.colums,
rows: distributions
});
}
else {
return ResponseTools.wrapInHtmlTemplate(RouteEvents.listDistributionsEmptyState);
}
}
catch {
console.log("something went wrong");
Expand Down
9 changes: 9 additions & 0 deletions PWA/public/no_distrib.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="column is-4 is-offset-4">
<div class="box">
<label class="label is-medium">No distributions found!</label>
<br>
<form action="/name_distrib" method="GET">
<button class="button is-block is-info is-medium is-fullwidth">Create new distribution</button>
</form>
</div>
</div>
1 change: 1 addition & 0 deletions PWA/src/RouteEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export class RouteEvents {
static distributionsHome = "/distrib.html"
static nameDistribution = "/name_distrib.html"
static listDistributions = "/list_distrib.html"
static listDistributionsEmptyState = "no_distrib.html"
static deleteDistribution = "/list_distrib_delete.html"
static uploadData = "/upload_data.html"
static viewData = "/view_data.html"
Expand Down
1 change: 1 addition & 0 deletions PWA/src/Services/CacheFilePathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class CacheFilePathService {
RouteEvents.distributionsHome,
RouteEvents.nameDistribution,
RouteEvents.listDistributions,
RouteEvents.listDistributionsEmptyState,
RouteEvents.deleteDistribution,
RouteEvents.uploadData,
RouteEvents.uploadDataError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ export class ListDistributionRequestHandler extends ActiveSessionContainer imple
try {
const distributions: Distribution[] = await this.activeSession.database.readDistributions()
console.log(distributions)
return ResponseTools.replaceTemplateKeysWithValues(
await fetch(RouteEvents.listDistributions), {
columns: Distribution.colums,
rows: distributions
})

if(distributions.length > 0) {
return ResponseTools.replaceTemplateKeysWithValues(
await fetch(RouteEvents.listDistributions), {
columns: Distribution.colums,
rows: distributions
})
} else {
return ResponseTools.wrapInHtmlTemplate(
RouteEvents.listDistributionsEmptyState
)
}
} catch {
console.log("something went wrong")
}
Expand Down

0 comments on commit b130bb6

Please sign in to comment.