]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/misc/screen.service.ts
Make video-add-nav tabs scrollable on small devices (#2677)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / screen.service.ts
index 2e01839b2c28c9dd6646c5d1cedaf2fd16fab642..9c71a8c831587a5df2d7136145f9b537be039b8e 100644 (file)
@@ -11,15 +11,37 @@ export class ScreenService {
   }
 
   isInSmallView () {
-    return this.getWindowInnerWidth() < 600
+    return this.getWindowInnerWidth() < 800
+  }
+
+  isInMediumView () {
+    return this.getWindowInnerWidth() < 1100
   }
 
   isInMobileView () {
     return this.getWindowInnerWidth() < 500
   }
 
+  isInTouchScreen () {
+    return 'ontouchstart' in window || navigator.msMaxTouchPoints
+  }
+
+  getNumberOfAvailableMiniatures () {
+    const screenWidth = this.getWindowInnerWidth()
+
+    let numberOfVideos = 1
+
+    if (screenWidth > 1850) numberOfVideos = 6
+    else if (screenWidth > 1600) numberOfVideos = 5
+    else if (screenWidth > 1370) numberOfVideos = 4
+    else if (screenWidth > 1100) numberOfVideos = 3
+    else if (screenWidth > 850) numberOfVideos = 2
+
+    return numberOfVideos
+  }
+
   // Cache window inner width, because it's an expensive call
-  private getWindowInnerWidth () {
+  getWindowInnerWidth () {
     if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
 
     return this.windowInnerWidth
@@ -32,6 +54,8 @@ export class ScreenService {
   }
 
   private cacheWindowInnerWidthExpired () {
+    if (!this.lastFunctionCallTime) return true
+
     return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)
   }
 }