AOSSIE-Org / AOSSIE-Org/PictoPy

Feat: Weekends category in memories section

未關閉
#1,213 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
283
分支
679
平均合併
7 天 2 小時
30 天內合併 PR
3

描述

### Describe the feature

### Description
Added a “Weekends” category in the Memories section to cluster all images that fall within a weekend.
### Current Problem

The Memories section groups photos by **location** and **date**, but there is no way to browse photos specifically from weekends. Users who take most of their photos on weekends (trips, hangouts, events) have no dedicated view to relive those moments as a cohesive group. The existing filter buttons **All**, **Location**, and **Date** do not surface weekend-specific clusters.

### Expected Feature

A new **"Weekends"** filter button in the Memories section that:

- Groups all photos by their ISO calendar week, producing one memory cluster per week that contains images.
- Displays each cluster as a **"Happy Weekends"** card showing the thumbnail of the first photo, the date range of that week's photos, and the total photo count.
- If a cluster spans a single day, shows only that date; otherwise shows **start date – end date**.
- Clicking a card opens a full detail view displaying all photos in that cluster, using the same `ImageCard` grid and `MediaView` full-screen viewer used by the rest of the Memories section.

---

## Implementation

### Backend — `generate_clusters_for_weekends()` in `memory_clustering.py`

A standalone function `generate_clusters_for_weekends()` was added at the bottom of `backend/app/utils/memory_clustering.py`:

1. Fetches all images from the database via `db_get_all_images()`.
2. Sorts images by `metadata.date_created` descending (most recent first).
3. Iterates over every image, parses its ISO date, and extracts the **ISO calendar year + week number** using `datetime.isocalendar()` , this forms a unique `week_key` (e.g. `"2025-W48"`).
4. Returns `list(weekend_memories.values())`, each element is:
```python
{
"mem_id": "",
"images": [{"id": ..., "path": ..., "thumbnailPath": ...}, ...],
"start_date": "YYYY-MM-DD", # earliest photo date in the ISO week
"end_date": "YYYY-MM-DD", # latest photo date in the ISO week
}
```
7. The `GET /api/memories/weekly-memories` endpoint in `routes/memories.py` calls this function and returns a `WeeklyMemoriesResponse` containing `weekly_memories`.

### Frontend

| Layer | Change |
|---|---|
| `apiEndpoints.ts` | Added `weeklyMemories: '/api/memories/weekly-memories'` to `memoriesEndpoints`. |
| `api-functions/memories.ts` | Added `WeeklyMemoryImage`, `WeeklyMemory`, `WeeklyMemoriesResponse` interfaces and `getWeeklyMemories()` which performs a `GET` to the endpoint and returns the typed response. |
| `hooks/useMemories.tsx` | Added `useWeeklyMemories()` Tanstack Query hook (5-min stale time). |
| `MemoriesPage.tsx` | Added **Weekends** filter button. When active, hides all other sections and renders a `WeekendMemoryCard` grid. Each card uses `thumbnailPath` via `convertFileSrc()` for a fast thumbnail. Clicking a card renders `WeekendMemoryDetail`, which loads the cluster's images into Redux (`setImages`) and renders `ImageCard` + `MediaView` — the same pattern used by `MemoryDetail` — enabling full-screen image browsing. |

***Note: ChatGPT was used to refine the statements above and to organize the structure of the issue.***

### Add ScreenShots

## Screenshots
### Before : No `Weekends` category.

Image

### After : With `Weekends` category

Image

Image

Image

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。