-
Notifications
You must be signed in to change notification settings - Fork 633
Set embedded app theme to match the site theme #1387
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
base: main
Are you sure you want to change the base?
Conversation
sfc-gh-tteixeira
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved after comments addressed
components/blocks/cloud.js
Outdated
| return "light"; // Default fallback for SSR | ||
| }; | ||
|
|
||
| const currentTheme = getCurrentTheme(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the function needed?
components/blocks/cloud.js
Outdated
| return "light"; // Default fallback for SSR | ||
| }; | ||
|
|
||
| const currentTheme = getCurrentTheme(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If currentTheme isn't used anywhere else, I think it's cleaner to just instantiate it to "dark_theme" or "light_theme" directly, rather than do a more brittle string interpolation later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, just instantiate to embed_options=dark_theme directly, and avoid a second string interpolation below.
Same for light.
components/blocks/cloud.js
Outdated
| } | ||
|
|
||
| // Add theme parameter to embed query string | ||
| embedQueryStr += `&${themeParam}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's cleaner to add the theme directly in the embedQueryParams array, and let the string joining logic above handle it.
That is, remove the if (query) { block but keep the code inside, modified like this:
const embedQueryParams = [themeParam];
const normalQueryParams = [];
if (query) {
query.split("&").forEach((qStr) => {
if (qStr.startsWith("embed=") || qStr.startsWith("embed_options=")) {
embedQueryParams.push(qStr);
} else {
normalQueryParams.push(qStr);
}
});
}
embedQueryStr = "&" + embedQueryParams.join("&");
normalQueryStr = "&" + normalQueryParams.join("&");
|
I think I followed your suggestions. I couldn't get rid of the function entirely, because server-side rendering broke. So, re-requested a review to make sure it satisfies you requests. |
📚 Context
This PR passed the currently selected theme to all Community Cloud embedded apps as a query parameter to make them match the site theme.
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.