Skip to content

Conversation

@zhephyn
Copy link
Contributor

@zhephyn zhephyn commented Jul 9, 2025

Description

Adds Light box support for the file field

Fixes #1647

Checkbox

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@zhephyn zhephyn marked this pull request as draft July 9, 2025 13:52
@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

@Paul-Bob I'm having trouble registering the light box controller in the application. I had initially imported from the stimulus components library. However, it seems I will have to extend it for the functionality to work.

Ideally if it works, I'm supposed to see this message logged in the browser console.

console.log("should see this message logged in console")

Tried looking at the docs but it seems i got more confused.

Copy link

@qlty-cloud-legacy qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 15842 lines exceeds the maximum allowed for the inline comments feature.

@qlty-cloud-legacy
Copy link

qlty-cloud-legacy bot commented Jul 9, 2025

Code Climate has analyzed commit 2b11638 and detected 0 issues on this pull request.

View more on Code Climate.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

Hi @zhephyn,

I noticed that the yarn.lock file has an unusually large number of changes. That's not ideal. I'm not sure how that happened, but it should be looked into.

Also, it seems you're registering two different things under the same name:

application.register(lightbox, LightboxController)
application.register('lightbox', Lightbox)

Additionally, the first controller registration might contain a syntax error. The identifier should be a string, like this:

application.register('lightbox', LightboxController)

Lastly, it looks like the controller isn't actually being used in the DOM, so it never connects. For the controller to initialize properly, you need to attach it to an element like this:

<div data-controller="lightbox"></div>

When this element is loaded, the lightbox controller will connect to it and start working as expected.

Copy link

@qlty-cloud-legacy qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 15890 lines exceeds the maximum allowed for the inline comments feature.

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

Think I'm gonna go with a custom light box controller instead of the one that is imported from the stimulus components library. Gonna rebase and possibly delete that yarn file with a large diff

@zhephyn zhephyn force-pushed the adds_lightbox_support_for_file_field branch from 86fbb58 to 20e6320 Compare July 9, 2025 15:39
Copy link

@qlty-cloud-legacy qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 15889 lines exceeds the maximum allowed for the inline comments feature.

@zhephyn zhephyn force-pushed the adds_lightbox_support_for_file_field branch from 20e6320 to 16815d7 Compare July 9, 2025 15:53
Copy link

@qlty-cloud-legacy qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 6519 lines exceeds the maximum allowed for the inline comments feature.

@zhephyn zhephyn force-pushed the adds_lightbox_support_for_file_field branch from 16815d7 to 5af3303 Compare July 9, 2025 15:56
Copy link

@qlty-cloud-legacy qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 6628 lines exceeds the maximum allowed for the inline comments feature.

@zhephyn zhephyn force-pushed the adds_lightbox_support_for_file_field branch from 5af3303 to 12f888e Compare July 9, 2025 16:12
@zhephyn zhephyn force-pushed the adds_lightbox_support_for_file_field branch from a7072cc to a93a02b Compare July 9, 2025 16:26
@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

@Paul-Bob I've successfully rebased the PR to remove the unnecessary previous commits. Now the PR, shows one commit which is related to me implementing a custom light box controller that we'll use to implement the feature as opposed to the one i had imported from the stimulus components library before.

Still though, I'm having trouble registering the controller even after making it available for the cover photo component.

As for the tests, I wanted to first make sure that the functionality is working, then I will add tests for the light box functionality.

PS: Sorry about the cluttering of the PR with code climate comments. Not really sure how to delete them to make the PR cleaner.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

@Paul-Bob I've successfully rebased the PR to remove the unnecessary previous commits. Now the PR, shows one commit which is related to me implementing a custom light box controller that we'll use to implement the feature as opposed to the one i had imported from the stimulus components library before.

Cool!

Still though, I'm having trouble registering the controller even after making it available for the cover photo component.

What is the issue? What are you expecting to happen and is not? How are you veryfing if the controller is connecting or not?

As for the tests, I wanted to first make sure that the functionality is working, then I will add tests for the light box functionality.

We're still far from tests, let's ensure we implement the feature before adding tests for it.

PS: Sorry about the cluttering of the PR with code climate comments. Not really sure how to delete them to make the PR cleaner.

That's no problem at all.

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

@Paul-Bob I expect this message to be logged to the browser console to signify that the controller connected successfully.

connect() {
    console.log("Lightbox controller connected")
  }

Usually that's how I do it. Is there a better way for me to check that the controller is regsitered?

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

That is all right, and what page are you visiting and expecting the message to be present on the browser console? I moved to this branch locally and I was able to see the connect debug message on my browser console

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

I've been navigating to the posts show page for an individual post as every post has a cover photo. So I figured this page would be perfect for seeing the console message.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

I think you are confusing components, the cover where you added the controller is the one rendered here https://github.com/avo-hq/avo/blob/main/app/components/avo/panel_component.html.erb#L2

And it is the big cover photo that appear on show view like this: https://main.avodemo.com/avo/resources/events/47

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

Not sure if I get what you're trying to say. I had added the controller to the opening div inside the cover_photo_component.html.erb
Was the controller supposed to be added to a different component file and is this not the component which renders the cover photo on the post show page?

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

Not sure if I get what you're trying to say. I had added the controller to the opening div inside the cover_photo_component.html.erb

That component is rendered when the resource has self.cover_photo configured.

Was the controller supposed to be added to a different component file and is this not the component which renders the cover photo on the post show page?

I'm unclear on where the controller is supposed to go. Based on the original issue request, I think it should be added to the file and files fields.

What I'm trying to say is that you added the controller to a component that isn't present on the post resource's show component. The cover_photo_component.html.erb is only responsible for rendering this:

class Avo::Resources::Event < Avo::BaseResource
  self.cover_photo = {
    size: :xl,
    visible_on: [:show, :index],
    source: -> {
      if record.present?
        record.cover_photo
      else
        Event.first&.cover_photo
      end
    }
  }
end

https://main.avodemo.com/avo/resources/events/47
image

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

field :cover_photo, as: :file, ...
field :cover_photo, as: :external_image, ...

I think I understand from where your confusion started, this fields have nothing to do with the cover component, these are just 2 fields, one as file and the other as external image, that are using the cover_photo name by coincidence.

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 9, 2025

Ohhh I get it now.
let me dig around and see if I can figure out where it's supposed to go. Gonna report back ASAP!

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 9, 2025

Ohhh I get it now. let me dig around and see if I can figure out where it's supposed to go. Gonna report back ASAP!

Cool!

No rush, take your time

@zhephyn
Copy link
Contributor Author

zhephyn commented Jul 11, 2025

Hey @Paul-Bob

So I've finally moved the data-action and target attributes for the lightbox stimulus controlller to the right file which renders the cover photo on the post show page. This file is the grid_item_component.html.erb.

At this point, I expected the functionality to work, but just like before, its not working. Still not sure if the controller was registered because even when i added data-controller="lightbox" to the main div of the grid_item_component.html.erb file, i expect to see a message logged to the console when this component is rendered like you had mentioned. However, that's not the case.

All in all, I'm not sure if its not working because of incorrect implementation or because the controller was never registered to begin with.

@zhephyn
Copy link
Contributor Author

zhephyn commented Aug 19, 2025

Tried this as a way of potentially fixing it but I get 2 errors related to the commands being unrecognized.

zhephyn@mail:~/Desktop/avo$ rails tailwindcss:watch
Unrecognized command "tailwindcss:watch" (Rails::Command::UnrecognizedCommandError)
zhephyn@mail:~/Desktop/avo$ rails tailwind:css build
Unrecognized command "tailwind:css" (Rails::Command::UnrecognizedCommandError)

@zhephyn
Copy link
Contributor Author

zhephyn commented Aug 19, 2025

However to address your comment from the initial review about the image being overstretched, by adding the mx-auto class to the image, we can prevent it from being over stretched, such that we have something which looks like this:
image

@Paul-Bob
Copy link
Contributor

So, the green background is not applied when I add it.

Are you using the bin/dev command to start the server?

@zhephyn
Copy link
Contributor Author

zhephyn commented Aug 19, 2025

Yeah.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2025

This PR has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Sep 5, 2025
@zhephyn
Copy link
Contributor Author

zhephyn commented Sep 5, 2025

Hey @Paul-Bob, The github actions bot just marked this as stale, which may result in the PR being closed. I could try again to debug the UI tailwind issue if its cool with you.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Sep 5, 2025

I could try again to debug the UI tailwind issue if its cool with you.

The issue seems to be on your local environment. bin/dev does run css: yarn build:css --watch, so I'm not sure why the watcher is not working on your environment. You're the right person to debug and fix it on your side. Alternatively, if you want to move fast without debugging this problem, you can just run yarn build:css after each style change to rebuild and confirm the effect in the browser.

@github-actions github-actions bot removed the Stale label Sep 6, 2025
@zhephyn
Copy link
Contributor Author

zhephyn commented Sep 18, 2025

Update. Done debugging the watcher issue.

@Paul-Bob
Copy link
Contributor

Update. Done debugging the watcher issue.

What was the issue?

@zhephyn
Copy link
Contributor Author

zhephyn commented Sep 19, 2025

I actually don't know. but I deleted the project locally and re-cloned it again from Github. Following that, the watcher was picking up the new classes when i ran bin/dev. Gonna now proceed to work on the styles so that we can get this merged!

@zhephyn
Copy link
Contributor Author

zhephyn commented Sep 26, 2025

Hey @Paul-Bob . Think I've made final progress on this PR. This is what the image looks like when opened in the lightbox modal.

output.mp4

Maybe one change I would propose is the use of a heroicon instead of the current <button>X</button> syntax. I had tried making this change however I ran into the error below related to helpers.svg probably since I had used it inside a partial.

web    | Information for: ActionView::Template::Error (undefined local variable or method `helpers' for an instance of #<Class:0x00007311ce7a7080>):
web    |     1: <div data-lightbox-target="modal" class="hidden fixed inset-0 z-[100] flex justify-center" data-action="click->lightbox#close">
web    |     2:   <img data-lightbox-target="image" class="rounded-lg shadow-lg mt-4 mb-4" alt="Expanded view of the image" src="" />
web    |     3:   <%= button_tag type: "button", class: "flex pt-2 ml-2", data: { action: "click->lightbox#close"} do %>
web    |     4:     <%= helpers.svg('heroicons/solid/x-mark') %>
web    |     5:   <% end %>
web    |     6: </div>
web    |   
web    | app/views/avo/partials/_lightbox.html.erb:4
web    | app/views/avo/partials/_lightbox.html.erb:3
web    | 
web    | Information for cause: NameError (undefined local variable or method `helpers' for an instance of #<Class:0x00007311ce7a7080>):

Then finally about the failing feature test, I think it could be a flaky issue because all the failing tests pass on my machine.
image

In case of anything, lmk and I'll poke around, otherwise it seems to me that this is close to completion.

@github-actions
Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Oct 11, 2025
@Paul-Bob Paul-Bob removed the Stale label Oct 13, 2025
@github-actions
Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Oct 29, 2025
@Paul-Bob Paul-Bob removed the Stale label Oct 29, 2025
@github-actions
Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lightbox support for file field

2 participants