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}}
|
{{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
|
```go
|
||||||
type PageData struct {
|
// FilterOption represents a filter radio option for the sidebar.
|
||||||
// ... 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
|
|
||||||
type FilterOption struct {
|
type FilterOption struct {
|
||||||
Label string
|
Label string
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] **Step 4: Update FromResponse to accept filter params**
|
Then update `PageData` struct to include new fields:
|
||||||
|
|
||||||
Update `FromResponse` signature to accept `activeCategory`, `activeTime`, and `activeType` from the request. First update the `Search` handler in `handlers.go` to pass these params:
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// In handlers.go, update Search handler:
|
type PageData struct {
|
||||||
pd := views.FromResponse(resp, req.Query, req.Pageno)
|
// ... existing fields (SourceURL, Query, Pageno, etc.) ...
|
||||||
pd.ActiveCategory = r.FormValue("category")
|
|
||||||
pd.ActiveTime = r.FormValue("time")
|
// New fields for three-column layout
|
||||||
pd.ActiveType = r.FormValue("type")
|
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
|
```go
|
||||||
func FromResponse(resp contracts.SearchResponse, query string, pageno int, activeCategory, activeTime, activeType string) PageData {
|
func FromResponse(resp contracts.SearchResponse, query string, pageno int, activeCategory, activeTime, activeType string) PageData {
|
||||||
|
// Set defaults
|
||||||
|
if activeCategory == "" {
|
||||||
|
activeCategory = "all"
|
||||||
|
}
|
||||||
|
|
||||||
pd := PageData{
|
pd := PageData{
|
||||||
// ... existing initialization ...
|
// ... existing initialization (NumberOfResults, Results, etc.) ...
|
||||||
|
|
||||||
// New: categories with icons
|
// New: categories with icons
|
||||||
Categories: []string{"all", "news", "images", "videos", "maps"},
|
Categories: []string{"all", "news", "images", "videos", "maps"},
|
||||||
|
|
@ -536,7 +536,6 @@ func FromResponse(resp contracts.SearchResponse, query string, pageno int, activ
|
||||||
"weather": "🌤️",
|
"weather": "🌤️",
|
||||||
},
|
},
|
||||||
ActiveCategory: activeCategory,
|
ActiveCategory: activeCategory,
|
||||||
if activeCategory == "" { activeCategory = "all" }
|
|
||||||
|
|
||||||
// Time filters
|
// Time filters
|
||||||
TimeFilters: []FilterOption{
|
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**
|
- [ ] **Step 5: Update results.html sidebar to show disabled state**
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue