[search bar] dont auto focus if touch screen
This commit is contained in:
		
							parent
							
								
									6ce3c1d75d
								
							
						
					
					
						commit
						da4a20cb85
					
				@ -23,6 +23,6 @@ export class MiningDashboardComponent implements OnInit, AfterViewChecked {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngAfterViewChecked(): void {
 | 
					  ngAfterViewChecked(): void {
 | 
				
			||||||
    this.stateService.searchFocus$.next(true);
 | 
					    this.stateService.focusSearchInputDesktop();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -58,7 +58,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewChecked {
 | 
				
			|||||||
  ) { }
 | 
					  ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngAfterViewChecked(): void {
 | 
					  ngAfterViewChecked(): void {
 | 
				
			||||||
    this.stateService.searchFocus$.next(true);
 | 
					    this.stateService.focusSearchInputDesktop();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnDestroy(): void {
 | 
					  ngOnDestroy(): void {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ import { Router, NavigationStart } from '@angular/router';
 | 
				
			|||||||
import { isPlatformBrowser } from '@angular/common';
 | 
					import { isPlatformBrowser } from '@angular/common';
 | 
				
			||||||
import { filter, map, scan, shareReplay } from 'rxjs/operators';
 | 
					import { filter, map, scan, shareReplay } from 'rxjs/operators';
 | 
				
			||||||
import { StorageService } from './storage.service';
 | 
					import { StorageService } from './storage.service';
 | 
				
			||||||
 | 
					import { hasTouchScreen } from '../shared/pipes/bytes-pipe/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface MarkBlockState {
 | 
					export interface MarkBlockState {
 | 
				
			||||||
  blockHeight?: number;
 | 
					  blockHeight?: number;
 | 
				
			||||||
@ -357,4 +358,10 @@ export class StateService {
 | 
				
			|||||||
    this.blocks = this.blocks.slice(0, this.env.KEEP_BLOCKS_AMOUNT);
 | 
					    this.blocks = this.blocks.slice(0, this.env.KEEP_BLOCKS_AMOUNT);
 | 
				
			||||||
    this.blocksSubject$.next(this.blocks);
 | 
					    this.blocksSubject$.next(this.blocks);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  focusSearchInputDesktop() {
 | 
				
			||||||
 | 
					    if (!hasTouchScreen()) {
 | 
				
			||||||
 | 
					      this.searchFocus$.next(true);
 | 
				
			||||||
 | 
					    }    
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -309,3 +309,29 @@ export function takeWhile(input: any[], predicate: CollectionPredicate) {
 | 
				
			|||||||
  return takeUntil(input, (item: any, index: number | undefined, collection: any[] | undefined) =>
 | 
					  return takeUntil(input, (item: any, index: number | undefined, collection: any[] | undefined) =>
 | 
				
			||||||
    !predicate(item, index, collection));
 | 
					    !predicate(item, index, collection));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
 | 
				
			||||||
 | 
					export function hasTouchScreen(): boolean {
 | 
				
			||||||
 | 
					  let hasTouchScreen = false;
 | 
				
			||||||
 | 
					  if ('maxTouchPoints' in navigator) {
 | 
				
			||||||
 | 
					    hasTouchScreen = navigator.maxTouchPoints > 0;
 | 
				
			||||||
 | 
					  } else if ('msMaxTouchPoints' in navigator) {
 | 
				
			||||||
 | 
					    // @ts-ignore
 | 
				
			||||||
 | 
					    hasTouchScreen = navigator.msMaxTouchPoints > 0;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    const mQ = matchMedia?.('(pointer:coarse)');
 | 
				
			||||||
 | 
					    if (mQ?.media === '(pointer:coarse)') {
 | 
				
			||||||
 | 
					      hasTouchScreen = !!mQ.matches;
 | 
				
			||||||
 | 
					    } else if ('orientation' in window) {
 | 
				
			||||||
 | 
					      hasTouchScreen = true; // deprecated, but good fallback
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      // @ts-ignore - Only as a last resort, fall back to user agent sniffing
 | 
				
			||||||
 | 
					    const UA = navigator.userAgent;
 | 
				
			||||||
 | 
					      hasTouchScreen =
 | 
				
			||||||
 | 
					        /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
 | 
				
			||||||
 | 
					        /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  console.log(hasTouchScreen);
 | 
				
			||||||
 | 
					  return hasTouchScreen;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user