Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update grouped images #100

Merged
merged 14 commits into from
Sep 27, 2023
Merged

Feature/update grouped images #100

merged 14 commits into from
Sep 27, 2023

Conversation

capetillo
Copy link
Contributor

@capetillo capetillo commented Sep 27, 2023

FEATURE UPDATE: Update Image Grouping and Display

DESCRIPTION

Background:
After having grouped images, more details here, @wrosing noticed that a couple of issues emerged. First, thumbnails were taking a really long time to load. And second, the ThumbnailRow component was not updating with new images as they were coming. Only after the user would refresh the page, would the new images show up. Additionally, sometimes the images would show up at the very end of the ThumbnailRow rather than at the beginning.

Implementation:
With the extensive help and advice of @timbeccue, I learned that Vue is not as reactive to group_images because of its data structures. Instead, it's best to store images in an array so that the UI can re-render when the state has updated (i.e. when new images come). This new implementation can be found on lines 63-72 of images.js.

   // First, generate a map of maximum SSTKNUM for each SMARTSTK
   const maxSSTKNUMs = state.recent_images.reduce((acc, cur) => {
     if (!cur.header || !cur.header.SMARTSTK || !cur.header.SSTKNUM) return acc // Skip if missing header, SMARTSTK or SSTKNUM

     const num = parseInt(cur.header.SSTKNUM) // convert string to number
     if (!acc[cur.header.SMARTSTK] || num > acc[cur.header.SMARTSTK]) {
       acc[cur.header.SMARTSTK] = num
     }
     return acc
   }, {})
   const filteredArr = state.recent_images.filter(el => {
     if (!el.header || !el.header.SMARTSTK || !el.header.SSTKNUM) return true
     return el.header.SSTKNUM >= maxSSTKNUMs[el.header.SMARTSTK]
   })
   return filteredArr
}

This new implementation, written by @timbeccue, goes as follows:

  1. First, it takes the existing array of recent_images and with the reduce method, it creates a map (maxSSTKNUMs) where the key is SMARTSTK and the value is the greatest SSTKNUM found in the recent_images array
  2. Then, the it checks if the current image has a header, a SMARTSTK, or a SSTKNUM (stack number). If it doesn't have any, then we return the acc as is.
  3. Next, for each unique SMARTSTK in the array of image objects, it finds the max value of SSTKNUM. If the current image has a SMARTSTK value that is not yet in the acc object OR if the SSTKNUM value (parsed to an integer) is greater than the currently one stored in acc for that existing SMARTSTK, it updates the acc with the new maximum SSTKNUM for that SMARTSTK.
  4. It then returns the acc object to be used in the next iteration
  5. Then it filters the recent_images array to include items that either don't have a header, SMARTSTK, or SSTKNUM OR have the maximum SSTKNUM for the SMARTSTK associated with it.
  6. Finally, it returns the filtered array filteredArr

Updated Features:

  1. Reduced Thumbnail Count: Only the most recent image from each smart stack is displayed in the ThumbnailRow component. Thus, reducing significantly the number of thumbnail images displayed. This remains true, however, the implementation has now changed, as mentioned above
  2. Updating Images: Because images are now stored in an array, the UI is now reacting to the updates. As images are stored in the state, it's accurately reflected on the UI and shown at the beginning of the ThumbnailRow carousel.

Visuals:

Before taking an image

Screenshot 2023-09-27 at 12 10 25 PM

After taking an image and without having to refresh the site

Screenshot 2023-09-27 at 12 11 08 PM

Carolina Capetillo and others added 10 commits September 22, 2023 09:46
…l. and added a watcher in thumbnailrow component
…image with the same smartstack value comes. Images are updating as they come too. And images are being stored in an array because Vue is more reactive to arrays than objects (which is why images were not updating as they were received)
…space. leaving the commented out code there for when Wayne wants to use the group_images feature
Copy link

@markBowman markBowman left a comment

Choose a reason for hiding this comment

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

Amazing pr description - thank you
Approved for trial deployment

Copy link
Collaborator

@timbeccue timbeccue left a comment

Choose a reason for hiding this comment

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

Lots of great work that went into this! Just one suggestion to add a comment explaining what the getter is doing, but ready to merge after that!

@@ -59,7 +59,29 @@ const getters = {
current_image: state => state.current_image,
recent_images: state => state.recent_images,
user_images: state => state.user_images,
grouped_images: state => state.grouped_images,
// grouped_images: state => state.grouped_images,
recent_images_condensed: state => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be helpful to include a comment describing an overview of what this getter is doing, something along the lines of 'Same as recent_images but removes any intermediate smartstack frames, so you only see the latest version of each smart stack'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Added comment!

@capetillo capetillo merged commit c835df5 into dev Sep 27, 2023
1 check passed
@capetillo capetillo deleted the feature/update-grouped-images branch September 27, 2023 21:35
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.

3 participants