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 spinner while loading ZIM content in viewer iframe #1183

Merged
merged 1 commit into from
Mar 30, 2025

Conversation

Optimus-NP
Copy link
Contributor

@Optimus-NP Optimus-NP commented Feb 28, 2025

Fixes #731

  • Implemented a spinner to improve user experience while ZIM content is loading in the viewer iframe.
  • Added .loader and .spinner styles in kiwix.css.
  • The iframe content is initially hidden (visibility: hidden) and will be displayed once loading completes.
  • Used CSS animations (@Keyframes spin) for a smooth rotating effect.

Demo

kiwix_issue_731.mp4

Command

/usr/local/bin/kiwix-serve --port=8080 --library /tmp/zimlibrary/linux_library.xml --monitorLibrary

@Optimus-NP
Copy link
Contributor Author

Hi @kelson42,

I've added a spinner to improve the user experience while ZIM content is loading in the viewer iframe. The iframe is initially hidden and becomes visible once loading completes. I also added styles in kiwix.css and used CSS animations for a smooth effect.

Could you review the changes and let me know if any improvements are needed? Thanks!

@benoit74
Copy link

benoit74 commented Mar 9, 2025

@Optimus-NP thank you, I'm not a maintainer on this repo, but I see one potential flaw, can you check how your spinner render on smaller screens (e.g. phones in portrait mode). I'm concerned about the fact that text might be split on two rows which is probably a bit ugly.

@Optimus-NP Optimus-NP force-pushed the kiwix-tools-issue_731 branch from f57da12 to fc2a6f6 Compare March 11, 2025 15:12
@Optimus-NP
Copy link
Contributor Author

Thanks @benoit74 for the feedback. I have addressed the comment.
Requesting for the review.

kiwix_issue_mob_731.mp4

@benoit74
Copy link

@kelson42 who should review this?

@Optimus-NP
Copy link
Contributor Author

Hi @kelson42

Requesting you to review this PR.

@Optimus-NP
Copy link
Contributor Author

@veloman-yunkan

Please review this PR.

@kelson42 kelson42 force-pushed the kiwix-tools-issue_731 branch from fc2a6f6 to fc89461 Compare March 17, 2025 18:47
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

Failures of the unit-tests must be fixed by updating the cacheids of the modified static resources (the new values can be seen in the test failure reports).

@@ -425,6 +425,10 @@ let viewerSetupComplete = false;

function on_content_load() {
if ( viewerSetupComplete ) {
const loader = document.getElementById("kiwix__loader");
const iframe = document.getElementById("content_iframe");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the readily available global variable contentIframe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @veloman-yunkan

I appreciate your well-thought-out recommendations. They will certainly help improve the outcome.

Comment on lines 428 to 433
const loader = document.getElementById("kiwix__loader");
const iframe = document.getElementById("content_iframe");
iframe.style.visibility = "visible";
loader.style.display = "none";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be moved out of the if statement (it doesn't depend on the viewer setup, which is mostly about loading translations).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have now integrated for the i18n for the loading content message so I need to wait for the translations to happen.

@@ -30,9 +30,12 @@
location.href = root + '/';
}
</script>
</head>

</head>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that.

<body style="margin:0" onload="setupViewer()">
<div class="loader" id="kiwix__loader">
<div class="spinner"></div>
Loading content...
Copy link
Collaborator

Choose a reason for hiding this comment

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

This text is not internationalized/translated. You will have to update the function updateUIText() in viewer.js. Please do that in a separate commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sincerely appreciate your guidance on i18n. I wasn’t familiar with how to use and implement it, but thanks to your help, I now understand its importance and how to integrate it effectively. Your insights were incredibly valuable—thank you!

Comment on lines 43 to 45
.content-iframe {
visibility: hidden; /* Hide initially */
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better rename this class to hidden or invisible and then dynamically remove it from from the classList of the content iframe element in order to make it visible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That’s a solid idea, appreciate you sharing it.

@Optimus-NP Optimus-NP force-pushed the kiwix-tools-issue_731 branch 2 times, most recently from f598cb2 to 4a0428a Compare March 22, 2025 21:43
@Optimus-NP
Copy link
Contributor Author

Failures of the unit-tests must be fixed by updating the cacheids of the modified static resources (the new values can be seen in the test failure reports).

Thanks this fixes the test failure issues.

@Optimus-NP
Copy link
Contributor Author

@veloman-yunkan

Thanks for the review. I have addressed the comment.

@Optimus-NP
Copy link
Contributor Author

@veloman-yunkan @kelson42

Requesting you to review this PR.

@@ -34,5 +34,6 @@
"magnet-link-text": "رابط جذب {رابط جاذب}",
"magnet-alt-text": "التحميل {التنزيل} عن طريق/بواسطة رابط الجذب\n{الرابط الجاذب}",
"torrent-download-link-text": "بت تورنت",
"torrent-download-alt-text": "التحميل {التنزيل} عن طريق/بواسطة بت تورنت"
"torrent-download-alt-text": "التحميل {التنزيل} عن طريق/بواسطة بت تورنت",
"text-loading-content": "جاري تحميل المحتوى"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder where the translations of the new i18n string came from. Did you add them yourself? If so, then please undo those changes. Be advised that translation is outsourced to https://translatewiki.net and its results are integrated into our code via automated pull requests like, for example, #1179. The only files that should be manually modified under static/skin/i18n directory are en.json (the source text for translation), qqq.json (provides context for translation), and test.json (used in unit tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I’ve reverted the changes to the translation files and ensured that only en.json, qqq.json, and test.json are manually modified as per the guidelines. I'll make sure to follow the correct workflow via TranslateWiki for future updates.

@@ -25,14 +25,16 @@

const root = getRootLocation();
const blankPageUrl = root + "/skin/blank.html?KIWIXCACHEID";

if ( location.hash == '' ) {
if (location.hash == '') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Undo this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reverted this change.

<body style="margin:0" onload="setupViewer()">
<div class="loader" id="kiwix__loader">
<div class="spinner"></div>
<span id="kiwix__loading_text">Loading content...</span> <!-- Added ID for translation -->
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment has no value. Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed the comment as requested.

@@ -78,7 +80,7 @@
</div>
</div>

<iframe id="content_iframe"
<iframe id="content_iframe" class="content-iframe"
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no CSS class content-iframe anymore - it has been renamed to hidden

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the update. I’ve updated the references accordingly to use hidden instead of content-iframe.

Comment on lines 428 to 433
//viewerSetupComplete is marked as true once the translations are loaded
//Now we can load the spinner.
const loader = document.getElementById("kiwix__loader");

contentIframe.classList.remove("hidden");
loader.style.display = "none";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hiding the spinner and showing the content doesn't in any way depend on the translations being loaded and therefore must be performed outside the if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification. I’ve updated the logic to ensure that hiding the spinner and showing the content happens independently of the translations being loaded.

@Optimus-NP Optimus-NP force-pushed the kiwix-tools-issue_731 branch 4 times, most recently from 08ec098 to da87a5f Compare March 25, 2025 16:05
@Optimus-NP
Copy link
Contributor Author

@veloman-yunkan

Thanks for the review. I have addressed the comment.

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

LGTM, but before we merge please remove the reference to the issue number from the commit title (since it points to the wrong issue as the issue addressed is in a different repository).

@Optimus-NP Optimus-NP changed the title Show spinner while loading ZIM content in viewer iframe (#731) Show spinner while loading ZIM content in viewer iframe Mar 26, 2025
@Optimus-NP
Copy link
Contributor Author

LGTM, but before we merge please remove the reference to the issue number from the commit title (since it points to the wrong issue as the issue addressed is in a different repository).

Thank you for catching that. Addressed.

@Optimus-NP
Copy link
Contributor Author

@kelson42 @veloman-yunkan

Please help in merging this.

@veloman-yunkan
Copy link
Collaborator

LGTM, but before we merge please remove the reference to the issue number from the commit title (since it points to the wrong issue as the issue addressed is in a different repository).

Thank you for catching that. Addressed.

Not really. Please remove the reference to the issue number from the commit title. The PR title could be fixed after we merge. The commit title - once merged - will stay there forever.

- Implemented a spinner to improve user experience while ZIM content is loading in the viewer iframe.
- Added .loader and .spinner styles in kiwix.css.
- The iframe content is initially hidden (visibility: hidden) and will be displayed once loading completes.
- Used CSS animations (@Keyframes spin) for a smooth rotating effect.
@Optimus-NP Optimus-NP force-pushed the kiwix-tools-issue_731 branch from da87a5f to c7e86c9 Compare March 26, 2025 16:22
@Optimus-NP
Copy link
Contributor Author

LGTM, but before we merge please remove the reference to the issue number from the commit title (since it points to the wrong issue as the issue addressed is in a different repository).

Thank you for catching that. Addressed.

Not really. Please remove the reference to the issue number from the commit title. The PR title could be fixed after we merge. The commit title - once merged - will stay there forever.

done @veloman-yunkan

@Optimus-NP
Copy link
Contributor Author

@kelson42 @veloman-yunkan

Please help in merging this.

@Optimus-NP
Copy link
Contributor Author

@kelson42

Please help in merging this.

@kelson42 kelson42 merged commit a0c99f8 into kiwix:main Mar 30, 2025
13 checks passed
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.

Add spinner when waiting for ZIM to load viewer iframe content on kiwix-server
4 participants