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

Add new ThemeSwitcher logic #9698

Merged
merged 23 commits into from
Dec 11, 2023

Conversation

pascalwengerter
Copy link
Contributor

Description

Overhaul of theme loading (used to be object key-value instead of an array of themes, which seems more desireable)-

Motivation and Context

Supersede && finish some draft PRs, take advantage of upcoming major release

Open tasks:

  • Implement
  • Test
  • Document

packages/web-runtime/themes/owncloud/theme.json Outdated Show resolved Hide resolved
@@ -16,6 +16,7 @@
"peerDependencies": {
"@ownclouders/design-system": "workspace:*",
"@ownclouders/web-client": "workspace:*",
"@ownclouders/web-pkg": "workspace:*"
"@ownclouders/web-pkg": "workspace:*",
"pinia": "^2.1.7"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we should re-export the required part (storeToRefs) from web-pkg?

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO it's fine to have pinia as peerDependency in most of our packages since that will probably be the case anyway after fully switching to it.

privacyUrl: '',
imprintUrl: '',
accessDeniedHelpUrl: '',
logoutUrl: '', // Fixme: why was this missing before?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was this a conscious omission?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think so, I feel like we sometimes forget adding new configs here 😅

const currentLocalStorageThemeName = useLocalStorage(themeStorageKey, theme.name)
currentLocalStorageThemeName.value = currentTheme.value.name

// TODO: Shouldn't we loop over all designTokens and set them?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kulmann do you remember if we only applied the colorPalette on purpose instead of applying all designTokens?

Copy link
Member

Choose a reason for hiding this comment

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

don't remember it. but yes, we should loop over all design tokens... otherwise one theme would leak into the other, newly selected theme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It technically still could since we're not resetting everything, but at least with the change I just pushed one isn't left wondering why the e.g. fontsize never changes even though a theme might re-define it 😋

changelog/unreleased/change-theme-handling Outdated Show resolved Hide resolved
packages/web-runtime/src/App.vue Outdated Show resolved Hide resolved
const currentLocalStorageThemeName = useLocalStorage(themeStorageKey, theme.name)
currentLocalStorageThemeName.value = currentTheme.value.name

// TODO: Shouldn't we loop over all designTokens and set them?
Copy link
Member

Choose a reason for hiding this comment

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

don't remember it. but yes, we should loop over all design tokens... otherwise one theme would leak into the other, newly selected theme.

}
const theme = await response.json()
return { web: theme.web || theme, common: theme.common || {} }

if (WebThemeConfigSchema.safeParse(theme).success) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dschmidt is this roughly what you had in mind?

packages/web-app-importer/src/extensions.ts Outdated Show resolved Hide resolved
@@ -16,6 +16,7 @@
"peerDependencies": {
"@ownclouders/design-system": "workspace:*",
"@ownclouders/web-client": "workspace:*",
"@ownclouders/web-pkg": "workspace:*"
"@ownclouders/web-pkg": "workspace:*",
"pinia": "^2.1.7"
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO it's fine to have pinia as peerDependency in most of our packages since that will probably be the case anyway after fully switching to it.

privacyUrl: '',
imprintUrl: '',
accessDeniedHelpUrl: '',
logoutUrl: '', // Fixme: why was this missing before?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think so, I feel like we sometimes forget adding new configs here 😅

Comment on lines -82 to -83
- `options.imprintUrl` Specifies the target URL for the imprint link valid for the ocis instance in the account menu.
- `options.privacyUrl` Specifies the target URL for the privacy link valid for the ocis instance in the account menu.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the config for this has been removed intentionally? Because then we need to remove it in oCIS as well.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we should. The way to go is the theme, so that all clients can use the URLs. Config is only for web.

currentThemeName.value = useDefaultThemeName()
}
await store.dispatch('loadTheme', { theme: web[unref(currentThemeName)] || web.default })
const themeStore = useThemeStore()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also not in an injection context here... I know we currently don't have an alternative, but one day that might become a problem 😬 @dschmidt Maybe also something to consider for a future refactoring.

packages/web-runtime/src/composables/head/useHead.ts Outdated Show resolved Hide resolved
@@ -89,6 +91,9 @@ export default defineComponent({
const { getInternalSpace } = useGetMatchingSpace()
useUpload({ uppyService })

const { currentTheme } = storeToRefs(themeStore)
const themeSlogan = computed(() => currentTheme.value.common.slogan)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be computed, as storeToRefs builds already a reactive object, or does this not apply to nested objects?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand it: It's not necessary in this case. currentTheme is already a Ref because of storeToRefs. Meaning the consuming code could go directly via unref(currentTheme).common.slogan.

It doesn't hurt to have a computed here though, I guess it's used as a "shortcut".

Copy link

sonarcloud bot commented Dec 11, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

61.0% 61.0% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link
Member

@kulmann kulmann left a comment

Choose a reason for hiding this comment

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

nice work 💪

)
})

const imprintUrl = computed(() => themeStore.currentTheme.common.urls.imprint)
Copy link
Member

Choose a reason for hiding this comment

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

For the record, we might need to re-introduce setting the imprint and privacy urls via config.json for short term deployment reasons.

@kulmann kulmann dismissed AlexAndBear’s stale review December 11, 2023 20:53

to be solved in a followup if needed

@kulmann kulmann merged commit 4da807e into owncloud:master Dec 11, 2023
3 of 4 checks passed
ownclouders pushed a commit that referenced this pull request Dec 11, 2023
New theme structure

---------

Co-authored-by: Jannik Stehle <[email protected]>
pascalwengerter added a commit to pascalwengerter/web that referenced this pull request Dec 12, 2023
pascalwengerter added a commit to pascalwengerter/web that referenced this pull request Dec 12, 2023
AlexAndBear pushed a commit that referenced this pull request Dec 13, 2023
New theme structure

---------

Co-authored-by: Jannik Stehle <[email protected]>
kulmann added a commit that referenced this pull request Dec 14, 2023
ownclouders pushed a commit that referenced this pull request Dec 14, 2023
@micbar micbar mentioned this pull request Dec 20, 2023
71 tasks
@pascalwengerter pascalwengerter deleted the change/rework-theme-logic branch January 18, 2024 18:06
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.

None yet

5 participants