2022-09-20 15:02:09 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { ViewModel } = require('hydrogen-view-sdk');
|
|
|
|
|
2023-05-03 03:45:33 -06:00
|
|
|
const LOCAL_STORAGE_KEYS = require('matrix-public-archive-shared/lib/local-storage-keys');
|
2022-10-20 01:06:43 -06:00
|
|
|
|
2022-10-27 00:09:13 -06:00
|
|
|
class DeveloperOptionsContentViewModel extends ViewModel {
|
2022-09-20 15:02:09 -06:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2022-10-27 00:09:13 -06:00
|
|
|
const { room, debugActiveDateIntersectionObserver = false } = options;
|
2022-09-20 15:02:09 -06:00
|
|
|
|
2022-10-27 00:09:13 -06:00
|
|
|
this._room = room;
|
2022-09-20 15:02:09 -06:00
|
|
|
this._debugActiveDateIntersectionObserver = debugActiveDateIntersectionObserver;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadValuesFromPersistence() {
|
2023-05-05 18:44:49 -06:00
|
|
|
// Debugging is disabled by default and only enabled with the correct 'true' value
|
|
|
|
let debugActiveDateIntersectionObserver = false;
|
|
|
|
|
2022-09-20 15:02:09 -06:00
|
|
|
if (window.localStorage) {
|
2023-05-05 18:44:49 -06:00
|
|
|
const debugActiveDateIntersectionObserverFromPersistence = window.localStorage.getItem(
|
|
|
|
LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver
|
2022-09-20 15:02:09 -06:00
|
|
|
);
|
2023-05-05 18:44:49 -06:00
|
|
|
|
|
|
|
if (debugActiveDateIntersectionObserverFromPersistence === 'true') {
|
|
|
|
debugActiveDateIntersectionObserver = true;
|
|
|
|
}
|
2022-09-20 15:02:09 -06:00
|
|
|
} else {
|
2023-05-03 03:45:33 -06:00
|
|
|
console.warn(
|
|
|
|
`Skipping \`${LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver}\` read from LocalStorage since LocalStorage is not available`
|
|
|
|
);
|
2022-09-20 15:02:09 -06:00
|
|
|
}
|
2023-05-05 18:44:49 -06:00
|
|
|
|
|
|
|
this.toggleDebugActiveDateIntersectionObserver(debugActiveDateIntersectionObserver);
|
2022-09-20 15:02:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
get debugActiveDateIntersectionObserver() {
|
|
|
|
return this._debugActiveDateIntersectionObserver;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleDebugActiveDateIntersectionObserver(checkedValue) {
|
|
|
|
this._debugActiveDateIntersectionObserver = checkedValue;
|
2023-05-05 18:44:49 -06:00
|
|
|
if (window.localStorage) {
|
|
|
|
window.localStorage.setItem(
|
|
|
|
LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver,
|
|
|
|
this._debugActiveDateIntersectionObserver ? 'true' : 'false'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.warn(
|
|
|
|
`Skipping \`${LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver}\` write to LocalStorage since LocalStorage is not available`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-20 15:02:09 -06:00
|
|
|
this.emitChange('debugActiveDateIntersectionObserver');
|
|
|
|
}
|
2022-10-27 00:09:13 -06:00
|
|
|
|
|
|
|
get roomId() {
|
|
|
|
return this._room.id;
|
|
|
|
}
|
2022-09-20 15:02:09 -06:00
|
|
|
}
|
|
|
|
|
2022-10-27 00:09:13 -06:00
|
|
|
module.exports = DeveloperOptionsContentViewModel;
|