From 88a7f93f8e5666f44121a2e3cf9d33d74c472aa7 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 11 Dec 2019 22:13:20 +0100 Subject: add loop setting for playlists, and use sessionStorage --- .../src/app/shared/images/global-icon.component.ts | 1 + .../src/app/shared/misc/peertube-local-storage.ts | 70 -------------------- client/src/app/shared/misc/peertube-web-storage.ts | 75 ++++++++++++++++++++++ client/src/app/shared/rest/rest-table.ts | 2 +- 4 files changed, 77 insertions(+), 71 deletions(-) delete mode 100644 client/src/app/shared/misc/peertube-local-storage.ts create mode 100644 client/src/app/shared/misc/peertube-web-storage.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/images/global-icon.component.ts b/client/src/app/shared/images/global-icon.component.ts index eb723db94..31cfe2666 100644 --- a/client/src/app/shared/images/global-icon.component.ts +++ b/client/src/app/shared/images/global-icon.component.ts @@ -26,6 +26,7 @@ const icons = { 'cross': require('!!raw-loader?!../../../assets/images/global/cross.svg'), 'validate': require('!!raw-loader?!../../../assets/images/global/validate.svg'), 'tick': require('!!raw-loader?!../../../assets/images/global/tick.svg'), + 'repeat': require('!!raw-loader?!../../../assets/images/global/repeat.svg'), 'dislike': require('!!raw-loader?!../../../assets/images/video/dislike.svg'), 'support': require('!!raw-loader?!../../../assets/images/video/support.svg'), 'like': require('!!raw-loader?!../../../assets/images/video/like.svg'), diff --git a/client/src/app/shared/misc/peertube-local-storage.ts b/client/src/app/shared/misc/peertube-local-storage.ts deleted file mode 100644 index fb5c45acf..000000000 --- a/client/src/app/shared/misc/peertube-local-storage.ts +++ /dev/null @@ -1,70 +0,0 @@ -// Thanks: https://github.com/capaj/localstorage-polyfill - -const valuesMap = new Map() - -class MemoryStorage { - [key: string]: any - [index: number]: string - - getItem (key: any) { - const stringKey = String(key) - if (valuesMap.has(key)) { - return String(valuesMap.get(stringKey)) - } - - return null - } - - setItem (key: any, val: any) { - valuesMap.set(String(key), String(val)) - } - - removeItem (key: any) { - valuesMap.delete(key) - } - - clear () { - valuesMap.clear() - } - - key (i: any) { - if (arguments.length === 0) { - throw new TypeError('Failed to execute "key" on "Storage": 1 argument required, but only 0 present.') - } - - const arr = Array.from(valuesMap.keys()) - return arr[i] - } - - get length () { - return valuesMap.size - } -} - -let peertubeLocalStorage: Storage -try { - peertubeLocalStorage = localStorage -} catch (err) { - const instance = new MemoryStorage() - - peertubeLocalStorage = new Proxy(instance, { - set: function (obj, prop: string | number, value) { - if (MemoryStorage.prototype.hasOwnProperty(prop)) { - instance[prop] = value - } else { - instance.setItem(prop, value) - } - return true - }, - get: function (target, name: string | number) { - if (MemoryStorage.prototype.hasOwnProperty(name)) { - return instance[name] - } - if (valuesMap.has(name)) { - return instance.getItem(name) - } - } - }) -} - -export { peertubeLocalStorage } diff --git a/client/src/app/shared/misc/peertube-web-storage.ts b/client/src/app/shared/misc/peertube-web-storage.ts new file mode 100644 index 000000000..fff209678 --- /dev/null +++ b/client/src/app/shared/misc/peertube-web-storage.ts @@ -0,0 +1,75 @@ +// Thanks: https://github.com/capaj/localstorage-polyfill + +const valuesMap = new Map() + +class MemoryStorage { + [key: string]: any + [index: number]: string + + getItem (key: any) { + const stringKey = String(key) + if (valuesMap.has(key)) { + return String(valuesMap.get(stringKey)) + } + + return null + } + + setItem (key: any, val: any) { + valuesMap.set(String(key), String(val)) + } + + removeItem (key: any) { + valuesMap.delete(key) + } + + clear () { + valuesMap.clear() + } + + key (i: any) { + if (arguments.length === 0) { + throw new TypeError('Failed to execute "key" on "Storage": 1 argument required, but only 0 present.') + } + + const arr = Array.from(valuesMap.keys()) + return arr[i] + } + + get length () { + return valuesMap.size + } +} + +let peertubeLocalStorage: Storage +let peertubeSessionStorage: Storage +try { + peertubeLocalStorage = localStorage + peertubeSessionStorage = sessionStorage +} catch (err) { + const instance = new MemoryStorage() + + peertubeLocalStorage = sessionStorage = new Proxy(instance, { + set: function (obj, prop: string | number, value) { + if (MemoryStorage.prototype.hasOwnProperty(prop)) { + instance[prop] = value + } else { + instance.setItem(prop, value) + } + return true + }, + get: function (target, name: string | number) { + if (MemoryStorage.prototype.hasOwnProperty(name)) { + return instance[name] + } + if (valuesMap.has(name)) { + return instance.getItem(name) + } + } + }) +} + +export { + peertubeLocalStorage, + peertubeSessionStorage +} diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts index 884588207..c180346af 100644 --- a/client/src/app/shared/rest/rest-table.ts +++ b/client/src/app/shared/rest/rest-table.ts @@ -1,4 +1,4 @@ -import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' +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' -- cgit v1.2.3