-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jqphu/8-create-a-simple-way-to-disable-the…
…-extension Add a settings button to disable the extension
- Loading branch information
Showing
10 changed files
with
197 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { MdClose } from 'react-icons/md'; | ||
import { Switch } from '@headlessui/react'; | ||
import { useState, useEffect } from 'react'; | ||
import { setSettings, getSettings } from '../../lib/storage'; | ||
import React from 'react'; | ||
|
||
const Settings = ({ closeSettings }: { closeSettings: () => void }) => { | ||
const [enabled, setEnabled] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
getSettings().then((settings) => setEnabled(!settings.disable)); | ||
}, []); | ||
|
||
const switchedCallback = async (enabled: boolean) => { | ||
await setSettings({ disable: !enabled }); | ||
setEnabled(enabled); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<div className="flex flex-col grow"> | ||
<div className="flex flex-row border-t border-gray-600 py-4"> | ||
<div className="text-xl font-bold text-gray-100 px-4">Settings</div> | ||
<button | ||
onClick={closeSettings} | ||
className="text-2xl font-bold text-gray-400 ml-auto my-auto text-right mr-3 p-1 hover:bg-gray-600 hover:rounded-full" | ||
> | ||
<MdClose /> | ||
</button> | ||
</div> | ||
<div className="flex flex-col gap-4 px-4 pt-4 w-full"> | ||
<div className="flex flex-row w-full"> | ||
<div className="text-lg text-gray-100 my-auto">Run Simulations</div> | ||
<Switch | ||
checked={enabled} | ||
onChange={switchedCallback} | ||
className={`${enabled ? 'bg-blue-400' : 'bg-teal-700'} | ||
my-auto ml-auto relative inline-flex h-6 w-12 shrink-0 cursor-pointer rounded-full items-center border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`} | ||
> | ||
<span className="sr-only">Use setting</span> | ||
<span | ||
aria-hidden="true" | ||
className={`${enabled ? 'translate-x-6' : 'translate-x-0'} | ||
pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out`} | ||
/> | ||
</Switch> | ||
</div> | ||
</div> | ||
</div> | ||
<div> | ||
<img className="mt-auto w-screen" src="waves_bottom.png" alt="" /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export let settings = { | ||
disable: false, | ||
}; | ||
|
||
const DISPATCH_SETTINGS = 'POCKET_UNIVERSE_DISPATCH_SETTINGS'; | ||
|
||
/** | ||
* Dispatch from ContentScript to InjectedScript the new settings. | ||
*/ | ||
export const dispatchSettings = (settings: any) => { | ||
document.dispatchEvent( | ||
new CustomEvent(DISPATCH_SETTINGS, { | ||
detail: settings, | ||
}) | ||
); | ||
}; | ||
|
||
/** | ||
* Listen to updates in settings. | ||
*/ | ||
export const listenForSettingsUpdates = () => { | ||
document.addEventListener(DISPATCH_SETTINGS, (event: any) => { | ||
settings = event.detail; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters