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

Show placeholder if there is no preview image #842

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bookmarks/static/preview-placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 17 additions & 2 deletions bookmarks/styles/bookmark-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,29 @@ li[ld-bookmark-item] {
min-width: 0;
}

& img.preview-image {
& .preview-image {
flex: 0 0 auto;
width: 100px;
height: 60px;
margin-top: var(--unit-h);
object-fit: cover;
border-radius: var(--border-radius);
border: solid 1px var(--border-color);
object-fit: cover;

&.placeholder {
display: flex;
align-items: center;
justify-content: center;
background: var(--body-color-contrast);

& .img {
width: var(--unit-12);
height: var(--unit-12);
background-color: var(--tertiary-text-color);
-webkit-mask: url(preview-placeholder.svg) no-repeat center;
mask: url(preview-placeholder.svg) no-repeat center;
}
}
}

& .form-checkbox.bulk-edit-checkbox {
Expand Down
10 changes: 8 additions & 2 deletions bookmarks/templates/bookmarks/bookmark_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@
{% endif %}
</div>
</div>
{% if bookmark_list.show_preview_images and bookmark_item.preview_image_file %}
<img class="preview-image" src="{% static bookmark_item.preview_image_file %}" loading="lazy"/>
{% if bookmark_list.show_preview_images %}
{% if bookmark_item.preview_image_file %}
<img class="preview-image" src="{% static bookmark_item.preview_image_file %}" loading="lazy"/>
{% else %}
<div class="preview-image placeholder">
<div class="img"/>
</div>
{% endif %}
{% endif %}
</li>
{% endfor %}
Expand Down
11 changes: 8 additions & 3 deletions bookmarks/tests/test_bookmarks_list_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def assertPreviewImage(self, html: str, bookmark: Bookmark, visible=True):
self.assertIsNotNone(preview_image)
self.assertEqual(preview_image["src"], url)

def assertPreviewImagePlaceholder(self, html: str):
soup = self.make_soup(html)
placeholder = soup.select_one(".preview-image.placeholder")
self.assertIsNotNone(placeholder)

def assertBookmarkURLCount(
self, html: str, bookmark: Bookmark, link_target: str = "_blank", count=0
):
Expand Down Expand Up @@ -691,15 +696,15 @@ def test_preview_image_should_be_hidden_when_preview_images_disabled(self):

self.assertPreviewImageHidden(html, bookmark)

def test_preview_image_should_be_hidden_when_there_is_no_preview_image(self):
def test_preview_image_shows_placeholder_when_there_is_no_preview_image(self):
profile = self.get_or_create_test_user().profile
profile.enable_preview_images = True
profile.save()

bookmark = self.setup_bookmark()
self.setup_bookmark()
html = self.render_template()

self.assertPreviewImageHidden(html, bookmark)
self.assertPreviewImagePlaceholder(html)

def test_favicon_should_be_visible_when_favicons_enabled(self):
profile = self.get_or_create_test_user().profile
Expand Down