Skip to content

Commit 230c84d

Browse files
committed
feat: [OCISDEV-710] add theme mode
Added a new property to the theme called `mode`. This property specifies whether the theme is suitable for regular mode or vault mode. Valid values are `regular` and `vault`.
1 parent 9bf97c7 commit 230c84d

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Add theme mode
2+
3+
We've added a new property to the theme called `mode`. This property specifies whether the theme is suitable for regular mode or vault mode.
4+
Valid values are `regular` and `vault`.
5+
6+
https://github.com/owncloud/web/pull/13631

packages/web-pkg/src/composables/piniaStores/theme.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useLocalStorage, usePreferredDark } from '@vueuse/core'
55
import { z } from 'zod'
66
import { applyCustomProp } from '@ownclouders/design-system/helpers'
77
import { ShareRole } from '@ownclouders/web-client'
8+
import { useVault } from '../vault'
89

910
const AppBanner = z.object({
1011
title: z.string().optional(),
@@ -76,6 +77,11 @@ const WebTheme = z.object({
7677
common: CommonSection.optional(),
7778
designTokens: DesignTokens.optional(),
7879
isDark: z.boolean(),
80+
/**
81+
* Specifies whether the theme is suitable for regular mode or vault mode.
82+
* If not specified, the theme is suitable for regular mode.
83+
*/
84+
mode: z.optional(z.enum(['regular', 'vault']).default('regular')),
7985
name: z.string(),
8086
loginPage: LoginPage.optional(),
8187
logo: Logo.optional(),
@@ -103,13 +109,24 @@ export const useThemeStore = defineStore('theme', () => {
103109
const currentLocalStorageThemeName = useLocalStorage(themeStorageKey, null)
104110

105111
const isDark = usePreferredDark()
112+
const { isInVault } = useVault()
106113

107114
const currentTheme = ref<WebThemeType | undefined>()
108115

109-
const availableThemes = ref<WebThemeType[]>([])
116+
const themes = ref<WebThemeType[]>([])
117+
118+
const availableThemes = computed(() => {
119+
return unref(themes).filter((theme) => {
120+
if (unref(isInVault)) {
121+
return theme.mode === 'vault'
122+
}
123+
124+
return theme.mode === 'regular' || theme.mode === undefined
125+
})
126+
})
110127

111128
const initializeThemes = (themeConfig: WebThemeConfigType) => {
112-
availableThemes.value = themeConfig.themes.map((theme) =>
129+
themes.value = themeConfig.themes.map((theme) =>
113130
merge<WebThemeType>(themeConfig.defaults, theme)
114131
)
115132
setThemeFromStorageOrSystem()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* This composable is used for various vault-related functionality.
3+
*/
4+
interface VaultComposable {
5+
/**
6+
* Checks whether the user is currently in the vault.
7+
* This is not reactive value because a full page reload is required to switch between regular and vault mode.
8+
*/
9+
isInVault: boolean
10+
}
11+
12+
export function useVault(): VaultComposable {
13+
const isInVault = (() => {
14+
const { pathname, hash } = window.location
15+
16+
if (pathname.startsWith('/vault')) {
17+
return true
18+
}
19+
20+
if (hash) {
21+
const vaultHashPattern = /^#\/vault(?:\/|$)/
22+
return vaultHashPattern.test(hash)
23+
}
24+
25+
return false
26+
})()
27+
28+
return {
29+
isInVault
30+
}
31+
}

packages/web-runtime/src/components/Topbar/UserMenu.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ export default defineComponent({
184184
185185
const accountPageRoute = computed(() => ({
186186
name: 'account',
187-
query: routeToContextQuery(unref(route))
187+
query: routeToContextQuery(unref(route)),
188+
params: {
189+
scope: unref(route).params.scope
190+
}
188191
}))
189192
190193
const loginLink = computed(() => {

packages/web-runtime/src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const routes = [
8484
meta: { title: $gettext('Access denied'), authContext: 'anonymous' }
8585
},
8686
{
87-
path: '/account',
87+
path: '/:scope(vault)?/account',
8888
name: 'account',
8989
component: Account,
9090
meta: { title: $gettext('Account'), authContext: 'hybrid' }

0 commit comments

Comments
 (0)