From e82a2ce9ae0a578476bc158dd45606ef337b5b19 Mon Sep 17 00:00:00 2001
From: Joe <33972521+hnb-ku@users.noreply.github.com>
Date: Wed, 22 Jun 2022 04:35:46 +0800
Subject: [PATCH] UX: Introduces a splash screen behind a hidden site setting
(#17094)
This PR introduces a new hidden site setting that allows admins to display a splash screen while site assets load.
The splash screen can be enabled via the `splash_screen` hidden site setting.
This is what the splash screen currently looks like
https://d11a6trkgmumsb.cloudfront.net/original/4X/5/c/e/5ceb72f0853a111469ca08a61328b01b39806d47.mp4
Once site assets load, the splash screen is automatically removed.
To control the loading text that shows in the splash screen, you can change the preloader_text translation string in admin > customize > text
---
app/assets/javascripts/discourse/app/app.js | 3 +
app/assets/stylesheets/d_splash.scss | 59 ++++++++++++++
app/helpers/application_helper.rb | 5 ++
app/views/common/_discourse_splash.html.erb | 17 ++++
app/views/layouts/application.html.erb | 8 ++
config/locales/client.en.yml | 2 +
config/locales/server.en.yml | 4 +-
config/site_settings.yml | 4 +
public/images/preloader.svg | 85 ++++++++++++++++++++
spec/lib/stylesheet/compiler_spec.rb | 2 +-
spec/requests/application_controller_spec.rb | 22 +++++
11 files changed, 209 insertions(+), 2 deletions(-)
create mode 100644 app/assets/stylesheets/d_splash.scss
create mode 100644 app/views/common/_discourse_splash.html.erb
create mode 100644 public/images/preloader.svg
diff --git a/app/assets/javascripts/discourse/app/app.js b/app/assets/javascripts/discourse/app/app.js
index 19da3d28362..5d620caf85d 100644
--- a/app/assets/javascripts/discourse/app/app.js
+++ b/app/assets/javascripts/discourse/app/app.js
@@ -52,6 +52,9 @@ const Discourse = Application.extend({
start() {
document.querySelector("noscript")?.remove();
+ // The app booted. Remove the splash screen
+ document.querySelector("#d-splash")?.remove();
+
if (Error.stackTraceLimit) {
// We need Errors to have full stack traces for `lib/source-identifier`
Error.stackTraceLimit = Infinity;
diff --git a/app/assets/stylesheets/d_splash.scss b/app/assets/stylesheets/d_splash.scss
new file mode 100644
index 00000000000..c56c915f936
--- /dev/null
+++ b/app/assets/stylesheets/d_splash.scss
@@ -0,0 +1,59 @@
+html {
+ background: var(--secondary);
+ // needed because this sheet loads early and we want no scroll bars until
+ // the splash is removed.
+ overflow: hidden !important;
+}
+
+#d-splash {
+ display: grid;
+ place-items: center;
+ position: relative;
+ backface-visibility: hidden;
+
+ .preloader-image {
+ max-width: 100%;
+ height: 100vh;
+ object-fit: none;
+ }
+
+ .preloader-text {
+ padding-top: 5em;
+ position: absolute;
+ display: grid;
+ grid-auto-flow: column;
+ place-items: center;
+
+ &:after {
+ animation: loading-text 3s infinite;
+ content: "";
+ position: absolute;
+ top: 5em;
+ margin: 0 0.1em;
+ left: 100%;
+ // TODO: this needs R2 RTL magic
+ .rtl & {
+ left: 0;
+ right: 100%;
+ }
+ }
+ }
+}
+
+@keyframes loading-text {
+ 0% {
+ content: "";
+ }
+
+ 25% {
+ content: ".";
+ }
+
+ 50% {
+ content: "..";
+ }
+
+ 75% {
+ content: "...";
+ }
+}
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3b2306eae21..de081f8b943 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -429,6 +429,11 @@ module ApplicationHelper
", app-argument=discourse://new?siteUrl=#{Discourse.base_url}" : ""
end
+ def include_splash_screen?
+ # A bit basic for now but will be expanded later
+ SiteSetting.splash_screen
+ end
+
def allow_plugins?
!request.env[ApplicationController::NO_PLUGINS]
end
diff --git a/app/views/common/_discourse_splash.html.erb b/app/views/common/_discourse_splash.html.erb
new file mode 100644
index 00000000000..e48c75e1ef3
--- /dev/null
+++ b/app/views/common/_discourse_splash.html.erb
@@ -0,0 +1,17 @@
+<%- unless customization_disabled? %>
+
+
+