Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Save settings in local storage #206

Open
1 of 2 tasks
bdougie opened this issue Jul 12, 2023 · 4 comments
Open
1 of 2 tasks

Feature: Save settings in local storage #206

bdougie opened this issue Jul 12, 2023 · 4 comments
Assignees

Comments

@bdougie
Copy link
Member

bdougie commented Jul 12, 2023

Type of feature

🍕 Feature

Current behavior

I use the same settings every-time I generate a description. But every-time there is an update or the cookie refreshes I need to save the settings again. It would be nice if we save the user settings in local storage.

Suggested solution

localstorage is preferred, but we could potentially store a settings JSON.

"settings" : {
  "Description Source" : "Commit Message",
  "Description Type" : "Formal"
}

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Contributing Docs

  • I agree to follow this project's Contribution Docs
@Anush008
Copy link
Member

We are saving the settings to chrome.storage.local for it to be persistent.

const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
void setAIDescriptionConfig(config);
toast.success("Configuration updated!");
};

export const setAIDescriptionConfig = async (data: DescriptionConfig): Promise<void> => {
await chrome.storage.local.set({ [AI_PR_DESCRIPTION_CONFIG_KEY]: data });
};

The problem being, the storage is reset if there's a reinstall.

@nickytonline
Copy link
Member

@Anush008, consider using chrome.storage.sync instead. See https://developer.chrome.com/docs/extensions/reference/storage/#storage-areas. The only caveat is it can't store much, only 100KB but it will perist across all devices and shouldn't get wiped between installs (need to double check that)

Also, see https://pandaquests.medium.com/data-retention-made-easy-persist-data-with-chrome-storage-api-in-chrome-extensions-ea4f4c721a62

@Anush008
Copy link
Member

Right. The extension settings are being saved to the synced storage.

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();
}, []);

We can do same for the AI description settings too.

@a0m0rajab
Copy link
Contributor

@Anush008 do we have anything to do for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Todos
Development

No branches or pull requests

5 participants