feat(web): real channel filter — multi-select of the user's channels
The free-text 'channel' filter was dead: it exact-matched SummaryRow.Channel,
which is just the provider ('youtube'), because videos never stored their source
channel. Now they do.
- migration 014: videos.channel_title (nullable; existing rows backfill on the
next discovery pass, pasted videos immediately).
- discovery (NewVideos) + paste (VideoByID) populate channel_title; UpsertVideo
persists it, preserving an existing title when an update arrives empty.
- store.DistinctChannels lists a user's channels (RLS-scoped); SummaryRow carries
ChannelTitle via the shared projection.
- Filter: single Channel -> Channels []string, matching on ChannelTitle; the feed
renders a multi-select of DistinctChannels (hidden until channels exist).
- migrate tests: 014 reversibility + fixed the relative-step counts in the 010/011
up/down tests (014 shifted the topology).
TDD throughout: channel persist + distinct, adapter channel wiring, multi-channel
filter match, handler channel filter, migration up/down.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+26
-4
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
@@ -469,7 +470,7 @@ func (b listBuckets) empty() bool {
|
||||
// Dates are kept as the raw YYYY-MM-DD strings so the form re-renders the user's
|
||||
// input verbatim; parsing happens in matchFilter.
|
||||
type Filter struct {
|
||||
Channel string
|
||||
Channels []string // selected channel titles; empty = all channels
|
||||
From string
|
||||
To string
|
||||
OnlySummarized bool // show only videos that have a summary
|
||||
@@ -480,7 +481,28 @@ type Filter struct {
|
||||
// filter) the bar is hidden so the connect CTA stands alone (UX review C1); a
|
||||
// filter that happens to match nothing still shows the bar so it can be cleared.
|
||||
func (f Filter) active() bool {
|
||||
return f.Channel != "" || f.From != "" || f.To != "" || f.OnlySummarized
|
||||
return len(f.Channels) > 0 || f.From != "" || f.To != "" || f.OnlySummarized
|
||||
}
|
||||
|
||||
// HasChannel reports whether a channel is currently selected (drives the
|
||||
// multi-select's selected state in the view).
|
||||
func (f Filter) HasChannel(c string) bool {
|
||||
return slices.Contains(f.Channels, c)
|
||||
}
|
||||
|
||||
// nonEmptyStrings drops blank entries. A channel multi-select submits real
|
||||
// channel titles; this guards against a stray empty value reaching the filter.
|
||||
func nonEmptyStrings(ss []string) []string {
|
||||
out := ss[:0:0]
|
||||
for _, s := range ss {
|
||||
if strings.TrimSpace(s) != "" {
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// matches reports whether a row satisfies the filter. Channel is an exact match;
|
||||
@@ -491,7 +513,7 @@ func (f Filter) matches(r store.SummaryRow) bool {
|
||||
if f.OnlySummarized && !r.Summarized {
|
||||
return false
|
||||
}
|
||||
if f.Channel != "" && r.Channel != f.Channel {
|
||||
if len(f.Channels) > 0 && !slices.Contains(f.Channels, r.ChannelTitle) {
|
||||
return false
|
||||
}
|
||||
if from, ok := parseDate(f.From); ok {
|
||||
@@ -521,7 +543,7 @@ func parseDate(s string) (time.Time, bool) {
|
||||
|
||||
// apply returns the subset of rows matching the filter, preserving order.
|
||||
func (f Filter) apply(rows []store.SummaryRow) []store.SummaryRow {
|
||||
if f.Channel == "" && f.From == "" && f.To == "" && !f.OnlySummarized {
|
||||
if len(f.Channels) == 0 && f.From == "" && f.To == "" && !f.OnlySummarized {
|
||||
return rows
|
||||
}
|
||||
out := rows[:0:0]
|
||||
|
||||
Reference in New Issue
Block a user