Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def get_photos(
camera: str | None = None,
date_from: str | None = None,
date_to: str | None = None,
filename_search: str | None = None,
cursor_date: str | None = None,
cursor_id: int | None = None,
limit: int = 100,
Expand All @@ -144,6 +145,7 @@ def get_photos(
camera: Filter by camera model (exact match).
date_from: Filter photos taken on or after this date (YYYY-MM-DD).
date_to: Filter photos taken on or before this date (YYYY-MM-DD).
filename_search: Case-insensitive substring search on filename.
cursor_date: Keyset pagination cursor date_taken.
cursor_id: Keyset pagination cursor photo id.
limit: Max number of results.
Expand All @@ -169,6 +171,9 @@ def get_photos(
if camera is not None:
conditions.append("camera = ?")
params.append(camera)
if filename_search is not None:
conditions.append("filename LIKE ? ESCAPE '\\'")
params.append(f"%{filename_search.replace('%', r'\%').replace('_', r'\_')}%")
if date_from is not None:
conditions.append("REPLACE(date_taken, ':', '-') >= ?")
params.append(date_from)
Expand Down Expand Up @@ -223,6 +228,7 @@ def get_photo_count(
camera: str | None = None,
date_from: str | None = None,
date_to: str | None = None,
filename_search: str | None = None,
) -> int:
"""Return total count of photos matching filters."""
conn = get_connection(db_path)
Expand All @@ -242,6 +248,9 @@ def get_photo_count(
if camera is not None:
conditions.append("camera = ?")
params.append(camera)
if filename_search is not None:
conditions.append("filename LIKE ? ESCAPE '\\'")
params.append(f"%{filename_search.replace('%', r'\%').replace('_', r'\_')}%")
if date_from is not None:
conditions.append("REPLACE(date_taken, ':', '-') >= ?")
params.append(date_from)
Expand Down
4 changes: 4 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def list_photos(
camera: Optional[str] = Query(None),
date_from: Optional[str] = Query(None, pattern=r"^\d{4}-\d{2}-\d{2}$"),
date_to: Optional[str] = Query(None, pattern=r"^\d{4}-\d{2}-\d{2}$"),
filename_search: Optional[str] = Query(None, max_length=255),
cursor_date: Optional[str] = Query(None),
cursor_id: Optional[int] = Query(None),
limit: int = Query(100, ge=1, le=500),
Expand All @@ -283,6 +284,7 @@ def list_photos(
camera=camera,
date_from=date_from,
date_to=date_to,
filename_search=filename_search or None,
cursor_date=cursor_date,
cursor_id=cursor_id,
limit=limit,
Expand All @@ -305,6 +307,7 @@ def count_photos(
camera: Optional[str] = Query(None),
date_from: Optional[str] = Query(None, pattern=r"^\d{4}-\d{2}-\d{2}$"),
date_to: Optional[str] = Query(None, pattern=r"^\d{4}-\d{2}-\d{2}$"),
filename_search: Optional[str] = Query(None, max_length=255),
):
"""Return total count of photos matching filters."""
total = get_photo_count(
Expand All @@ -315,6 +318,7 @@ def count_photos(
camera=camera,
date_from=date_from,
date_to=date_to,
filename_search=filename_search or None,
)
return {"count": total}

Expand Down
53 changes: 51 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { usePhotos } from './hooks/usePhotos'
import { useKeyboardShortcuts } from './hooks/useKeyboardShortcuts'

function App() {
const [filters, setFilters] = useState({ min_rating: null, status: null, dev_status: null, camera: null, date_from: null, date_to: null })
const [filters, setFilters] = useState({ min_rating: null, status: null, dev_status: null, camera: null, date_from: null, date_to: null, filename_search: null })
const [searchInput, setSearchInput] = useState('')
const searchTimerRef = useRef(null)
const [selectedIndex, setSelectedIndex] = useState(null)
const [showSettings, setShowSettings] = useState(false)
const [selectedIds, setSelectedIds] = useState(new Set())
Expand Down Expand Up @@ -39,6 +41,17 @@ function App() {
// Clean up timer on unmount
useEffect(() => () => { if (jumpTimerRef.current) clearTimeout(jumpTimerRef.current) }, [])

const handleSearchChange = useCallback((e) => {
const val = e.target.value
setSearchInput(val)
if (searchTimerRef.current) clearTimeout(searchTimerRef.current)
searchTimerRef.current = setTimeout(() => {
setFilters(prev => ({ ...prev, filename_search: val.trim() || null }))
searchTimerRef.current = null
}, 300)
}, [])
useEffect(() => () => { if (searchTimerRef.current) clearTimeout(searchTimerRef.current) }, [])

const handleScrollToMonth = useCallback((monthKey) => {
const el = document.querySelector(`[data-month="${monthKey}"]`)
if (el) {
Expand Down Expand Up @@ -213,6 +226,34 @@ function App() {
</div>
</div>
<div className="flex items-center gap-2">
{/* Filename search */}
<div className="relative">
<svg className="absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-surface-500 pointer-events-none" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M21 21l-4.35-4.35M17 11A6 6 0 105 11a6 6 0 0012 0z" />
</svg>
<input
type="text"
id="filename-search"
value={searchInput}
onChange={handleSearchChange}
placeholder="Search filenames…"
className="pl-8 pr-3 py-1.5 rounded-lg bg-surface-800/50 border border-surface-700/50
text-surface-200 text-sm placeholder:text-surface-600
focus:outline-none focus:ring-2 focus:ring-indigo-500/40 focus:border-indigo-500/40
hover:bg-surface-800 transition-all w-44"
/>
{searchInput && (
<button
onClick={() => { setSearchInput(''); setFilters(prev => ({ ...prev, filename_search: null })) }}
className="absolute right-2 top-1/2 -translate-y-1/2 text-surface-500 hover:text-surface-300 transition-colors"
aria-label="Clear search"
>
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
)}
</div>
<button onClick={refresh} className="btn-ghost flex items-center gap-2 text-sm" id="refresh-btn">
<svg className={`w-4 h-4 ${loading ? 'animate-spin' : ''}`} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
Expand All @@ -236,7 +277,15 @@ function App() {
</header>

{/* Toolbar */}
<Toolbar filters={filters} onFilterChange={setFilters} photoCount={photos.length} />
<Toolbar
filters={filters}
onFilterChange={setFilters}
onClearAll={() => {
setSearchInput('')
setFilters({ min_rating: null, status: null, dev_status: null, camera: null, date_from: null, date_to: null, filename_search: null })
}}
photoCount={photos.length}
/>

{/* Selection action bar */}
{selectionMode && (
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const inputClass = `bg-surface-800/50 border border-surface-700/50 rounded-lg px
focus:border-indigo-500/40 transition-all hover:bg-surface-800
[&::-webkit-calendar-picker-indicator]:invert [&::-webkit-calendar-picker-indicator]:opacity-50`

export default function Toolbar({ filters, onFilterChange, photoCount }) {
export default function Toolbar({ filters, onFilterChange, onClearAll, photoCount }) {
const [cameras, setCameras] = useState([])

// Fetch available cameras for dropdown
Expand Down Expand Up @@ -67,11 +67,16 @@ export default function Toolbar({ filters, onFilterChange, photoCount }) {
}

const clearFilters = () => {
onFilterChange({ min_rating: null, status: null, dev_status: null, camera: null, date_from: null, date_to: null })
if (onClearAll) {
onClearAll()
} else {
onFilterChange({ min_rating: null, status: null, dev_status: null, camera: null, date_from: null, date_to: null, filename_search: null })
}
}

const hasFilters = filters.min_rating != null || filters.status != null
|| filters.dev_status != null || filters.camera != null || filters.date_from != null || filters.date_to != null
|| filters.filename_search != null

return (
<div className="sticky top-16 z-[30] border-b border-surface-800/40 bg-surface-950">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function usePhotos(filters = {}) {
if (filters.camera) params.set('camera', filters.camera)
if (filters.date_from) params.set('date_from', filters.date_from)
if (filters.date_to) params.set('date_to', filters.date_to)
if (filters.filename_search) params.set('filename_search', filters.filename_search)
params.set('limit', String(PAGE_SIZE))
if (cursor.id != null) {
if (cursor.date != null) {
Expand All @@ -36,7 +37,7 @@ export function usePhotos(filters = {}) {
params.set('direction', cursor.direction)
}
return params
}, [filters.min_rating, filters.status, filters.dev_status, filters.camera, filters.date_from, filters.date_to])
}, [filters.min_rating, filters.status, filters.dev_status, filters.camera, filters.date_from, filters.date_to, filters.filename_search])

const fetchPhotos = useCallback(async (forcedCursor = null) => {
setLoading(true)
Expand Down
Loading