summaryrefslogtreecommitdiff
path: root/source/features/toggle-files-button.tsx
diff options
context:
space:
mode:
authorGravatar Federico Brigante <me@fregante.com> 2023-07-08 16:23:45 +0200
committerGravatar GitHub <noreply@github.com> 2023-07-08 16:23:45 +0200
commit490b4c410add19fb7af5ccfc491258c489eab93b (patch)
treeee4c7bad916d61184a493708265bafb62876dbe6 /source/features/toggle-files-button.tsx
parent567a90067a4d7ad77e463bf4dfd6ffef785cf58f (diff)
downloadrefined-github-490b4c410add19fb7af5ccfc491258c489eab93b.tar.gz
refined-github-490b4c410add19fb7af5ccfc491258c489eab93b.tar.zst
refined-github-490b4c410add19fb7af5ccfc491258c489eab93b.zip
Use new cache API (#6733)
Diffstat (limited to 'source/features/toggle-files-button.tsx')
-rw-r--r--source/features/toggle-files-button.tsx10
1 files changed, 5 insertions, 5 deletions
diff --git a/source/features/toggle-files-button.tsx b/source/features/toggle-files-button.tsx
index f592690a..947bac75 100644
--- a/source/features/toggle-files-button.tsx
+++ b/source/features/toggle-files-button.tsx
@@ -1,6 +1,6 @@
import './toggle-files-button.css';
import select from 'select-dom';
-import cache from 'webext-storage-cache';
+import {CachedValue} from 'webext-storage-cache';
import React from 'dom-chef';
import delegate, {DelegateEvent} from 'delegate-it';
import * as pageDetect from 'github-url-detection';
@@ -10,7 +10,7 @@ import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';
import {isHasSelectorSupported} from '../helpers/select-has.js';
-const cacheKey = 'files-hidden';
+const wereFilesHidden = new CachedValue<boolean>('files-hidden');
const toggleButtonClass = 'rgh-toggle-files';
function addButton(filesBox: HTMLElement): void {
@@ -50,7 +50,7 @@ async function toggleList(): Promise<void> {
firstCollapseOnDesktop(targets);
if (window.matchMedia('(min-width: 768px)').matches) {
// We just hid the file list, no further action is necessary on desktop
- await cache.set<boolean>(cacheKey, true);
+ void wereFilesHidden.set(true);
return;
}
@@ -64,14 +64,14 @@ async function toggleList(): Promise<void> {
async function updateView(anchor: HTMLHeadingElement): Promise<void> {
const filesBox = anchor.parentElement!;
addButton(filesBox);
- if (await cache.get<boolean>(cacheKey)) {
+ if (await wereFilesHidden.get()) {
// This only applies on desktop; Mobile already always starts collapsed and we're not changing that
firstCollapseOnDesktop();
}
}
async function recordToggle({detail}: DelegateEvent<CustomEvent>): Promise<void> {
- await cache.set<boolean>(cacheKey, !detail.open);
+ await wereFilesHidden.set(!detail.open);
}
async function init(signal: AbortSignal): Promise<void> {