Skip to content

Commit d5ce565

Browse files
committed
Improve category edit UI
1 parent 134f1a5 commit d5ce565

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ It's a basic file format. Every command must be on it's own line empty lines are
4747
## Editing
4848

4949
The `/edit` page allows updating the entire bookmark file.
50-
Each category heading on the index page now also includes a small
51-
`edit` link that opens `/editCategory`. This page shows only the selected
50+
Each category heading on the index page now includes a small pencil icon
51+
link that opens `/editCategory`. This page shows only the selected
5252
category text and saves changes back to your bookmarks without touching
5353
other sections. Edits check the file's SHA so you'll get an error if it
5454
changed while you were editing.

bookmarkCategoryEdit_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ func TestExtractCategoryByIndex(t *testing.T) {
2020
}
2121
}
2222

23+
func TestExtractCategoryByIndexFirst(t *testing.T) {
24+
got, err := ExtractCategoryByIndex(testBookmarkText, 0)
25+
if err != nil {
26+
t.Fatalf("unexpected error: %v", err)
27+
}
28+
expected := "Category: A\nhttp://a.com a"
29+
if got != expected {
30+
t.Fatalf("expected %q got %q", expected, got)
31+
}
32+
}
33+
2334
func TestExtractCategoryByIndexError(t *testing.T) {
2435
if _, err := ExtractCategoryByIndex(testBookmarkText, 5); err == nil {
2536
t.Fatalf("expected error")
@@ -38,6 +49,18 @@ func TestReplaceCategoryByIndex(t *testing.T) {
3849
}
3950
}
4051

52+
func TestReplaceCategoryByIndexFirst(t *testing.T) {
53+
newSection := "Category: A\nhttp://changed.com x"
54+
updated, err := ReplaceCategoryByIndex(testBookmarkText, 0, newSection)
55+
if err != nil {
56+
t.Fatalf("unexpected error: %v", err)
57+
}
58+
expected := newSection + "\nColumn\nCategory: B\nhttp://b.com b\n"
59+
if updated != expected {
60+
t.Fatalf("expected %q got %q", expected, updated)
61+
}
62+
}
63+
4164
func TestReplaceCategoryByIndexError(t *testing.T) {
4265
if _, err := ReplaceCategoryByIndex(testBookmarkText, 3, "foo"); err == nil {
4366
t.Fatalf("expected error")

main.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,19 @@ div.title {
9898
border: none;
9999
border-top: 1px solid #800000;
100100
}
101+
102+
.edit-link {
103+
font-size: small;
104+
margin-left: 0.3em;
105+
text-decoration: none;
106+
}
107+
108+
.edit-form textarea {
109+
width: 90vw;
110+
height: 80vh;
111+
font-family: monospace;
112+
}
113+
114+
.category-form textarea {
115+
height: 30vh;
116+
}

templates/edit.gohtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
Error: {{ $.Error }}
55
</p>
66
{{ end }}
7-
<form method=post action="?">
8-
<label for="code">Code</label>:<br/>
9-
<textarea id="code" name="text" rows="30" style="width: 90vw; height: 80vh;">{{bookmarksOrEditBookmarks}}</textarea><br>
7+
<form method=post action="?" class="edit-form">
8+
<label for="code">Code</label><br/>
9+
<textarea id="code" name="text" rows="30">{{bookmarksOrEditBookmarks}}</textarea><br>
1010
<label for="branch">Branch</label>: <input id="branch" type="text" name="branch" value="{{ branchOrEditBranch }}" /><br>
1111
<input type=submit name="task" value="Save" /><br>
1212
<input type=hidden name="ref" value="{{ref}}" />

templates/editCategory.gohtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{{ if $.Error }}
33
<p style="color: #FF0000">Error: {{ $.Error }}</p>
44
{{ end }}
5-
<form method=post action="?index={{$.Index}}">
5+
<form method=post action="?index={{$.Index}}" class="edit-form category-form">
66
<label for="code">Category</label><br/>
7-
<textarea id="code" name="text" rows="10" style="width: 90vw; height: 30vh;">{{$.Text}}</textarea><br>
7+
<textarea id="code" name="text" rows="10">{{$.Text}}</textarea><br>
88
<label for="branch">Branch</label>: <input id="branch" type="text" name="branch" value="{{ branchOrEditBranch }}" /><br>
99
<input type=submit name="task" value="Save" /><br>
1010
<input type=hidden name="ref" value="{{ref}}" />

templates/indexPage.gohtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<td>
1616
{{- range .Categories }}
1717
<ul style="list-style-type: none;">
18-
<h2>{{ .Name }} <a href="/editCategory?index={{ .Index }}&ref={{ref}}" style="font-size: small;">edit</a></h2>
18+
<h2>{{ .Name }} <a class="edit-link" href="/editCategory?index={{ .Index }}&ref={{ref}}" title="Edit">&#9998;</a></h2>
1919
{{- range .Entries }}
2020
<li>
2121
<img src="/proxy/favicon?url={{ .Url }}" alt="" style="width: 1em; max-height: 1em; font-weight: bolder; font-family: -moz-bullet-font;" />

0 commit comments

Comments
 (0)