♻️(frontend) address Sonar warnings in PiP and side panel

Replace nested ternary logic, use globalThis instead of window, and switch side-panel enum re-exports to export-from for clearer and safer patterns.

Made-with: Cursor
This commit is contained in:
Cyril
2026-04-29 14:28:17 +02:00
parent 2b50dd3158
commit 323a998721
6 changed files with 14 additions and 12 deletions
@@ -36,6 +36,8 @@ const syncThemeAttribute = (source: Document, target: Document) => {
const theme = source.documentElement.getAttribute('data-lk-theme')
if (theme) {
target.documentElement.setAttribute('data-lk-theme', theme)
} else {
target.documentElement.removeAttribute('data-lk-theme')
}
}
@@ -16,12 +16,11 @@ export const PipConnectionStateToast = () => {
keyPrefix: 'options.items.pictureInPicture.connection',
})
const label =
state === ConnectionState.Reconnecting
? t('reconnecting')
: state === ConnectionState.Disconnected
? t('disconnected')
: null
const connectionLabels: Partial<Record<ConnectionState, string>> = {
[ConnectionState.Reconnecting]: t('reconnecting'),
[ConnectionState.Disconnected]: t('disconnected'),
}
const label = connectionLabels[state] ?? null
if (!label) return null
@@ -23,8 +23,8 @@ export const useDocumentPiP = ({
const pendingPiPRef = useRef<Promise<Window | null> | null>(null)
const [isSupported] = useState(() => {
if (typeof window === 'undefined') return false
return 'documentPictureInPicture' in window
if (typeof globalThis === 'undefined') return false
return 'documentPictureInPicture' in globalThis
})
const openPiP = useCallback(async () => {
@@ -35,7 +35,8 @@ export const useDocumentPiP = ({
if (pendingPiPRef.current) return pendingPiPRef.current
// Request a new PiP window from the browser API.
const pip = (window as WindowWithDocumentPiP).documentPictureInPicture
const pip = (globalThis as unknown as WindowWithDocumentPiP)
.documentPictureInPicture
if (!pip) return null
const requestPromise = (async () => {
@@ -25,7 +25,7 @@ export const usePipElementSize = <T extends HTMLElement>(
measure()
const RO =
el.ownerDocument.defaultView?.ResizeObserver ?? window.ResizeObserver
el.ownerDocument.defaultView?.ResizeObserver ?? globalThis.ResizeObserver
if (!RO) return
const observer = new RO((entries) => {
@@ -5,7 +5,7 @@ import { roomPiPStore } from '@/stores/roomPiP'
export const useRoomPiP = () => {
const { isOpen } = useSnapshot(roomPiPStore)
const isSupported =
typeof window !== 'undefined' && 'documentPictureInPicture' in window
typeof globalThis !== 'undefined' && 'documentPictureInPicture' in globalThis
const open = useCallback(() => {
roomPiPStore.isOpen = true
@@ -2,7 +2,7 @@ import { useSnapshot } from 'valtio'
import { layoutStore } from '@/stores/layout'
import { PanelId, SubPanelId } from '../types/panel'
export { PanelId, SubPanelId }
export { PanelId, SubPanelId } from '../types/panel'
export type SidePanelStore = {
activePanelId: PanelId | null