📸 Gallery Backend Refactor: Photo Object V2 Implementation
The gallery backend is being refactored to align with the established patterns of the members and newsApi modules. The core change involves migrating from the legacy relational structure to the new, flat Photo Object V2 collection.
🔍 Reason for Refactor
The current implementation relies on a rigid photo_version collection which introduces unnecessary overhead. By adopting the Photo Object V2 collection:
- Performance is improved: Reduced database joins.
- Maintainability is increased: Data fetching is unified with other core modules.
- Flexibility is enhanced: Native support for multiple images, animations, and external links within a single object.
🛑 Developer Instructions
- Create a New Branch: Start your work by creating a new feature branch (e.g.,
youname/refactor/615-refactor-gallery).
- Ignore Legacy Implementation: Do not attempt to fix or modify the old code directly. Build the new logic alongside it.
- Reference Existing Modules: While you can check the old code for context, the best examples of modern Directus integration are found in the
members (Characters) and newsApi (News) modules.
🛠️ 1. Directus Schema (Photo Object V2)
We are using the new Photo Object V2 collection, which includes the following fields directly:
- Primary Assets:
image (Image/File, Required) – Primary asset.
image_2, image_3 (Image/File, Optional)
animation (Video/File, Optional) – To be rendered conditionally.
- Content Details:
title (String, Optional) – Primary title of the work.
author (String, Optional) – Author of the art (if known).
description (Textarea, Optional) – Detailed description of the work.
- References & Socials:
link, link_2 (URL/String, Optional) – External references, such as social media profiles, portfolio sites, or project-specific links.
✅ 2. Technical Implementation Details
API & Data Fetching
- Interface Update: Update the
PhotoObject interface to reflect the V2 flat structure. Remove all legacy photo_version types.
- API Service: Refactor
galleryApi to fetch data directly from the Photo Object V2 collection. Implement try-catch blocks and FetchBaseQueryError to match the error-handling patterns used in membersApi and newsApi.
Logic & Hook Integration
- Data Mapping: In the
useGetDirectusGalleryImages hook, convert asset IDs into full URLs using the ${directusBaseUrl}/assets/${id} pattern.
- Anchor Mapping: Generate a unique
anchorId for each item based on the author field (e.g., by sanitizing the name into a URL-safe string).
- Link Handling: Integrate the
linkify utility for the link and link_2 fields to ensure external URLs are handled safely and consistently.
UI & Conditional Rendering
- Anchor ID: Assign the generated
author-based ID to each gallery item's container in the DOM.
- Auto-Scroll Logic: Implement a
useEffect that checks window.location.hash after the Directus data has loaded. If a match is found, the page must automatically scroll to the corresponding author's work using scrollIntoView({ behavior: 'smooth' }).
- Animation Rendering: The animation button or player must use conditional rendering. It should only be rendered if the
animation field contains data; otherwise, it must remain hidden.
- Frames Composition: Bundle
image, image_2, image_3, and animation into a single frames array for the UI.
- Button Components: "Project" or "More" buttons should only appear if a valid URL exists after being processed by the
linkify logic.
🏁 Acceptance Criteria
- Data is successfully fetched from the Photo Object V2 collection.
- Gallery items have stable
id attributes derived from the author field for anchoring.
- Deep Linking: Arriving at the gallery with an author hash (e.g.,
/gallery#MattiMeikalainen) triggers an automatic smooth scroll to that item after data load.
- Animations and additional images render only when data is present (no empty slots or broken buttons).
- External links are processed via
linkify and appear only when valid.
- The fetching pattern is unified with the
members and newsApi modules.
- Redundant relational fetches for
photo_version are removed from the new implementation.
📋 Additional Information
If you do not have Directus credentials yet, please ask the team veterans to create an account for you so you can inspect the V2 collection schema.
- 🎨 UI/UX Design: Please check the latest design and layout specifications from Figma before starting the UI implementation.
🔗 Figma
🔗 Directus Documentation
📷 Preview:

📸 Gallery Backend Refactor: Photo Object V2 Implementation
The gallery backend is being refactored to align with the established patterns of the
membersandnewsApimodules. The core change involves migrating from the legacy relational structure to the new, flat Photo Object V2 collection.🔍 Reason for Refactor
The current implementation relies on a rigid
photo_versioncollection which introduces unnecessary overhead. By adopting the Photo Object V2 collection:🛑 Developer Instructions
youname/refactor/615-refactor-gallery).members(Characters) andnewsApi(News) modules.🛠️ 1. Directus Schema (Photo Object V2)
We are using the new Photo Object V2 collection, which includes the following fields directly:
image(Image/File, Required) – Primary asset.image_2,image_3(Image/File, Optional)animation(Video/File, Optional) – To be rendered conditionally.title(String, Optional) – Primary title of the work.author(String, Optional) – Author of the art (if known).description(Textarea, Optional) – Detailed description of the work.link,link_2(URL/String, Optional) – External references, such as social media profiles, portfolio sites, or project-specific links.✅ 2. Technical Implementation Details
API & Data Fetching
PhotoObjectinterface to reflect the V2 flat structure. Remove all legacyphoto_versiontypes.galleryApito fetch data directly from thePhoto Object V2collection. Implementtry-catchblocks andFetchBaseQueryErrorto match the error-handling patterns used inmembersApiandnewsApi.Logic & Hook Integration
useGetDirectusGalleryImageshook, convert asset IDs into full URLs using the${directusBaseUrl}/assets/${id}pattern.anchorIdfor each item based on theauthorfield (e.g., by sanitizing the name into a URL-safe string).linkifyutility for thelinkandlink_2fields to ensure external URLs are handled safely and consistently.UI & Conditional Rendering
author-based ID to each gallery item's container in the DOM.useEffectthat checkswindow.location.hashafter the Directus data has loaded. If a match is found, the page must automatically scroll to the corresponding author's work usingscrollIntoView({ behavior: 'smooth' }).animationfield contains data; otherwise, it must remain hidden.image,image_2,image_3, andanimationinto a singleframesarray for the UI.linkifylogic.🏁 Acceptance Criteria
idattributes derived from theauthorfield for anchoring./gallery#MattiMeikalainen) triggers an automatic smooth scroll to that item after data load.linkifyand appear only when valid.membersandnewsApimodules.photo_versionare removed from the new implementation.📋 Additional Information
If you do not have Directus credentials yet, please ask the team veterans to create an account for you so you can inspect the V2 collection schema.
🔗 Figma
🔗 Directus Documentation
📷 Preview:
