mirror of
https://github.com/thedevs-network/kutt-extension.git
synced 2026-02-03 13:53:23 +00:00
refactor: restore comments
This commit is contained in:
@@ -83,6 +83,7 @@ function Form() {
|
||||
|
||||
function handleApiKeyInputChange(apikey: string): void {
|
||||
setFormValues((prev) => ({...prev, apikey}));
|
||||
// ToDo: Remove special symbols
|
||||
|
||||
if (!(apikey.trim().length > 0)) {
|
||||
setFormErrors((prev) => ({...prev, apikey: 'API key missing'}));
|
||||
|
||||
@@ -59,8 +59,10 @@ function Form() {
|
||||
true;
|
||||
|
||||
async function handleFormSubmit(): Promise<void> {
|
||||
// enable loading screen
|
||||
setIsSubmitting(true);
|
||||
|
||||
// Get target link to shorten
|
||||
const tabs = await getCurrentTab();
|
||||
const target: string | null = get(tabs, '[0].url', null);
|
||||
const shouldSubmit: boolean = !isNull(target) && isValidUrl(target);
|
||||
@@ -95,15 +97,18 @@ function Form() {
|
||||
hostUrl: extensionSettingsState.host.hostUrl,
|
||||
};
|
||||
|
||||
// shorten url in the background
|
||||
const response: SuccessfulShortenStatusProperties | ApiErroredProperties =
|
||||
await messageUtil.send(SHORTEN_URL, apiShortenUrlBody);
|
||||
|
||||
// disable spinner
|
||||
setIsSubmitting(false);
|
||||
|
||||
if (!response.error) {
|
||||
const {
|
||||
data: {link},
|
||||
} = response;
|
||||
// show shortened url
|
||||
requestStatusDispatch({
|
||||
type: RequestStatusActionTypes.SET_REQUEST_STATUS,
|
||||
payload: {
|
||||
@@ -112,6 +117,7 @@ function Form() {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// errored
|
||||
requestStatusDispatch({
|
||||
type: RequestStatusActionTypes.SET_REQUEST_STATUS,
|
||||
payload: {
|
||||
@@ -124,6 +130,8 @@ function Form() {
|
||||
|
||||
function handleCustomUrlInputChange(url: string): void {
|
||||
setFormState((prev) => ({...prev, customurl: url}));
|
||||
// ToDo: Remove special symbols
|
||||
|
||||
if (url.length > 0 && url.length < 3) {
|
||||
setFormErrors((prev) => ({
|
||||
...prev,
|
||||
@@ -136,6 +144,8 @@ function Form() {
|
||||
|
||||
function handlePasswordInputChange(password: string): void {
|
||||
setFormState((prev) => ({...prev, password}));
|
||||
// ToDo: Remove special symbols
|
||||
|
||||
if (password.length > 0 && password.length < 3) {
|
||||
setFormErrors((prev) => ({
|
||||
...prev,
|
||||
|
||||
@@ -60,6 +60,7 @@ function Popup() {
|
||||
let performMigration = false;
|
||||
|
||||
if ((key as string).trim().length > 0) {
|
||||
// map it to `settings.apikey`
|
||||
migrationSettings.apikey = key;
|
||||
performMigration = true;
|
||||
}
|
||||
@@ -67,15 +68,19 @@ function Popup() {
|
||||
(host as string).trim().length > 0 &&
|
||||
(userOptions.devMode as boolean)
|
||||
) {
|
||||
// map `host` to `settings.host`
|
||||
migrationSettings.host = host;
|
||||
// set `advanced` to true
|
||||
migrationSettings.advanced = true;
|
||||
performMigration = true;
|
||||
}
|
||||
if (userOptions.keepHistory as boolean) {
|
||||
// set `settings.history` to true
|
||||
migrationSettings.history = true;
|
||||
performMigration = true;
|
||||
}
|
||||
if (performMigration) {
|
||||
// perform migration
|
||||
await migrateSettings(migrationSettings);
|
||||
}
|
||||
|
||||
@@ -134,6 +139,7 @@ function Popup() {
|
||||
}
|
||||
}
|
||||
|
||||
// `history` field set
|
||||
let historyEnabled = false;
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(settings, 'history') &&
|
||||
@@ -176,8 +182,10 @@ function Popup() {
|
||||
}
|
||||
);
|
||||
|
||||
// merge to beginning of array
|
||||
optionsList = defaultOptions.concat(optionsList);
|
||||
|
||||
// update domain list
|
||||
extensionSettingsDispatch({
|
||||
type: ExtensionSettingsActionTypes.HYDRATE_EXTENSION_SETTINGS,
|
||||
payload: {
|
||||
@@ -188,6 +196,7 @@ function Popup() {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// no `user` but `apikey` exist on storage
|
||||
extensionSettingsDispatch({
|
||||
type: ExtensionSettingsActionTypes.HYDRATE_EXTENSION_SETTINGS,
|
||||
payload: {
|
||||
@@ -199,6 +208,7 @@ function Popup() {
|
||||
});
|
||||
}
|
||||
|
||||
// stop loader
|
||||
requestStatusDispatch({
|
||||
type: RequestStatusActionTypes.SET_LOADING,
|
||||
payload: false,
|
||||
|
||||
Reference in New Issue
Block a user