Storage controller refactor (#907)

* Use array for use/quota nodes

* Use classes instead of ids
This commit is contained in:
toasted-nutbread 2020-10-10 17:37:16 -04:00 committed by GitHub
parent 19e0346484
commit 0244d07ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View File

@ -31,12 +31,12 @@ class StorageController {
prepare() {
this._persistentStorageCheckbox = document.querySelector('#storage-persistent-checkbox');
this._storageUsageNode = document.querySelector('#storage-usage');
this._storageQuotaNode = document.querySelector('#storage-quota');
this._storageUseFiniteNodes = document.querySelectorAll('#storage-use-finite');
this._storageUseInfiniteNodes = document.querySelectorAll('#storage-use-infinite');
this._storageUseValidNodes = document.querySelectorAll('#storage-use-valid');
this._storageUseInvalidNodes = document.querySelectorAll('#storage-use-invalid');
this._storageUsageNodes = document.querySelectorAll('.storage-usage');
this._storageQuotaNodes = document.querySelectorAll('.storage-quota');
this._storageUseFiniteNodes = document.querySelectorAll('.storage-use-finite');
this._storageUseInfiniteNodes = document.querySelectorAll('.storage-use-infinite');
this._storageUseValidNodes = document.querySelectorAll('.storage-use-valid');
this._storageUseInvalidNodes = document.querySelectorAll('.storage-use-invalid');
this._preparePersistentStorage();
this.updateStats();
@ -56,8 +56,12 @@ class StorageController {
// Firefox reports usage as 0 when persistent storage is enabled.
const finite = valid && (estimate.usage > 0 || !(await this._isStoragePeristent()));
if (finite) {
this._storageUsageNode.textContent = this._bytesToLabeledString(estimate.usage);
this._storageQuotaNode.textContent = this._bytesToLabeledString(estimate.quota);
for (const node of this._storageUsageNodes) {
node.textContent = this._bytesToLabeledString(estimate.usage);
}
for (const node of this._storageQuotaNodes) {
node.textContent = this._bytesToLabeledString(estimate.quota);
}
}
this._setElementsVisible(this._storageUseFiniteNodes, valid && finite);

View File

@ -805,13 +805,13 @@
</div>
<div id="storage-use" hidden>
<p class="help-block" id="storage-use-invalid">
<p class="help-block" class="storage-use-invalid">
Yomichan is using an indeterminate amount of storage.
</p>
<p class="help-block" id="storage-use-finite" hidden>
Yomichan is using approximately <strong id="storage-usage"></strong> of <strong id="storage-quota"></strong>.
<p class="help-block" class="storage-use-finite" hidden>
Yomichan is using approximately <strong class="storage-usage"></strong> of <strong class="storage-quota"></strong>.
</p>
<p class="help-block" id="storage-use-infinite" hidden>
<p class="help-block" class="storage-use-infinite" hidden>
Yomichan is permitted <strong>unlimited storage</strong>.
</p>
</div>