-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: extension settings * link to settings * aiprdescription setting * lint fixes * remove switch on/off button from ai config menu * add settings for code refactor suggestions * tests fix
- Loading branch information
Showing
17 changed files
with
216 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useState } from "react"; | ||
|
||
const Toggle = ({ settingName, settingLabel, enabledSetting }: { settingName: string; enabledSetting: boolean; settingLabel: string }) => { | ||
const [enabled, setEnabled] = useState(enabledSetting); | ||
|
||
const changeSetting = async (value: boolean) => { | ||
const settingsConfig = await chrome.storage.sync.get("osSettingsConfig"); | ||
|
||
if (settingsConfig.osSettingsConfig === undefined) { | ||
const defaultSettings = { aiPrDescription: false }; | ||
|
||
await chrome.storage.sync.set({ osSettingsConfig: defaultSettings }); | ||
} | ||
|
||
const newSettingsConfig = { ...settingsConfig.osSettingsConfig, [settingName]: value }; | ||
|
||
await chrome.storage.sync.set({ osSettingsConfig: newSettingsConfig }); | ||
|
||
setEnabled(value); | ||
}; | ||
|
||
return ( | ||
<div className="flex items-center justify-between mt-3"> | ||
<span className="text-sm font-medium text-gray-400"> | ||
{settingLabel} | ||
</span> | ||
|
||
<label className="inline-flex relative items-center mr-5 cursor-pointer"> | ||
<input | ||
readOnly | ||
checked={enabled} | ||
className="sr-only peer" | ||
type="checkbox" | ||
/> | ||
|
||
<div | ||
aria-checked="false" | ||
className="w-11 h-6 bg-gray-200 rounded-full peer peer-focus:ring-green-300 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-green-600" | ||
role="checkbox" | ||
tabIndex={0} | ||
onClick={ async () => { | ||
enabled ? await changeSetting(false) : await changeSetting(true); | ||
}} | ||
onKeyDown={ async e => { | ||
if (e.key === "Enter") { | ||
enabled ? await changeSetting(false) : await changeSetting(true); | ||
} | ||
}} | ||
/> | ||
</label> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Toggle; |
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
File renamed without changes.
10 changes: 5 additions & 5 deletions
10
src/pages/posthighlight.tsx → src/popup/pages/posthighlight.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { FaChevronLeft } from "react-icons/fa"; | ||
import OpenSaucedLogo from "../../assets/opensauced-logo.svg"; | ||
import { goBack } from "react-chrome-extension-router"; | ||
import Toggle from "../components/ToggleSwitch"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export type SettingsConfig = Record<string, boolean | undefined>; | ||
|
||
const settingLabels: Record<string, string> = { | ||
aiPrDescription: "AI PR Description", | ||
codeRefactor: "Code Refactor", | ||
}; | ||
|
||
const Settings = () => { | ||
const [settingsConfig, setSettingsConfig] = useState<SettingsConfig>({}); | ||
|
||
useEffect(() => { | ||
const getSettingsDataFromStorage = async () => { | ||
const settingsConfig = await chrome.storage.sync.get("osSettingsConfig"); | ||
|
||
if (settingsConfig.osSettingsConfig === undefined) { | ||
const defaultSettings = { aiPrDescription: true, codeRefactor: true }; | ||
|
||
await chrome.storage.sync.set({ osSettingsConfig: defaultSettings }); | ||
setSettingsConfig(defaultSettings); | ||
} else { | ||
setSettingsConfig(settingsConfig.osSettingsConfig); | ||
} | ||
}; | ||
|
||
void getSettingsDataFromStorage(); | ||
}, []); | ||
|
||
return ( | ||
<div className="p-4 bg-slate-800"> | ||
<div className="grid grid-cols-1 divide-y divide-white/40 divider-y-center-2 min-w-[320px] text-white"> | ||
<header className="flex justify-between"> | ||
<div className="flex items-center gap-2"> | ||
<button | ||
className="rounded-full p-2 bg-slate-700 hover:bg-slate-700/50" | ||
onClick={() => { | ||
goBack(); | ||
}} | ||
> | ||
<FaChevronLeft className="text-osOrange text-white" /> | ||
</button> | ||
|
||
<img | ||
alt="OpenSauced logo" | ||
className="w-[100%]" | ||
src={OpenSaucedLogo} | ||
/> | ||
</div> | ||
</header> | ||
|
||
<main className="main-content text-white"> | ||
<h3 className="text font-medium text-base leading-10">Settings:</h3> | ||
|
||
{ | ||
Object.keys(settingsConfig).map(settingName => ( | ||
<Toggle | ||
key={settingName} | ||
enabledSetting={settingsConfig[settingName]!} | ||
settingLabel={settingLabels[settingName]} | ||
settingName={settingName} | ||
/> | ||
)) | ||
|
||
} | ||
|
||
<div className="flex flex-col gap-2" /> | ||
</main> | ||
</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
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
Oops, something went wrong.