Skip to content

Add image viewer with zoom and pan controls#22

Merged
adbenitez merged 2 commits intomainfrom
copilot/allow-enlarge-images-in-posts
Nov 23, 2025
Merged

Add image viewer with zoom and pan controls#22
adbenitez merged 2 commits intomainfrom
copilot/allow-enlarge-images-in-posts

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

Implement Image Enlargement Feature ✅

This PR adds the ability to enlarge images in posts by clicking on them, similar to typical social media image viewers.

Changes Made

  • Create ImageViewer modal component for displaying enlarged images
  • Add click handler to PostImage component to open ImageViewer
  • Implement zoom controls (zoom in, zoom out, reset)
  • Add mouse wheel zoom support
  • Add click-and-drag panning for zoomed images (desktop)
  • Add touch support for panning on mobile/touchscreen devices
  • Style the ImageViewer with pixelart aesthetics matching the app
  • Add accessibility labels using i18n for multi-language support
  • Test the implementation manually (desktop and mobile)
  • Run code review and security checks

Features

  • Click to enlarge: Click on any image in a post to view it full-screen
  • Zoom controls: Four control buttons (zoom out, reset, zoom in, close)
  • Mouse wheel zoom: Scroll to zoom in/out (0.5x to 4x)
  • Pan when zoomed: Click and drag to pan around when zoomed > 1x (desktop)
  • Touch pan support: Touch and drag to pan on mobile/touchscreen devices
  • Click to close: Click outside the image or use the close button
  • Smooth transitions: Smooth transform animations for better UX
  • Accessibility: All controls have internationalized aria-labels

Screenshots

Normal post view with clickable image:
Post with image

Image viewer opened (mobile view):
Image viewer mobile

Desktop image viewer:
Image viewer desktop

Mobile Support

The image viewer now fully supports touch interactions on mobile devices:

  • Touch drag to pan when zoomed in
  • Single-finger touch gestures
  • Works on all touchscreen devices

Internationalization

All user-facing text in the ImageViewer is now internationalized:

  • Zoom out → "Reducir zoom" (ES)
  • Reset zoom → "Restablecer zoom" (ES)
  • Zoom in → "Aumentar zoom" (ES)
  • Close image viewer → "Cerrar visor de imagen" (ES)
  • Enlarged view → "Vista ampliada" (ES)

Security Summary

  • ✅ No security vulnerabilities detected by CodeQL
  • ✅ All code follows TypeScript best practices
  • ✅ No external dependencies added
Original prompt

This section details on the original issue you should resolve

<issue_title>Allow to enlarge images in posts</issue_title>
<issue_description>currently it is not possible to click the posts with images to enlarge them, when clicking an image in a post, it should be opened in an image viewer with zooming options, like the typical image viewer one see when clicking an image in social media posts to have a closer look </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Enable image enlargement feature in posts Add image viewer with zoom and pan controls Nov 16, 2025
Copilot AI requested a review from adbenitez November 16, 2025 00:32
@adbenitez
Copy link
Contributor

@copilot this has poor mobile support, moving/dragging the big zoomed-in image around to see other parts of it only work on desktop but not when using a touchscreen

Copy link
Contributor Author

Copilot AI commented Nov 22, 2025

@copilot this has poor mobile support, moving/dragging the big zoomed-in image around to see other parts of it only work on desktop but not when using a touchscreen

Added touch event handlers for mobile support in commit 8cacaf7. The image viewer now supports:

  • Touch drag to pan when zoomed in
  • Single-finger touch gestures
  • Works on all touchscreen devices

The implementation mirrors the mouse drag functionality using onTouchStart, onTouchMove, and onTouchEnd event handlers.

Mobile view with touch support:
Mobile image viewer

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements an image enlargement feature for PixelSocial, adding a modal image viewer with zoom and pan controls. The implementation follows WebXDC patterns and adds interactive image viewing capabilities similar to mainstream social media platforms.

Key Changes:

  • New ImageViewer modal component with zoom controls (0.5x-4x), mouse wheel zoom, and click-and-drag panning
  • Integration of the viewer into PostImage component with click-to-open functionality
  • Touch support for mobile devices with pan gestures

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/components/modals/ImageViewer.tsx New modal component implementing image viewer with zoom/pan controls and mouse/touch event handlers
src/components/modals/ImageViewer.module.css Styling for the image viewer modal with pixelart aesthetic (backdrop, controls, container layout)
src/components/PostImage.tsx Added state management and click handler to open ImageViewer modal when image is clicked

Comment on lines +154 to +163
<button className={styles.controlBtn} onClick={handleZoomOut}>
<PixelarticonsZoomOut />
</button>
<button className={styles.controlBtn} onClick={handleReset}>
<PixelarticonsReload />
</button>
<button className={styles.controlBtn} onClick={handleZoomIn}>
<PixelarticonsZoomIn />
</button>
<button className={styles.controlBtn} onClick={onClose}>
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The control buttons lack accessible labels. Screen readers will not be able to announce what each button does since the icon components don't provide text alternatives.

Add aria-label attributes to each button:

<button className={styles.controlBtn} onClick={handleZoomOut} aria-label="Zoom out">
  <PixelarticonsZoomOut />
</button>
<button className={styles.controlBtn} onClick={handleReset} aria-label="Reset zoom">
  <PixelarticonsReload />
</button>
<button className={styles.controlBtn} onClick={handleZoomIn} aria-label="Zoom in">
  <PixelarticonsZoomIn />
</button>
<button className={styles.controlBtn} onClick={onClose} aria-label="Close image viewer">
  <PixelarticonsClose />
</button>
Suggested change
<button className={styles.controlBtn} onClick={handleZoomOut}>
<PixelarticonsZoomOut />
</button>
<button className={styles.controlBtn} onClick={handleReset}>
<PixelarticonsReload />
</button>
<button className={styles.controlBtn} onClick={handleZoomIn}>
<PixelarticonsZoomIn />
</button>
<button className={styles.controlBtn} onClick={onClose}>
<button className={styles.controlBtn} onClick={handleZoomOut} aria-label="Zoom out">
<PixelarticonsZoomOut />
</button>
<button className={styles.controlBtn} onClick={handleReset} aria-label="Reset zoom">
<PixelarticonsReload />
</button>
<button className={styles.controlBtn} onClick={handleZoomIn} aria-label="Zoom in">
<PixelarticonsZoomIn />
</button>
<button className={styles.controlBtn} onClick={onClose} aria-label="Close image viewer">

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but we have _ function at i18n.ts and src/lib/langs/es.json, avoid using hardcoded text in english

Comment on lines +29 to +48
.controlBtn {
background-color: rgba(24, 24, 33, 0.9);
border: 1px solid #6364ff;
color: white;
padding: 0.5em;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
width: 2.5em;
height: 2.5em;
}

.controlBtn:hover {
background-color: rgba(99, 100, 255, 0.2);
}

.controlBtn:active {
background-color: rgba(99, 100, 255, 0.4);
}
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded color values duplicate constants from src/constants.ts. These colors should be applied via inline styles in the TypeScript component using the imported constants, following the pattern used in other components like PrimaryButton.tsx and Modal.tsx.

The hardcoded values are:

  • Line 30: rgba(24, 24, 33, 0.9) should use BG_COLOR (#181821)
  • Line 31: #6364ff should use MAIN_COLOR
  • Line 43: rgba(99, 100, 255, 0.2) should use MAIN_COLOR or ACCENT_COLOR with opacity
  • Line 47: rgba(99, 100, 255, 0.4) should use MAIN_COLOR or ACCENT_COLOR with opacity

Consider moving these styles to inline styles in the component using the constants, or create CSS custom properties (CSS variables) that are set from the TypeScript constants.

Copilot uses AI. Check for mistakes.
@adbenitez adbenitez force-pushed the copilot/allow-enlarge-images-in-posts branch from 8cacaf7 to fee5cfb Compare November 22, 2025 23:41
@adbenitez
Copy link
Contributor

@copilot but we have _ function at i18n.ts and src/lib/langs/es.json, avoid using hardcoded text in english in the aria-labels in ImageViewer component

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 22, 2025

@copilot but we have _ function at i18n.ts and src/lib/langs/es.json, avoid using hardcoded text in english in the aria-labels in ImageViewer component

Updated in commit 255d4a4. All aria-labels and alt text now use the _() function from i18n.ts with Spanish translations added to es.json:

  • "Zoom out" → "Reducir zoom"
  • "Reset zoom" → "Restablecer zoom"
  • "Zoom in" → "Aumentar zoom"
  • "Close image viewer" → "Cerrar visor de imagen"
  • "Enlarged view" → "Vista ampliada"

@adbenitez adbenitez marked this pull request as ready for review November 22, 2025 23:59
@adbenitez adbenitez merged commit c9d165e into main Nov 23, 2025
2 checks passed
@adbenitez adbenitez deleted the copilot/allow-enlarge-images-in-posts branch November 23, 2025 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to enlarge images in posts

3 participants