# SamCloud Dashboard - Common Issues & Fixes

## File Browser Issues

### Issue: File Browser shows "Loading..." indefinitely
**Symptoms:** File Browser view shows "Loading... Please wait while we load your files" and never displays drives

**Root Cause:** Duplicate `loadFiles()` functions in `dashboard_sensei.html` with conflicting API endpoints

**Fix:**
1. Check for duplicate `loadFiles` function definitions in the template
2. Remove any duplicate that calls `/api/browse` (incorrect endpoint)
3. Keep only the function that calls `/api/files/browse` (correct endpoint)
4. Rebuild container: `docker-compose up -d --build`

**How to verify fix:**
```bash
# Test API directly
curl -s "http://localhost:8383/api/files/browse?path=/Volumes" | jq '.items[].name'

# Check for duplicate functions
grep -n "function loadFiles" templates/dashboard_sensei.html
```

### Issue: localhost:8383 connection refused
**Symptoms:** Cannot access dashboard at localhost:8383

**Root Cause:** Docker container using `network_mode: host` prevents proper port binding

**Fix:**
1. Remove `network_mode: host` from `docker-compose.yml`
2. Ensure ports mapping is present: `"8383:8383"`
3. Restart container: `docker-compose down && docker-compose up -d --build`

## Container Issues

### Issue: Published ports discarded warning
**Symptoms:** Warning "Published ports are discarded when using host network mode"

**Root Cause:** Conflicting configuration - both `network_mode: host` and `ports` mapping

**Fix:** Choose one networking approach:
- For host access: Remove `network_mode: host`, keep `ports: ["8383:8383"]`
- For host network: Remove `ports` mapping, keep `network_mode: host`

## API Issues

### Issue: System monitoring fails inside container
**Symptoms:** Errors like "system_profiler: No such file or directory"

**Root Cause:** macOS system tools not available inside Linux container

**Solution:** Expected behavior - system monitoring works partially in containerized environment

## Recovery Procedures

### Restore from backup
```bash
# If you have a working backup
cp "/path/to/backup/dashboard_sensei.html" templates/dashboard_sensei.html
docker-compose up -d --build
```

### Reset to last working state
```bash
# Check git history if available
git log --oneline templates/dashboard_sensei.html

# Or restore from timestamped backup
ls templates/dashboard_sensei.html.bak.*
cp templates/dashboard_sensei.html.bak.TIMESTAMP templates/dashboard_sensei.html
```

## Quick Diagnostics

### Check container status
```bash
docker ps --filter "name=samcloud-dashboard"
docker logs --tail 50 samcloud-dashboard
```

### Test API endpoints
```bash
# File browser API
curl -s "http://localhost:8383/api/files/browse?path=/Volumes" | jq '.items | length'

# System API  
curl -s "http://localhost:8383/api/system" | jq '.hostname'
```

### Check port usage
```bash
lsof -nP -iTCP:8383 -sTCP:LISTEN
```

## File Locations

- Main template: `templates/dashboard_sensei.html`
- Docker config: `docker-compose.yml`
- Flask app: `samcloud_app.py`
- Backups: `templates/dashboard_sensei.html.bak.*`

---
*Last updated: September 11, 2025*
*Critical fix: Remove duplicate loadFiles() functions with wrong API endpoint*
