tangled
alpha
login
or
join now
izquiratops.bsky.social
/
dictionary-backend
0
fork
atom
English/Japanese dictionary
0
fork
atom
overview
issues
pulls
pipelines
empty results template fix, style changes
izquiratops.bsky.social
3 weeks ago
02e81919
98cb90b0
+34
-20
4 changed files
expand all
collapse all
unified
split
internal
adapters
primary
http
templates
base.html
partials
search_results.html
application
usecases
search.go
web
static
css
style.css
+12
-1
internal/adapters/primary/http/templates/base.html
···
1
1
<!DOCTYPE html>
2
2
<html lang="en">
3
3
+
3
4
<head>
4
5
<meta charset="UTF-8">
5
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
···
7
8
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon.ico">
8
9
<link rel="stylesheet" href="/static/css/style.css">
9
10
<script src="/static/js/htmx.min.js"></script>
11
11
+
<script>
12
12
+
document.addEventListener('keydown', (e) => {
13
13
+
if (e.key === '/') {
14
14
+
alert('!'); // TODO: Implement search focus here. But move it to a js file.
15
15
+
e.preventDefault(); // Prevent "/" from being typed into the input
16
16
+
}
17
17
+
});
18
18
+
</script>
10
19
</head>
20
20
+
11
21
<body>
12
22
<div class="container">
13
23
{{block "content" .}}{{end}}
14
24
</div>
15
25
</body>
16
16
-
</html>
26
26
+
27
27
+
</html>
+2
-2
internal/adapters/primary/http/templates/partials/search_results.html
···
1
1
-
{{if .Entries}}
1
1
+
{{if and .Entries (gt (len .Entries) 0)}}
2
2
<div class="results-list">
3
3
<p class="results-count">Found {{len .Entries}} entries</p>
4
4
···
46
46
</div>
47
47
{{else}}
48
48
<div class="no-results">
49
49
-
<p>{{if .Error}}{{.Error}}{{else}}No results found. Try another search term.{{end}}</p>
49
49
+
<p>No results found. Try another search term.</p>
50
50
</div>
51
51
{{end}}
+7
-2
internal/application/usecases/search.go
···
35
35
36
36
func (uc *SearchUseCase) Execute(ctx context.Context, req *SearchRequest) (*SearchResponse, error) {
37
37
ids, _ := uc.index.Search(req.Term, req.Limit)
38
38
-
entries, _ := uc.repo.GetByIDs(ctx, ids)
39
39
-
return &SearchResponse{Entries: entries}, nil
38
38
+
39
39
+
if len(ids) == 0 {
40
40
+
return &SearchResponse{Entries: nil}, nil
41
41
+
} else {
42
42
+
entries, _ := uc.repo.GetByIDs(ctx, ids)
43
43
+
return &SearchResponse{Entries: entries}, nil
44
44
+
}
40
45
}
+13
-15
web/static/css/style.css
···
4
4
--font-size: 1rem;
5
5
6
6
/* Color */
7
7
-
--background-color: #fff;
8
8
-
--layout-separator-color: #e0e0e0;
9
9
-
--layout-form-color: #ccc;
7
7
+
--background-color: #99D19C;
10
8
--text-main-color: #000;
11
11
-
--text-accent-color: #0066cc;
9
9
+
--text-accent-color: #73AB84;
12
10
--text-alt-color: #666;
13
11
14
12
/* Spacing */
···
73
71
}
74
72
75
73
.search-container input[type="search"] {
76
76
-
width: 100%;
77
77
-
padding: var(--spacing-sm);
74
74
+
border-radius: 2px;
75
75
+
border: 2px solid black;
76
76
+
box-shadow: 6px 6px 0px 0px black;
78
77
font-size: var(--font-size-md);
79
79
-
border: 2px solid var(--layout-form-color);
80
80
-
border-radius: 6px;
78
78
+
padding: var(--spacing-sm);
79
79
+
width: 100%;
81
80
}
82
81
83
82
.search-container input[type="search"]:focus {
···
113
112
}
114
113
115
114
.entry {
116
116
-
border-bottom: 2px solid var(--layout-separator-color);
117
117
-
padding-bottom: var(--spacing-xl);
115
115
+
background: white;
116
116
+
border: 2px solid black;
117
117
+
border-radius: 2px;
118
118
+
box-shadow: 6px 6px 0px 0px black;
119
119
+
padding: var(--spacing-md);
120
120
+
margin-bottom: var(--spacing-xl);
118
121
}
119
122
120
123
.entry:last-child {
···
169
172
font-size: var(--font-size-sm);
170
173
color: var(--text-alt-color);
171
174
margin-bottom: var(--spacing-xxs);
172
172
-
}
173
173
-
174
174
-
.glosses {
175
175
-
list-style: disc;
176
176
-
padding-left: var(--spacing-lg);
177
175
}
178
176
179
177
.gloss {