Skip to content

Commit

Permalink
Fix: Remove unneeded method
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Nov 9, 2023
1 parent 9d5e652 commit 7c1779c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
11 changes: 3 additions & 8 deletions src/class/StorageTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Browser from "webextension-polyfill";

import { WebsiteIds, Websites } from "@/data/websites";
import { WebsiteIds } from "@/data/websites";

import IsTrue from "../../utils/isTrue";

Expand All @@ -19,20 +19,15 @@ export type StorageKeys =
export type StorageIds = WebsiteIds | "other";

export default class StorageTool {
id: string;
constructor(id: string) {
id: StorageIds;
constructor(id: StorageIds) {
this.id = id;
}

static getChromeStorage() {
return Browser.storage ? Browser.storage.sync : null;
}

static getStorage(id: StorageIds) {
if (id == "other") return new StorageTool(id);
return Websites.get(id)?.class.storage;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async set(key: StorageKeys, value: any) {
let newData = { [key]: value };
Expand Down
5 changes: 1 addition & 4 deletions src/components/ToggleWithStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ interface ToggleProps {

export function ToggleWithStorage({ dataId, color, dataKey, readonly }: ToggleProps) {
const [enabled, setEnabled] = useState(false);
const storage = new StorageTool(dataId);

useEffect(() => {
const storage = StorageTool.getStorage(dataId);
if (storage === undefined) return;
storage.get(dataKey).then((value) => {
const istrue = IsTrue(value);
if (istrue !== undefined) setEnabled(istrue);
Expand All @@ -31,8 +30,6 @@ export function ToggleWithStorage({ dataId, color, dataKey, readonly }: TogglePr
if (readonly) return;
return (e: React.ChangeEvent<HTMLInputElement>) => {
setEnabled(e.target.checked);
const storage = StorageTool.getStorage(dataId);
if (storage === undefined) return;
storage.set(dataKey, e.target.checked.toString());
sendMsgToAllTab<string>("reload");
};
Expand Down

0 comments on commit 7c1779c

Please sign in to comment.