docs: fix Go syntax errors in implementation plan
- Move if statement outside struct literal in FromResponse - Define FilterOption at package level (not inside function) - Add DisabledCategories to PageData struct - Add defaults handling before struct literal - Update Search handler call with filter params Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8909654c8f
commit
ce92a692f8
1 changed files with 32 additions and 28 deletions
|
|
@ -478,49 +478,49 @@ Replace the entire file content:
|
|||
{{end}}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Update PageData struct to include new fields**
|
||||
- [ ] **Step 3: Add FilterOption struct and update PageData struct**
|
||||
|
||||
Modify `internal/views/views.go` — add to `PageData` struct:
|
||||
Add `FilterOption` struct at package level in `views.go` (near `PageNumber` struct):
|
||||
|
||||
```go
|
||||
type PageData struct {
|
||||
// ... existing fields ...
|
||||
|
||||
// New fields for three-column layout
|
||||
Categories []string
|
||||
CategoryIcons map[string]string
|
||||
ActiveCategory string
|
||||
TimeFilters []FilterOption
|
||||
TypeFilters []FilterOption
|
||||
ActiveTime string
|
||||
ActiveType string
|
||||
}
|
||||
|
||||
// FilterOption represents a filter radio option
|
||||
// FilterOption represents a filter radio option for the sidebar.
|
||||
type FilterOption struct {
|
||||
Label string
|
||||
Value string
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Update FromResponse to accept filter params**
|
||||
|
||||
Update `FromResponse` signature to accept `activeCategory`, `activeTime`, and `activeType` from the request. First update the `Search` handler in `handlers.go` to pass these params:
|
||||
Then update `PageData` struct to include new fields:
|
||||
|
||||
```go
|
||||
// In handlers.go, update Search handler:
|
||||
pd := views.FromResponse(resp, req.Query, req.Pageno)
|
||||
pd.ActiveCategory = r.FormValue("category")
|
||||
pd.ActiveTime = r.FormValue("time")
|
||||
pd.ActiveType = r.FormValue("type")
|
||||
type PageData struct {
|
||||
// ... existing fields (SourceURL, Query, Pageno, etc.) ...
|
||||
|
||||
// New fields for three-column layout
|
||||
Categories []string
|
||||
CategoryIcons map[string]string
|
||||
DisabledCategories []string
|
||||
ActiveCategory string
|
||||
TimeFilters []FilterOption
|
||||
TypeFilters []FilterOption
|
||||
ActiveTime string
|
||||
ActiveType string
|
||||
}
|
||||
```
|
||||
|
||||
Then update `FromResponse` in `views.go` to accept these params:
|
||||
- [ ] **Step 4: Update FromResponse signature and body**
|
||||
|
||||
Update `FromResponse` signature to accept filter params and set defaults:
|
||||
|
||||
```go
|
||||
func FromResponse(resp contracts.SearchResponse, query string, pageno int, activeCategory, activeTime, activeType string) PageData {
|
||||
// Set defaults
|
||||
if activeCategory == "" {
|
||||
activeCategory = "all"
|
||||
}
|
||||
|
||||
pd := PageData{
|
||||
// ... existing initialization ...
|
||||
// ... existing initialization (NumberOfResults, Results, etc.) ...
|
||||
|
||||
// New: categories with icons
|
||||
Categories: []string{"all", "news", "images", "videos", "maps"},
|
||||
|
|
@ -536,7 +536,6 @@ func FromResponse(resp contracts.SearchResponse, query string, pageno int, activ
|
|||
"weather": "🌤️",
|
||||
},
|
||||
ActiveCategory: activeCategory,
|
||||
if activeCategory == "" { activeCategory = "all" }
|
||||
|
||||
// Time filters
|
||||
TimeFilters: []FilterOption{
|
||||
|
|
@ -562,7 +561,12 @@ func FromResponse(resp contracts.SearchResponse, query string, pageno int, activ
|
|||
}
|
||||
```
|
||||
|
||||
Add `DisabledCategories []string` field to `PageData`.
|
||||
Update the `Search` handler in `handlers.go` to pass filter params:
|
||||
|
||||
```go
|
||||
pd := views.FromResponse(resp, req.Query, req.Pageno,
|
||||
r.FormValue("category"), r.FormValue("time"), r.FormValue("type"))
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Update results.html sidebar to show disabled state**
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue