Skip to content

Commit

Permalink
fix: Home Style
Browse files Browse the repository at this point in the history
Since 5c85013 I store the
default wallpaper into the wallpaperlink var of the hook.

But I didn't expect that an other hook was relying on this
value to determine if it was an inverted theme or not.

So I fix the issue by checking if the current wallpaper
is different of the default one.
  • Loading branch information
Crash-- committed Jan 18, 2024
1 parent 6d15e9d commit 3566bcc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hooks/usePreferedTheme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from 'react'
import { useCustomWallpaperContext } from './useCustomWallpaperContext'
import { useClient } from 'cozy-client'

const getHomeThemeCssVariable = (): string => {
return getComputedStyle(document.getElementsByTagName('body')[0])
Expand All @@ -11,17 +12,21 @@ export const usePreferedTheme = (): string => {
const {
data: { wallpaperLink, binaryCustomWallpaper }
} = useCustomWallpaperContext()
const client = useClient()
const [preferedTheme, setPreferedTheme] = useState('inverted')

// @ts-expect-error client is not typed
const { cozyDefaultWallpaper } = client.getInstanceOptions()
useEffect(() => {
const preferedTheme = getHomeThemeCssVariable()

if (wallpaperLink || binaryCustomWallpaper) {
if (
(wallpaperLink && wallpaperLink !== cozyDefaultWallpaper) ||
binaryCustomWallpaper
) {
setPreferedTheme('inverted')
} else {
setPreferedTheme(preferedTheme || 'inverted')
}
}, [wallpaperLink, binaryCustomWallpaper])

}, [wallpaperLink, binaryCustomWallpaper, cozyDefaultWallpaper])
return preferedTheme
}

0 comments on commit 3566bcc

Please sign in to comment.