]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/rest/rest-table.ts
add loop setting for playlists, and use sessionStorage
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / rest / rest-table.ts
index 165fc4e45959fffe364ac23ced8e032476528494..c180346af066bc4b45af2cec7636248cb366b142 100644 (file)
@@ -1,7 +1,9 @@
+import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
 import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'
 import { SortMeta } from 'primeng/components/common/sortmeta'
-
 import { RestPagination } from './rest-pagination'
+import { Subject } from 'rxjs'
+import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
 
 export abstract class RestTable {
 
@@ -10,12 +12,17 @@ export abstract class RestTable {
   abstract sort: SortMeta
   abstract pagination: RestPagination
 
+  protected search: string
+  private searchStream: Subject<string>
   private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name
 
-  protected abstract loadData (): void
+  initialize () {
+    this.loadSort()
+    this.initSearch()
+  }
 
   loadSort () {
-    const result = localStorage.getItem(this.sortLocalStorageKey)
+    const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey)
 
     if (result) {
       try {
@@ -42,7 +49,26 @@ export abstract class RestTable {
   }
 
   saveSort () {
-    localStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
+    peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
   }
 
+  initSearch () {
+    this.searchStream = new Subject()
+
+    this.searchStream
+      .pipe(
+        debounceTime(400),
+        distinctUntilChanged()
+      )
+      .subscribe(search => {
+        this.search = search
+        this.loadData()
+      })
+  }
+
+  onSearch (search: string) {
+    this.searchStream.next(search)
+  }
+
+  protected abstract loadData (): void
 }