11/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
22import type { PropertyValues } from 'lit' ;
3- import { html , nothing , unsafeCSS , isServer } from 'lit' ;
4- import { customElement , property } from 'lit/decorators.js' ;
3+ import { html , isServer , nothing , unsafeCSS } from 'lit' ;
4+ import { customElement , property , query } from 'lit/decorators.js' ;
55import type {
66 FileUnderTestModel ,
77 Metrics ,
@@ -24,10 +24,9 @@ import { mutantChanges } from '../../lib/mutant-changes.js';
2424import { locationChange$ , View } from '../../lib/router.js' ;
2525import type { Theme } from '../../lib/theme.js' ;
2626import { globals , tailwind } from '../../style/index.js' ;
27+ import { type MutationTestReportFilePickerComponent } from '../file-picker/file-picker.component.js' ;
2728import { RealTimeElement } from '../real-time-element.js' ;
2829import theme from './theme.scss?inline' ;
29- import { type MutationTestReportFilePickerComponent } from '../file-picker/file-picker.component.js' ;
30- import { createRef , ref } from 'lit/directives/ref.js' ;
3130
3231interface BaseContext {
3332 path : string [ ] ;
@@ -88,7 +87,10 @@ export class MutationTestReportAppComponent extends RealTimeElement {
8887 return getComputedStyle ( this ) . getPropertyValue ( '--mut-body-bg' ) ;
8988 }
9089
91- #filePickerRef = createRef < MutationTestReportFilePickerComponent > ( ) ;
90+ @query ( 'mte-file-picker' )
91+ private declare filePicker : MutationTestReportFilePickerComponent ;
92+
93+ #abortController = new AbortController ( ) ;
9294
9395 @property ( )
9496 public get title ( ) : string {
@@ -161,6 +163,10 @@ export class MutationTestReportAppComponent extends RealTimeElement {
161163 }
162164 }
163165
166+ #handlePrefersColorScheme = ( ) => {
167+ this . theme = this . getTheme ( ) ;
168+ } ;
169+
164170 private getTheme ( ) : Theme {
165171 // 1. check local storage
166172 const theme = isLocalStorageAvailable ( ) && localStorage . getItem ( 'mutation-testing-elements-theme' ) ;
@@ -246,6 +252,9 @@ export class MutationTestReportAppComponent extends RealTimeElement {
246252
247253 public connectedCallback ( ) {
248254 super . connectedCallback ( ) ;
255+ window
256+ . matchMedia ( '(prefers-color-scheme: dark)' )
257+ . addEventListener ?.( 'change' , this . #handlePrefersColorScheme, { signal : this . #abortController. signal } ) ;
249258 this . subscriptions . push ( locationChange$ . subscribe ( ( path ) => ( this . path = path ) ) ) ;
250259 this . initializeSse ( ) ;
251260 }
@@ -328,6 +337,7 @@ export class MutationTestReportAppComponent extends RealTimeElement {
328337
329338 public disconnectedCallback ( ) {
330339 super . disconnectedCallback ( ) ;
340+ this . #abortController. abort ( ) ;
331341 this . subscriptions . forEach ( ( subscription ) => subscription . unsubscribe ( ) ) ;
332342 }
333343
@@ -347,15 +357,15 @@ export class MutationTestReportAppComponent extends RealTimeElement {
347357 public render ( ) {
348358 if ( this . context . result ?? this . errorMessage ) {
349359 return html `
350- < mte-file-picker ${ ref ( this . #filePickerRef ) } .rootModel ="${ this . rootModel } "> </ mte-file-picker >
360+ < mte-file-picker .rootModel ="${ this . rootModel } "> </ mte-file-picker >
351361 < div class ="container bg-white pb-4 font-sans text-gray-800 motion-safe:transition-max-width ">
352362 < div class ="space-y-4 transition-colors ">
353363 ${ this . renderErrorMessage ( ) }
354364 < mte-theme-switch @theme-switch ="${ this . themeSwitch } " class ="sticky top-offset z-20 float-right pt-6 " .theme ="${ this . theme } ">
355365 </ mte-theme-switch >
356366 ${ this . renderTitle ( ) } ${ this . renderTabs ( ) }
357367 < mte-breadcrumb
358- @mte-file-picker-open ="${ ( ) => this . #filePickerRef . value ? .open ( ) } "
368+ @mte-file-picker-open ="${ ( ) => this . filePicker . open ( ) } "
359369 .view ="${ this . context . view } "
360370 .path ="${ this . context . path } "
361371 > </ mte-breadcrumb >
0 commit comments