# SPRINT 10.8 — FOLDERS & SEARCH

## METADATA
- Execution: Hodina 8
- Prerekvizity: Sprint 10.7 COMPLETE
- Deliverables: Sidebar folders, SearchBar, folder routing
- Estimated time: 45-55 min
- Output folder: Modifikace v existujícím React projektu

## OBJECTIVES
Dokončit folder navigaci a search:
1. Sidebar folders s unread counts (INBOX, SENT, DRAFTS, TRASH, SPAM)
2. Custom folders (user-created)
3. Folder routing (/folder/TRASH, /folder/SPAM)
4. Search bar s full-text search přes emaily
5. Search results stránka
6. Drag-and-drop email přesun mezi foldery (optional)

## STEP-BY-STEP INSTRUCTIONS

### Krok 1: Rozšířit Layout sidebar
**Soubor:** `src/components/Layout.tsx` — update

Sidebar nyní zobrazuje:
```
┌──────────────┐
│ SKYMAILBOX   │
│ user@email   │
├──────────────┤
│ ✏️ Compose    │  ← Primary action button
├──────────────┤
│ 📥 Inbox  (3) │  ← Unread count badge
│ 📤 Sent       │
│ 📝 Drafts (1) │
│ 🗑 Trash      │
│ ⚠️ Spam       │
├──────────────┤
│ 📁 Folders    │
│   Work        │
│   Personal    │
│   + New folder│
├──────────────┤
│ user · tier   │
│ Sign Out      │
└──────────────┘
```

**Funkce:**
- Načíst folders z emailStore.loadFolders() v useEffect
- Unread count badge: amber pill vedle folder name
- Active folder: highlighted (bg-sky-card, border-left amber)
- Click → navigate to `/folder/${folderName}` nebo `/inbox`, `/sent`
- Compose button: prominent amber button nahoře

### Krok 2: Folder route
Přidat do App.tsx router:
```tsx
<Route path="folder/:folderName" element={<Inbox />} />
```

Update Inbox.tsx pro čtení folder z URL:
```ts
const { folderName } = useParams();
// Load emails based on folder
```

### Krok 3: Create folder dialog
**Soubor:** `src/components/CreateFolderDialog.tsx`

Modal dialog:
- Input: "Folder name"
- Create / Cancel buttons
- Volat API (POST /folders s folder name) — nebo localStorage pro MVP
- Po vytvoření: refresh folder list

### Krok 4: Search bar
**Soubor:** `src/components/SearchBar.tsx`

Umístění: nahoře v Layout, nad email listem

Funkce:
- Input s ikonou lupy
- Debounced search (300ms po posledním keystroke)
- Placeholder: "Search emails..."
- Na Enter nebo po debounce → navigate to `/search?q=query`
- Klávesová zkratka: `/` focus search bar

### Krok 5: Search results page
**Soubor:** `src/pages/SearchResults.tsx`

- Číst query z URL search params
- Volat API search endpoint (nebo client-side filter pro MVP)
- Zobrazit výsledky jako EmailListItem
- "X results for 'query'" header
- Empty state: "No emails match your search"

Přidat do App.tsx router:
```tsx
<Route path="search" element={<SearchResults />} />
```

### Krok 6: Email API search extension
Pokud email Lambda ještě nemá search endpoint, přidat do email_lambda.py:

**GET /search?q=query&limit=20**
- Full-text scan přes DynamoDB (subject + body contains query)
- Return: same format jako inbox
- Note: DynamoDB scan je pomalý, ale OK pro MVP. Upgrade na OpenSearch later.

### Krok 7: Testovat
1. Ověřit folder navigace v sidebar
2. Ověřit unread counts
3. Ověřit search bar
4. Test folder routing (/folder/TRASH)
5. Test create new folder
6. Build check

## COMPLETION CHECKLIST
- [ ] Sidebar zobrazuje všechny foldery s unread counts
- [ ] Click na folder načte správné emaily
- [ ] Compose button v sidebar funguje
- [ ] Create folder dialog
- [ ] Search bar s debounce
- [ ] Search results page
- [ ] Folder routing (/folder/:name)
- [ ] Keyboard shortcut `/` pro search
- [ ] Build prochází

## DELIVERABLES LIST
1. `src/components/Layout.tsx` (updated)
2. `src/components/SearchBar.tsx`
3. `src/components/CreateFolderDialog.tsx`
4. `src/pages/SearchResults.tsx`
5. `src/pages/Inbox.tsx` (updated for folder param)
6. `src/App.tsx` (updated routes)
7. `SPRINT_10.8_COMPLETE.md`

## COMPLETION REPORT TEMPLATE
```markdown
# ✅ SPRINT 10.8 — FOLDERS & SEARCH — COMPLETE

## Timestamp
[ISO datetime]

## Components
- Layout.tsx: Updated with folders
- SearchBar.tsx: OK
- CreateFolderDialog.tsx: OK
- SearchResults.tsx: OK

## Features
- Folder navigation: OK/ISSUE
- Unread counts: OK/ISSUE
- Search: OK/ISSUE
- Create folder: OK/ISSUE

## Next Sprint
SPRINT_10.9_INTEGRATION
```
