Skip to content

Commit

Permalink
feat: Handling absence of suggests gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
ViBiOh committed Oct 28, 2020
1 parent efc14b7 commit 1db3a99
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
7 changes: 4 additions & 3 deletions pkg/renderer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/ViBiOh/httputils/v3/pkg/httperror"
"github.com/ViBiOh/httputils/v3/pkg/logger"
"github.com/ViBiOh/httputils/v3/pkg/templates"
"github.com/ViBiOh/ketchup/pkg/model"
)
Expand Down Expand Up @@ -40,10 +41,10 @@ func (a app) getData(r *http.Request) (interface{}, error) {

suggests, err := a.repositoryService.Suggest(r.Context(), ketchupIds, min(suggestThresold-ketchupsCount, suggestCount))
if err != nil {
return nil, err
logger.Warn("unable to get suggest repositories: %s", err)
} else {
datas["Suggests"] = suggests
}

datas["Suggests"] = suggests
}

return datas, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/renderer/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a app) publicHandler(w http.ResponseWriter, r *http.Request, status int, m

suggests, err := a.repositoryService.Suggest(r.Context(), []uint64{0}, 3)
if err != nil {
logger.Warn("unable to get suggest repositories: %s", err)
logger.Warn("unable to get publics suggestions: %s", err)
}

content := map[string]interface{}{
Expand Down
1 change: 0 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ <h2>Receive an email digest of your Github dependencies updates every day at 8am
No ads, free. Because being update-to-date must be accessible to everyone.
</em>

<h3>Suggestions</h3>
{{ template "suggests" . }}

{{ template "signup" . }}
Expand Down
68 changes: 36 additions & 32 deletions templates/suggest.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
{{ define "suggests" }}
<style type="text/css">
.ketchups {
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: .5rem;
}
{{ if .Suggests }}
<style type="text/css">
.ketchups {
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: .5rem;
}

.ketchup {
border: 1px dashed var(--success);
display: inline-flex;
flex-direction: column;
height: 15rem;
width: 24rem;
}
.ketchup {
border: 1px dashed var(--success);
display: inline-flex;
flex-direction: column;
height: 15rem;
width: 24rem;
}

.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>

<aside class="ketchups">
{{ range .Suggests }}
<div class="ketchup center">
<h2 class="header small ellipsis">{{ .Name }}</h2>
<h3>Suggestions</h3>

<div class="ketchup__version">
<span>
<a href="https://github.com/{{ .Name }}/releases/tag/{{ .Version }}" target="_blank" rel="noopener noreferrer">{{ .Version }}</a>
</span>
<aside class="ketchups">
{{ range .Suggests }}
<div class="ketchup center">
<h2 class="header small ellipsis">{{ .Name }}</h2>

<div class="ketchup__version">
<span>
<a href="https://github.com/{{ .Name }}/releases/tag/{{ .Version }}" target="_blank" rel="noopener noreferrer">{{ .Version }}</a>
</span>
</div>
</div>
</div>
{{ end }}
</aside>
{{ end }}
</aside>
{{ end }}
{{ end }}

0 comments on commit 1db3a99

Please sign in to comment.