Skip to content

Commit 8aa074f

Browse files
committed
Fix adding note
1 parent 846aa65 commit 8aa074f

File tree

8 files changed

+50
-27
lines changed

8 files changed

+50
-27
lines changed

components/add_note.templ

Lines changed: 0 additions & 9 deletions
This file was deleted.

components/filter.templ

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
)
66

77
templ filter() {
8-
<form class="ml-3 mr-3 mt-3 flex items-center space-x-2">
8+
<form
9+
class="ml-3 mr-3 mt-3 flex items-center space-x-2"
10+
>
911
<div class="w-full">
1012
<label for="company" class="block text-sm font-medium leading-6 text-gray-900">Company</label>
1113
<div class="mt-2">

components/jobs.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ templ JobDetails(j types.JobApplication, timelineEntries []types.JobApplicationT
154154
</form>
155155
@Timeline(timelineEntries, "")
156156
<div class="mt-6 flex gap-x-3">
157-
@note(j.ID, timelineEntries)
157+
@note(j.ID)
158158
</div>
159159
}
160160

components/note.templ

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ package components
22

33
import (
44
"strconv"
5-
"github.com/Piszmog/pathwise/types"
6-
"github.com/Piszmog/pathwise/utils"
75
)
86

9-
templ note(id int, timelineEntries []types.JobApplicationTimelineEntry) {
7+
templ note(id int) {
108
<form
119
id="note-form"
1210
class="relative flex-auto"
1311
hx-post={ "/jobs/" + strconv.Itoa(id) + "/notes" }
1412
hx-on::after-request="this.reset()"
13+
hx-target="#timeline-list"
14+
hx-swap="afterbegin"
1515
>
16-
<input type="hidden" name="firstTimelineEntryID" value={ strconv.Itoa(utils.GetFirstElementID(timelineEntries)) }/>
17-
<input type="hidden" name="firstTimelineEntryType" value={ string(utils.GetFirstElementType(timelineEntries)) }/>
1816
<div
1917
class="overflow-hidden rounded-lg pb-12 shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-blue-600"
2018
>

components/timeline.templ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ templ Timeline(entries []types.JobApplicationTimelineEntry, oob string) {
99
<div id="timeline" class="flow-root" hx-swap-oob={ oob }>
1010
<ul id="timeline-list" role="list" class="-mb-8">
1111
for i, entry := range entries {
12-
@timelineEntry(entry, i == len(entries) - 1)
12+
@TimelineEntry(entry, i == len(entries) - 1)
1313
}
1414
</ul>
1515
</div>
1616
}
1717

18-
templ timelineEntry(entry types.JobApplicationTimelineEntry, isLast bool) {
18+
templ TimelineEntry(entry types.JobApplicationTimelineEntry, isLast bool) {
1919
switch v := entry.(type) {
2020
case types.JobApplicationStatusHistory:
2121
@timelineEntryStatus(v, isLast)

components/update_job.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ templ UpdateJob(j types.JobApplication, s *types.StatsOpts, newTimelineEntry typ
88
}
99
if newTimelineEntry.SwapOOB != "" {
1010
<div hx-swap-oob={ newTimelineEntry.SwapOOB }>
11-
@timelineEntry(newTimelineEntry.Entry, false)
11+
@TimelineEntry(newTimelineEntry.Entry, false)
1212
</div>
1313
}
1414
@job(j)

handlers/handler.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,44 @@ func (h *Handler) Jobs(w http.ResponseWriter, r *http.Request) {
5757
m.Render(r.Context(), w)
5858
}
5959

60+
func (h *Handler) FilterJobs(w http.ResponseWriter, r *http.Request) {
61+
queries := r.URL.Query()
62+
pageQuery := queries.Get("page")
63+
perPageQuery := queries.Get("per_page")
64+
page := 0
65+
var err error
66+
if pageQuery != "" {
67+
page, err = strconv.Atoi(pageQuery)
68+
if err != nil {
69+
w.WriteHeader(http.StatusBadRequest)
70+
return
71+
}
72+
}
73+
perPage := 10
74+
if perPageQuery != "" {
75+
perPage, err = strconv.Atoi(perPageQuery)
76+
if err != nil {
77+
w.WriteHeader(http.StatusBadRequest)
78+
return
79+
}
80+
}
81+
jobs, err := h.JobApplicationStore.Get(r.Context(), store.GetOpts{Page: page, PerPage: perPage})
82+
if err != nil {
83+
w.WriteHeader(http.StatusInternalServerError)
84+
return
85+
}
86+
statsOpts, err := h.StatsStore.Get(r.Context())
87+
if err != nil {
88+
w.WriteHeader(http.StatusInternalServerError)
89+
return
90+
}
91+
m := components.Main(
92+
jobs,
93+
statsOpts,
94+
)
95+
m.Render(r.Context(), w)
96+
}
97+
6098
func (h *Handler) JobDetails(w http.ResponseWriter, r *http.Request) {
6199
vars := mux.Vars(r)
62100
id, err := strconv.Atoi(vars["id"])
@@ -220,8 +258,6 @@ func (h *Handler) AddNote(w http.ResponseWriter, r *http.Request) {
220258
w.WriteHeader(http.StatusBadRequest)
221259
return
222260
}
223-
firstTimelineEntryID := r.FormValue("firstTimelineEntryID")
224-
firstTimelineEntryType := r.FormValue("firstTimelineEntryType")
225261

226262
jobNote := types.JobApplicationNote{
227263
JobApplicationID: id,
@@ -232,10 +268,5 @@ func (h *Handler) AddNote(w http.ResponseWriter, r *http.Request) {
232268
w.WriteHeader(http.StatusInternalServerError)
233269
return
234270
}
235-
components.AddNote(
236-
types.NewTimelineEntry{
237-
SwapOOB: "beforebegin:#" + newTimelineID(firstTimelineEntryType, firstTimelineEntryID),
238-
Entry: n,
239-
},
240-
).Render(r.Context(), w)
271+
components.TimelineEntry(n, false).Render(r.Context(), w)
241272
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func main() {
4040
r.PathPrefix("/assets/").Handler(http.FileServer(http.FS(assets)))
4141
r.HandleFunc("/", handler.Jobs).Methods(http.MethodGet)
4242
r.HandleFunc("/jobs", handler.AddJob).Methods(http.MethodPost)
43+
r.HandleFunc("/jobs", handler.FilterJobs).Methods(http.MethodPost)
4344
r.HandleFunc("/jobs/{id}", handler.JobDetails).Methods(http.MethodGet)
4445
r.HandleFunc("/jobs/{id}", handler.UpdateJob).Methods(http.MethodPatch)
4546
r.HandleFunc("/jobs/{id}/notes", handler.AddNote).Methods(http.MethodPost)

0 commit comments

Comments
 (0)