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

load image in sidebar as thumbnail #1319

Merged
merged 9 commits into from
Jan 6, 2023
Merged

Conversation

7malikk
Copy link
Collaborator

@7malikk 7malikk commented Dec 23, 2022

Fixes #1295

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with grunt test
  • code is in a uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updates
  • @mention the original creator of the issue in a comment below for help or for a review

UI changes when the images fetched are above 100

thumbnail1 0

@7malikk
Copy link
Collaborator Author

7malikk commented Dec 23, 2022

@jywarren What are your thoughts on this implementation of the image render in the sidebar?
This is preceding the client-side pagination we discussed here: #1295 (comment)
I would take up that project in a separate issue and PR

@7malikk
Copy link
Collaborator Author

7malikk commented Jan 1, 2023

Hello @jywarren here is a draft for the server side pagination #1300
With @segun-codes's help (thanks again @segun-codes), I was able to achieve a Gmail look-alike pagination as requested

For a link with images over 100

pagination

For a link with images below 100

pagination-2

So upon your review of this PR - #1319, this would be integrated.

Thank you!

@jywarren
Copy link
Member

jywarren commented Jan 3, 2023

Wow, this is quite impressive, i really like the filtering of thumbnails into thumbs especially, and the pagination looks great.

I have two requests -- first, we are working with some much bigger blocks of code here; can you use a couple comments to explain what each portion does? For example, line 117-141 is so dense -- what does each section do? How can we make this code more readable and maintainable?

The second is -- are there any ways we can reduce the number of lines here by creating re-usable functions? Can we get clever with how the HTML is generated to make it easier to reuse across the 3 different renderers, since that seems to be the largest source of new lines of code?

Thanks a lot for this complex and carefully written PR -- I'm hoping we can refine it a little bit before we move forward!

@7malikk
Copy link
Collaborator Author

7malikk commented Jan 3, 2023

@jywarren Thanks a lot for your review, as per your requests, of course, I will add the comments and break them into chunks of reusable code. Thanks again

@7malikk
Copy link
Collaborator Author

7malikk commented Jan 4, 2023

@jywarren I've added the comments and made the adjustments to the code for readability and maintainability, I think you'd like it
As soon as this is merged I'd get the pagination in there, taking into account the corrections you made in this PR.
Thank you so much, I am learning so much from working with you and the rest of the team.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Hi @7malikk -- I've made some pretty big suggestions here, and I hope they make sense. Code style is not the kind of thing where there's a "right" answer, and everybody does things a little differently. But what I tried to explain is how I like to use comments to explain mysterious things, but to keep comments as short as possible by using descriptive variable and function names. And the structure of the code itself (not too many nested functions, similar named functions for related functionality) can help to make things readable.

This is looking really good. Let me know what you think about my review and suggestions. Thanks a lot for sticking with this one, we're almost there!

examples/js/archive.js Outdated Show resolved Hide resolved
examples/js/archive.js Show resolved Hide resolved
examples/js/archive.js Outdated Show resolved Hide resolved
function renderImages(files, url, count) {
// thumbs variable is to extract the thumbnail files from the fetched data
const thumbs = files.filter(file => file.source === 'derivative');
// images variable is to extract the actual image files from the fetched data
Copy link
Member

Choose a reason for hiding this comment

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

Here, I think we can skip the comment if we use a very clear variable name - i'm a big fan of longer variable names that are very descriptive -- that way they're legible wherever in the codebase they're used. So what if we skipped the comments and named these variables thumbnail_images and original_images? (I would use camelCase but the lower case l and the capital I are hard to read...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, thanks @jywarren, yea camelCase there is usually hard to read

// images variable is to extract the actual image files from the fetched data
const images = files.filter(file => file.format === 'PNG' || file.format === 'JPEG');

// this if check is to check the amount of image files and thumbnail files is below 100, afterwhich if true it renders the images in the sidebar
Copy link
Member

Choose a reason for hiding this comment

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

I'm just thinking -- I feel like I want to have two functions named renderImages and renderThumbnails, and to use comments to show that the first is just plain images, and the second searches for thumbnails if they exist. The current renderImages is mostly just logic switching between those two, isn't it? And the thumbs filter could go into renderThumbnails because it's more specific to that task.

The logic (if loop) for which of those two functions we use could be more simply written:

// if over 100 images, show only thumbnails
if (count > 100) renderThumbnails(images, url);
else renderImages(images, url);

Then it's quite readable too - and this could go down on line 152, eliminating this intermediary function. Then we have 2 functions which are similarly named and act similarly, although one uses thumbnails instead. What do you think?

This would also keep all the filtering code together, which seems good too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I like the idea, it does make the code more readable.
I will work on the implementation, hopefully, it'll be a homerun from there.
Thank you @jywarren

@7malikk
Copy link
Collaborator Author

7malikk commented Jan 5, 2023

Hi @7malikk -- I've made some pretty big suggestions here, and I hope they make sense. Code style is not the kind of thing where there's a "right" answer, and everybody does things a little differently. But what I tried to explain is how I like to use comments to explain mysterious things, but to keep comments as short as possible by using descriptive variable and function names. And the structure of the code itself (not too many nested functions, similar named functions for related functionality) can help to make things readable.

This is looking really good. Let me know what you think about my review and suggestions. Thanks a lot for sticking with this one, we're almost there!

@jywarren Thanks a lot for the review and the suggestions, they make a lot of sense as it helps demystify the code.
I would make the necessary changes and consult your expertise, afterward. Thanks again! 🙌🏾

7malikk and others added 4 commits January 5, 2023 17:51
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
@7malikk
Copy link
Collaborator Author

7malikk commented Jan 5, 2023

@jywarren made a refactor, and ended with a little chunky code but it seems readable and understandable, let me know what you think.

While refactoring I realized in other for the logic to fail gracefully into full-resolution images, I needed to filter initially, before the separate function calls.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Great, this looks good! I'm going to merge it now!!

@jywarren jywarren merged commit c4148e4 into publiclab:main Jan 6, 2023
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.

Load image thumbnail in sidebar - Discussion
2 participants